@Override public boolean isOpen() { return socketChannel.isOpen(); }
@Override public boolean isOpen() { return socketChannel.isOpen(); }
/** * Only used in order to allow testing */ protected boolean isSocketOpen() { return sock.isOpen(); }
@Override public boolean isOpen() { return socketChannel.isOpen(); }
@Override public boolean isOpen() { return socketChannel.isOpen(); }
@Override public boolean isConnectionOpen() { return channel.isOpen(); }
@Override public boolean isOpen() { return channel != null && channel.isOpen(); }
public InetAddress getSocketAddress() { if (sock.isOpen() == false) { return null; } return sock.socket().getInetAddress(); }
@Override public InetSocketAddress getRemoteSocketAddress() { if (sock.isOpen() == false) { return null; } return (InetSocketAddress) sock.socket().getRemoteSocketAddress(); }
@Override public boolean isOpen() { return getChannel().isOpen(); }
@Override public boolean isOpen() { return getChannel().isOpen(); }
public synchronized void freeTCPSocket( SocketChannel sock ) { assert 0 <= _socksAvail && _socksAvail < _socks.length; if( sock != null && !sock.isOpen() ) sock = null; _socks[_socksAvail++] = sock; assert TCPS.get() > 0; if( sock == null ) TCPS.decrementAndGet(); notify(); }
/** * Close resources associated with the sock of this cnxn. */ private void closeSock() { if (sock.isOpen() == false) { return; } LOG.debug("Closed socket connection for client " + sock.socket().getRemoteSocketAddress() + (sessionId != 0 ? " which had sessionid 0x" + Long.toHexString(sessionId) : " (no session established for client)")); closeSock(sock); }
@Override public boolean isActive() { SocketChannel ch = javaChannel(); return ch.isOpen() && ch.isConnected(); }
@Override public boolean isActive() { SocketChannel ch = javaChannel(); return ch.isOpen() && ch.isConnected(); }
public void close() throws IOException { sslEngine.closeOutbound(); sslEngine.getSession().invalidate(); if( socketChannel.isOpen() ) socketChannel.write( wrap( emptybuffer ) );// FIXME what if not all bytes can be written socketChannel.close(); }
@Override public boolean isActive() { SocketChannel ch = javaChannel(); return ch.isOpen() && ch.isConnected(); }
@Override protected Executor prepareToClose() { try { if (javaChannel().isOpen() && config().getSoLinger() > 0) { // We need to cancel this key of the channel so we may not end up in a eventloop spin // because we try to read or write until the actual close happens which may be later due // SO_LINGER handling. // See https://github.com/netty/netty/issues/4449 doDeregister(); return GlobalEventExecutor.INSTANCE; } } catch (Throwable ignore) { // Ignore the error as the underlying channel may be closed in the meantime and so // getSoLinger() may produce an exception. In this case we just return null. // See https://github.com/netty/netty/issues/4449 } return null; } }
@Override protected Executor prepareToClose() { try { if (javaChannel().isOpen() && config().getSoLinger() > 0) { // We need to cancel this key of the channel so we may not end up in a eventloop spin // because we try to read or write until the actual close happens which may be later due // SO_LINGER handling. // See https://github.com/netty/netty/issues/4449 doDeregister(); return GlobalEventExecutor.INSTANCE; } } catch (Throwable ignore) { // Ignore the error as the underlying channel may be closed in the meantime and so // getSoLinger() may produce an exception. In this case we just return null. // See https://github.com/netty/netty/issues/4449 } return null; } }
@Test public void registerFailure() throws Exception { ChannelBuilder channelBuilder = new PlaintextChannelBuilder(null) { @Override public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize, MemoryPool memoryPool) throws KafkaException { throw new RuntimeException("Test exception"); } @Override public void close() { } }; Selector selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", channelBuilder, new LogContext()); SocketChannel socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); try { selector.register("1", socketChannel); fail("Register did not fail"); } catch (IOException e) { assertTrue("Unexpected exception: " + e, e.getCause().getMessage().contains("Test exception")); assertFalse("Socket not closed", socketChannel.isOpen()); } selector.close(); }