@Override public void run(final UDPNIOConnection connection) throws Exception { // construct destination multicast address to send the message to final InetSocketAddress peerAddr = new InetSocketAddress(groupAddr, ((InetSocketAddress) connection.getLocalAddress()).getPort()); // Create Future to be able to block until the message is sent final FutureImpl<WriteResult<String, SocketAddress>> writeFuture = Futures.createSafeFuture(); // Send the message connection.write(peerAddr, msg, Futures.toCompletionHandler(writeFuture)); // Block until the message is sent writeFuture.get(10, TimeUnit.SECONDS); } }
@Override public void run(final UDPNIOConnection connection) throws Exception { // Join the multicast group connection.join(groupAddr, ni, source); // construct destination multicast address to send the message to final InetSocketAddress peerAddr = new InetSocketAddress(groupAddr, ((InetSocketAddress) connection.getLocalAddress()).getPort()); // Create Future to be able to block until the message is sent final FutureImpl<WriteResult<String, SocketAddress>> writeFuture = Futures.createSafeFuture(); // Send the greeting message to group connection.write(peerAddr, "joined the group " + groupAddr, Futures.toCompletionHandler(writeFuture)); // Block until the message is sent writeFuture.get(10, TimeUnit.SECONDS); } }
@Override public void run(final UDPNIOConnection connection) throws Exception { // Drop the multicast group membership connection.drop(groupAddr, ni, source); try { // construct destination multicast address to send the message to final InetSocketAddress peerAddr = new InetSocketAddress(groupAddr, ((InetSocketAddress) connection.getLocalAddress()).getPort()); // Create Future to be able to block until the message is sent final FutureImpl<WriteResult<String, SocketAddress>> writeFuture = Futures.createSafeFuture(); // Send the leave message to the group connection.write(peerAddr, "left the group " + groupAddr, Futures.toCompletionHandler(writeFuture)); // Block until the message is sent writeFuture.get(10, TimeUnit.SECONDS); } catch (Exception e) { } } }