/** * Drops non-source specific membership in a multicast group. * If this connection doesn't have non-source specific membership in the group * on the given interface to receive datagrams then this method call * has no effect. Otherwise this connection drops the group membership. * * @param group The multicast address to join * @param networkInterface The network interface on which to join the group * * @throws IOException */ public void drop(final InetAddress group, final NetworkInterface networkInterface) throws IOException { drop(group, networkInterface, null); }
/** * Joins a multicast group to begin receiving all datagrams sent to the * group. If this connection is currently a member of the group on the given * interface to receive all datagrams then this method call has no effect. * Otherwise this connection joins the requested group and channel's * membership in not source-specific. * * A multicast connection may join several multicast groups, including the * same group on more than one interface. An implementation may impose a * limit on the number of groups that may be joined at the same time. * * @param group The multicast address to join * @param networkInterface The network interface on which to join the group * * @throws IOException */ public void join(final InetAddress group, final NetworkInterface networkInterface) throws IOException { join(group, networkInterface, null); }
/** * Method will be called, when some data was read on the connection */ protected final void onRead(Buffer data, int size) { if (size > 0) { notifyProbesRead(this, data, size); } checkEmptyRead(size); }
final Object key = it.next(); if (networkInterface.equals(networkInterface0(key)) && sourceAddress0(key) == null) { block0(key, source);
@Override public void onComplete(final Context context, final Object data) throws IOException { final UDPNIOConnection connection = (UDPNIOConnection) context.getConnection(); if (completionHandler != null) { completionHandler.completed(connection); } if (!connection.isStandalone()) { connection.enableInitialOpRead(); } }
final Object key = it.next(); if (networkInterface.equals(networkInterface0(key))) { drop0(key); it.remove();
protected void addRecord(Connection connection, Buffer buffer, CompletionHandler completionHandler, Interceptor<ReadResult> interceptor) { final AsyncReadQueueRecord record = AsyncReadQueueRecord.create( connection, buffer, completionHandler, interceptor); ((UDPNIOConnection) connection).getAsyncReadQueue().offer(record); }
UDPNIOConnection obtainNIOConnection(DatagramChannel channel) { UDPNIOConnection connection = new UDPNIOConnection(this, channel); configureNIOConnection(connection); return connection; }
private static void abortConnection(final UDPNIOConnection connection, final CompletionHandler<Connection> completionHandler, final Throwable failure) { connection.closeSilently(); if (completionHandler != null) { completionHandler.failed(failure); } }
private int readConnected(final UDPNIOConnection connection, Buffer buffer, final ReadResult<Buffer, SocketAddress> currentResult) throws IOException { final int read; final int oldPos = buffer.position(); if (buffer.isComposite()) { final ByteBufferArray array = buffer.toByteBufferArray(); final ByteBuffer[] byteBuffers = array.getArray(); final int size = array.size(); read = (int) ((DatagramChannel) connection.getChannel()).read(byteBuffers, 0, size); array.restore(); array.recycle(); } else { read = ((DatagramChannel) connection.getChannel()).read( buffer.toByteBuffer()); } final boolean hasRead = (read > 0); if (hasRead) { buffer.position(oldPos + read); } if (hasRead && currentResult != null) { currentResult.setMessage(buffer); currentResult.setReadSize(currentResult.getReadSize() + read); currentResult.setSrcAddressHolder(connection.peerSocketAddressHolder); } return read; }
@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); } }
final Object key = it.next(); if (networkInterface.equals(networkInterface0(key)) && sourceAddress0(key) == null) { block0(key, source);
@Override public void onComplete(final Context context, final Object data) throws IOException { final UDPNIOConnection connection = (UDPNIOConnection) context.getConnection(); if (completionHandler != null) { completionHandler.completed(connection); } if (!connection.isStandalone()) { connection.enableInitialOpRead(); } }
final Object key = it.next(); if (networkInterface.equals(networkInterface0(key))) { drop0(key); it.remove();
protected void addRecord(Connection connection, Buffer buffer, CompletionHandler completionHandler, Interceptor<ReadResult> interceptor) { final AsyncReadQueueRecord record = AsyncReadQueueRecord.create( connection, buffer, completionHandler, interceptor); ((UDPNIOConnection) connection).getAsyncReadQueue().offer(record); }
UDPNIOConnection obtainNIOConnection(DatagramChannel channel) { UDPNIOConnection connection = new UDPNIOConnection(this, channel); configureNIOConnection(connection); return connection; }
private static void abortConnection(final UDPNIOConnection connection, final CompletionHandler<Connection> completionHandler, final Throwable failure) { connection.closeSilently(); if (completionHandler != null) { completionHandler.failed(failure); } }
private int readConnected(final UDPNIOConnection connection, Buffer buffer, final ReadResult<Buffer, SocketAddress> currentResult) throws IOException { final int read; final int oldPos = buffer.position(); if (buffer.isComposite()) { final ByteBufferArray array = buffer.toByteBufferArray(); final ByteBuffer[] byteBuffers = array.getArray(); final int size = array.size(); read = (int) ((DatagramChannel) connection.getChannel()).read(byteBuffers, 0, size); array.restore(); array.recycle(); } else { read = ((DatagramChannel) connection.getChannel()).read( buffer.toByteBuffer()); } final boolean hasRead = (read > 0); if (hasRead) { buffer.position(oldPos + read); } if (hasRead && currentResult != null) { currentResult.setMessage(buffer); currentResult.setReadSize(currentResult.getReadSize() + read); currentResult.setSrcAddressHolder(connection.peerSocketAddressHolder); } return read; }
final Object key = it.next(); if (networkInterface.equals(networkInterface0(key)) && sourceAddress0(key) == null) { block0(key, source);
/** * Method will be called, when some data was read on the connection */ protected final void onRead(Buffer data, int size) { if (size > 0) { notifyProbesRead(this, data, size); } checkEmptyRead(size); }