public InetSocketAddress getLocalAddress() { InetSocketAddress localAddress = this.localAddress; if (localAddress == null) { try { this.localAddress = localAddress = getLocalSocketAddress(); } catch (Throwable t) { // Sometimes fails on a closed socket in Windows. return null; } } return localAddress; }
public ServerSocketChannel newChannel(ChannelPipeline pipeline) { return new OioServerSocketChannel(this, pipeline, sink); }
public InetSocketAddress getRemoteAddress() { InetSocketAddress remoteAddress = this.remoteAddress; if (remoteAddress == null) { try { this.remoteAddress = remoteAddress = getRemoteSocketAddress(); } catch (Throwable t) { // Sometimes fails on a closed socket in Windows. return null; } } return remoteAddress; }
@Override public void run() { boolean fireConnected = channel instanceof OioAcceptedSocketChannel; if (fireConnected && channel.isOpen()) { // Fire the channelConnected event for OioAcceptedSocketChannel. // See #287 fireChannelConnected(channel, channel.getRemoteAddress()); } super.run(); }
public boolean isConnected() { return isOpen() && isSocketConnected(); }
public boolean isBound() { return isOpen() && isSocketBound(); }
static void close(AbstractOioChannel channel, ChannelFuture future) { close(channel, future, isIoThread(channel)); }
public void eventSunk( ChannelPipeline pipeline, ChannelEvent e) throws Exception { Channel channel = e.getChannel(); if (channel instanceof OioServerSocketChannel) { handleServerSocket(e); } else if (channel instanceof OioAcceptedSocketChannel) { handleAcceptedSocket(e); } }
public ChannelFuture joinGroup(InetAddress multicastAddress) { ensureBound(); try { socket.joinGroup(multicastAddress); return succeededFuture(this); } catch (IOException e) { return failedFuture(this, e); } }
public SocketChannel newChannel(ChannelPipeline pipeline) { return new OioClientSocketChannel(this, pipeline, sink); }
public DatagramChannel newChannel(ChannelPipeline pipeline) { return new OioDatagramChannel(this, pipeline, sink); }
/** * Creates a new instance. * * @param workerExecutor * the {@link Executor} which will execute the I/O worker threads * @param determiner * the {@link ThreadNameDeterminer} to set the thread names. */ public OioClientSocketChannelFactory(Executor workerExecutor, ThreadNameDeterminer determiner) { if (workerExecutor == null) { throw new NullPointerException("workerExecutor"); } this.workerExecutor = workerExecutor; sink = new OioClientSocketPipelineSink(workerExecutor, determiner); }
/** * Creates a new instance. * * @param workerExecutor * the {@link Executor} which will execute the I/O worker threads * @param determiner * the {@link ThreadNameDeterminer} to set the thread names. */ public OioDatagramChannelFactory(Executor workerExecutor, ThreadNameDeterminer determiner) { if (workerExecutor == null) { throw new NullPointerException("workerExecutor"); } this.workerExecutor = workerExecutor; sink = new OioDatagramPipelineSink(workerExecutor, determiner); }
private void ensureBound() { if (!isBound()) { throw new IllegalStateException( DatagramChannel.class.getName() + " must be bound to join a group."); } }
/** * Creates a new instance. * * @param bossExecutor * the {@link Executor} which will execute the boss threads * @param workerExecutor * the {@link Executor} which will execute the I/O worker threads * @param determiner * the {@link ThreadNameDeterminer} to set the thread names. */ public OioServerSocketChannelFactory(Executor bossExecutor, Executor workerExecutor, ThreadNameDeterminer determiner) { if (bossExecutor == null) { throw new NullPointerException("bossExecutor"); } if (workerExecutor == null) { throw new NullPointerException("workerExecutor"); } this.bossExecutor = bossExecutor; this.workerExecutor = workerExecutor; sink = new OioServerSocketPipelineSink(workerExecutor, determiner); }
@Override protected boolean isFireExceptionCaughtLater(ChannelEvent event, Throwable actualCause) { Channel channel = event.getChannel(); boolean fireLater = false; if (channel instanceof AbstractOioChannel) { fireLater = !AbstractOioWorker.isIoThread((AbstractOioChannel) channel); } return fireLater; }
public boolean isBound() { return isOpen() && socket.isBound(); }
@Override public ChannelFuture write(Object message, SocketAddress remoteAddress) { if (remoteAddress == null || remoteAddress.equals(getRemoteAddress())) { return super.write(message, null); } else { return super.write(message, remoteAddress); } }
private static void bind( OioClientSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { try { channel.socket.bind(localAddress); future.setSuccess(); fireChannelBound(channel, channel.getLocalAddress()); } catch (Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } }
public ChannelFuture joinGroup( InetSocketAddress multicastAddress, NetworkInterface networkInterface) { ensureBound(); try { socket.joinGroup(multicastAddress, networkInterface); return succeededFuture(this); } catch (IOException e) { return failedFuture(this, e); } }