@Test // This tests using NetSocket.writeHandlerID (on the server side) // Send some data and make sure it is fanned out to all connections public void testFanout() throws Exception { int numConnections = 10; Set<String> connections = new ConcurrentHashSet<>(); server.connectHandler(socket -> { connections.add(socket.writeHandlerID()); if (connections.size() == numConnections) { for (String actorID : connections) { vertx.eventBus().publish(actorID, Buffer.buffer("some data")); } } socket.closeHandler(v -> { connections.remove(socket.writeHandlerID()); }); }); startServer(); CountDownLatch receivedLatch = new CountDownLatch(numConnections); for (int i = 0; i < numConnections; i++) { client.connect(testAddress, onSuccess(socket -> { socket.handler(data -> { receivedLatch.countDown(); }); })); } assertTrue(receivedLatch.await(10, TimeUnit.SECONDS)); testComplete(); }
@Test // This tests using NetSocket.writeHandlerID (on the server side) // Send some data and make sure it is fanned out to all connections public void testFanout() throws Exception { int numConnections = 10; Set<String> connections = new ConcurrentHashSet<>(); server.connectHandler(socket -> { connections.add(socket.writeHandlerID()); if (connections.size() == numConnections) { for (String actorID : connections) { vertx.eventBus().publish(actorID, Buffer.buffer("some data")); } } socket.closeHandler(v -> { connections.remove(socket.writeHandlerID()); }); }); startServer(); CountDownLatch receivedLatch = new CountDownLatch(numConnections); for (int i = 0; i < numConnections; i++) { client.connect(testAddress, onSuccess(socket -> { socket.handler(data -> { receivedLatch.countDown(); }); })); } assertTrue(receivedLatch.await(10, TimeUnit.SECONDS)); testComplete(); }
/** * When a <code>NetSocket</code> is created it automatically registers an event handler with the event bus, the ID of that * handler is given by <code>writeHandlerID</code>. * <p> * Given this ID, a different event loop can send a buffer to that event handler using the event bus and * that buffer will be received by this instance in its own event loop and written to the underlying connection. This * allows you to write data to other connections which are owned by different event loops. * @return the write handler ID */ public String writeHandlerID() { String ret = delegate.writeHandlerID(); return ret; }
/** * When a <code>NetSocket</code> is created it automatically registers an event handler with the event bus, the ID of that * handler is given by <code>writeHandlerID</code>. * <p> * Given this ID, a different event loop can send a buffer to that event handler using the event bus and * that buffer will be received by this instance in its own event loop and written to the underlying connection. This * allows you to write data to other connections which are owned by different event loops. * @return the write handler ID */ public String writeHandlerID() { String ret = delegate.writeHandlerID(); return ret; }
protected void closeConnection() { logger.debug("net-socket will be closed ... " + netSocket.writeHandlerID()); netSocket.close(); }
private WireConnection createConnection(RLPxConnection conn, NetSocket netSocket) { String id = UUID.randomUUID().toString(); WireConnection wireConnection = new WireConnection(id, conn.publicKey().bytes(), conn.peerPublicKey().bytes(), logger, message -> { synchronized (conn) { Bytes bytes = conn.write(message); vertx.eventBus().send(netSocket.writeHandlerID(), Buffer.buffer(bytes.toArrayUnsafe())); } }, netSocket::end, handlers, DEVP2P_VERSION, clientId, advertisedPort()); wireConnections.put(wireConnection.id(), wireConnection); return wireConnection; }
public void start() { netSocket.handler(this); netSocket.exceptionHandler(event -> { String clientInfo = getClientInfo(); logger.error(clientInfo + ", net-socket closed ... " + netSocket.writeHandlerID() + " error: " + event.getMessage(), event.getCause()); handleWillMessage(); shutdown(); }); netSocket.closeHandler(aVoid -> { String clientInfo = getClientInfo(); logger.info(clientInfo + ", net-socket closed ... " + netSocket.writeHandlerID()); handleWillMessage(); shutdown(); }); }
client.close(); }); writeHandlerId.compareAndSet(null, socket.writeHandlerID()); latch.countDown();
}); final Session session = new Session(); session.setHandler(asyncResult.result().writeHandlerID()); sessions.put(sid.toString(), session); registerTimerOut(session, client);
NetSocket netSocket = netSocketAsyncResult.result(); connected = true; logger.info("Bridge Client - connected to server [" + remoteBridgeHost + ":" + remoteBridgePort + "] " + netSocket.writeHandlerID()); logger.info("Bridge Client - closed connection from server [" + remoteBridgeHost + ":" + remoteBridgePort + "] " + netSocket.writeHandlerID()); ebnb.stop(); connected = false;