@Test void stopServiceWithoutStartingItFirst(@VertxInstance Vertx vertx) { VertxRLPxService service = new VertxRLPxService( vertx, LoggerProvider.nullProvider(), 0, "localhost", 10000, SECP256K1.KeyPair.random(), new ArrayList<>(), "abc"); AsyncCompletion completion = service.stop(); assertTrue(completion.isDone()); }
@Override public AsyncCompletion stop() { if (started.compareAndSet(true, false)) { for (WireConnection conn : repository.asIterable()) { ((DefaultWireConnection) conn).disconnect(DisconnectReason.CLIENT_QUITTING); } repository.close(); client.close(); AsyncCompletion handlersCompletion = AsyncCompletion.allOf(handlers.values().stream().map(SubProtocolHandler::stop).collect(Collectors.toList())); CompletableAsyncCompletion completableAsyncCompletion = AsyncCompletion.incomplete(); server.close(res -> { if (res.succeeded()) { completableAsyncCompletion.complete(); } else { completableAsyncCompletion.completeExceptionally(res.cause()); } }); return handlersCompletion.thenCombine(completableAsyncCompletion); } else { return AsyncCompletion.completed(); } }
VertxRLPxService implements RLPxService { @Override public AsyncCompletion stop() { if (started.compareAndSet(true, false)) { for (WireConnection conn : repository.asIterable()) { ((DefaultWireConnection) conn).disconnect(DisconnectReason.CLIENT_QUITTING); } repository.close(); client.close(); AsyncCompletion handlersCompletion = AsyncCompletion.allOf(handlers.values().stream().map(SubProtocolHandler::stop).collect(Collectors.toList())); CompletableAsyncCompletion completableAsyncCompletion = AsyncCompletion.incomplete(); server.close(res -> { if (res.succeeded()) { completableAsyncCompletion.complete(); } else { completableAsyncCompletion.completeExceptionally(res.cause()); } }); return handlersCompletion.thenCombine(completableAsyncCompletion); } else { return AsyncCompletion.completed(); } } }
VertxRLPxService implements RLPxService { @Override public AsyncCompletion stop() { if (started.compareAndSet(true, false)) { for (WireConnection conn : repository.asIterable()) { ((DefaultWireConnection) conn).disconnect(DisconnectReason.CLIENT_QUITTING); } repository.close(); client.close(); AsyncCompletion handlersCompletion = AsyncCompletion.allOf(handlers.values().stream().map(SubProtocolHandler::stop).collect(Collectors.toList())); CompletableAsyncCompletion completableAsyncCompletion = AsyncCompletion.incomplete(); server.close(res -> { if (res.succeeded()) { completableAsyncCompletion.complete(); } else { completableAsyncCompletion.completeExceptionally(res.cause()); } }); return handlersCompletion.thenCombine(completableAsyncCompletion); } else { return AsyncCompletion.completed(); } } VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId);  VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId,
      WireConnectionRepository repository); }
VertxRLPxService implements RLPxService { @Override public AsyncCompletion stop() { if (started.compareAndSet(true, false)) { for (WireConnection conn : repository.asIterable()) { ((DefaultWireConnection) conn).disconnect(DisconnectReason.CLIENT_QUITTING); } repository.close(); client.close(); AsyncCompletion handlersCompletion = AsyncCompletion.allOf(handlers.values().stream().map(SubProtocolHandler::stop).collect(Collectors.toList())); CompletableAsyncCompletion completableAsyncCompletion = AsyncCompletion.incomplete(); server.close(res -> { if (res.succeeded()) { completableAsyncCompletion.complete(); } else { completableAsyncCompletion.completeExceptionally(res.cause()); } }); return handlersCompletion.thenCombine(completableAsyncCompletion); } else { return AsyncCompletion.completed(); } } VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId);  VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId,
      WireConnectionRepository repository); @Override AsyncCompletion start(); @Override void send(SubProtocolIdentifier subProtocolIdentifier, int messageType, String connectionId, Bytes message); @Override void disconnect(String connectionId, DisconnectReason disconnectReason); @Override void broadcast(SubProtocolIdentifier subProtocolIdentifier, int messageType, Bytes message); @Override AsyncCompletion stop(); int actualPort(); int advertisedPort(); @Override WireConnectionRepository repository(); @Override AsyncCompletion connectTo(PublicKey peerPublicKey, InetSocketAddress peerAddress); }
VertxRLPxService implements RLPxService { @Override public AsyncCompletion stop() { if (started.compareAndSet(true, false)) { for (WireConnection conn : repository.asIterable()) { ((DefaultWireConnection) conn).disconnect(DisconnectReason.CLIENT_QUITTING); } repository.close(); client.close(); AsyncCompletion handlersCompletion = AsyncCompletion.allOf(handlers.values().stream().map(SubProtocolHandler::stop).collect(Collectors.toList())); CompletableAsyncCompletion completableAsyncCompletion = AsyncCompletion.incomplete(); server.close(res -> { if (res.succeeded()) { completableAsyncCompletion.complete(); } else { completableAsyncCompletion.completeExceptionally(res.cause()); } }); return handlersCompletion.thenCombine(completableAsyncCompletion); } else { return AsyncCompletion.completed(); } } VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId);  VertxRLPxService(
      Vertx vertx,
      LoggerProvider loggerProvider,
      int listenPort,
      String networkInterface,
      int advertisedPort,
      KeyPair identityKeyPair,
      List<SubProtocol> subProtocols,
      String clientId,
      WireConnectionRepository repository); @Override AsyncCompletion start(); @Override void send(SubProtocolIdentifier subProtocolIdentifier, int messageType, String connectionId, Bytes message); @Override void disconnect(String connectionId, DisconnectReason disconnectReason); @Override void broadcast(SubProtocolIdentifier subProtocolIdentifier, int messageType, Bytes message); @Override AsyncCompletion stop(); int actualPort(); int advertisedPort(); @Override WireConnectionRepository repository(); @Override AsyncCompletion connectTo(PublicKey peerPublicKey, InetSocketAddress peerAddress);  }