/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ private CompletableFuture<Connection> createConnection(Address address) { return connectionFutures.computeIfAbsent(address, a -> { CompletableFuture<Connection> future = client.connect(address).thenApply(connection -> { connection.onClose(c -> connections.remove(address, c)); connections.put(address, connection); return connection; }); future.whenComplete((connection, error) -> connectionFutures.remove(address)); return future; }); }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ private CompletableFuture<Connection> createConnection(Address address) { return client.connect(address).thenApply(connection -> { connection.closeListener(c -> { if (connections.get(address) == c) { connections.remove(address); } }); connections.put(address, connection); return connection; }); }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ private CompletableFuture<Connection> createConnection(Address address) { return connectionFutures.computeIfAbsent(address, a -> { CompletableFuture<Connection> future = client.connect(address).thenApply(connection -> { connection.onClose(c -> connections.remove(address, c)); connections.put(address, connection); return connection; }); future.whenComplete((connection, error) -> connectionFutures.remove(address)); return future; }); }
/** * Attempts to connect to the cluster. */ private void connect(CompletableFuture<Connection> future) { if (!selector.hasNext()) { LOGGER.debug("{} - Failed to connect to the cluster", id); future.complete(null); } else { Address address = selector.next(); LOGGER.debug("{} - Connecting to {}", id, address); client.connect(address).whenComplete((c, e) -> handleConnection(address, c, e, future)); } }
/** * Attempts to connect to the cluster. */ private void connect(CompletableFuture<Connection> future) { if (!selector.hasNext()) { LOGGER.debug("{} - Failed to connect to the cluster", id); future.complete(null); } else { Address address = selector.next(); LOGGER.debug("{} - Connecting to {}", id, address); client.connect(address).whenComplete((c, e) -> handleConnection(address, c, e, future)); } }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ private CompletableFuture<Connection> createConnection(Address address) { return client.connect(address).thenApply(connection -> { connections.put(address.hashCode(), connection); connection.closeListener(c -> connections.remove(address.hashCode())); return connection; }); }
/** * Attempts to connect to the cluster. */ private void connect(CompletableFuture<Connection> future) { if (!selector.hasNext()) { LOGGER.debug("Failed to connect to the cluster"); future.complete(null); } else { Address address = selector.next(); LOGGER.debug("Connecting to {}", address); client.connect(address).whenComplete((c, e) -> handleConnection(address, c, e, future)); } }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ CompletableFuture<Connection> createConnection(Address address) { return client.connect(address).thenApply(connection -> { connections.put(address.hashCode(), connection); connection.closeListener(c -> connections.remove(address.hashCode())); return connection; }); }
client.connect(new Address(new InetSocketAddress(InetAddress.getByName("localhost"), 5555))).thenAccept(connection -> { connection.send("Hello world!").thenAccept(response -> { threadAssertEquals("Hello world back!", response);
client.connect(new Address(new InetSocketAddress(InetAddress.getByName("localhost"), 5555))).thenAccept(connection -> { connection.sendAndReceive("Hello world!").thenAccept(response -> { threadAssertEquals("Hello world back!", response);
/** * Sets up a server state. */ @Override @BeforeMethod void beforeMethod() throws Throwable { super.beforeMethod(); registry = new LocalServerRegistry(); transport = new LocalTransport(registry); clientCtx = new SingleThreadContext("test-context", serializer.clone()); server = transport.server(); client = transport.client(); serverCtx.execute(() -> { server.listen(members.get(0).clientAddress(), serverContext::connectClient).whenComplete((result, error) -> { threadAssertNull(error); resume(); }); }); await(); clientCtx.execute(() -> { client.connect(members.get(0).clientAddress()).whenComplete((result, error) -> { threadAssertNull(error); this.connection = result; resume(); }); }); await(); }
client.connect(new Address(new InetSocketAddress(InetAddress.getByName("localhost"), 5556))).thenAccept(connection -> { connection.sendAndReceive(new NotSerializable()).whenComplete((result, error) -> { threadAssertNotNull(error);