/** * 关闭 * * @throws InterruptedException */ public void close() throws InterruptedException { if (channel != null){ channel.close(); } } }
/** * Close connection. */ @Override public void close() { channel.close(); } }
/** * Close connection. */ @Override public void close() { channel.close(); } }
@Override public void close() { logger.debug("Closing client"); try { if (connection != null) { connection.getChannel().close().sync(); } } catch (final InterruptedException e) { logger.warn("Failure while shutting {}", this.getClass().getName(), e); // Preserve evidence that the interruption occurred so that code higher up on the call stack can learn of the // interruption and respond to it if it wants to. Thread.currentThread().interrupt(); } }
@Override public synchronized void close() throws IOException { ch.close().syncUninterruptibly(); }
@Override public void close() { if (closed.getAndSet(true)) { // Connection was already closed. Let's print out logger.info("Attempting to close connection again"); } CONNECTION_TYPE c = connectionHolder.getAndSet(null); if (c != null) { try { c.getChannel().close().sync(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
public void testWriteBeforeConnect(Bootstrap cb) throws Throwable { TestHandler h = new TestHandler(); SocketChannel ch = null; try { ch = (SocketChannel) cb.handler(h).connect(newSocketAddress()).channel(); ch.writeAndFlush(Unpooled.wrappedBuffer(new byte[] { 1 })); } finally { if (ch != null) { ch.close(); } } }
/** * Connection consumer wants to close connection. Initiate connection close * and complete. This is a blocking call that ensures that the connection is * closed before returning. As part of this call, the channel close handler * will be triggered which will call channelClosed() above. The latter will * happen in a separate thread while this method is blocking. */ @Override public void close() { try { if (channel.isActive()) { channel.close().get(); } } catch (final InterruptedException | ExecutionException e) { logger.warn("Caught exception while closing channel.", e); // Preserve evidence that the interruption occurred so that code higher up // on the call stack can learn of the // interruption and respond to it if it wants to. Thread.currentThread().interrupt(); } }
@Override public void initChannel(SocketChannel ch) throws Exception { _log.trace("channel initialized with remote address {}", ch.remoteAddress()); if (this.fish.getOrca() == null) { // orca not initialized ch.close(); return; } MysqlServerHandler handler = new MysqlServerHandler(fish, ch); ch.pipeline().addLast(new PacketDecoder(), handler); } }
@Override public void run() { try { closeLatch.await(); ((RemoteConnection)connection).getChannel().close(); } catch (InterruptedException e) { } }
futures.add(c.close()); } catch (Exception ex) { component.extLog.warn("Error during Netty shutdown. Messages might have been lost! \n {}", ex);
listener.connectionEstablished(NettyIoConnector.this, local, remote); } catch (Exception e) { ch.close(); throw e;
@Override public void close() { super.close(); closing = true; channel.disconnect().awaitUninterruptibly(); channel.close().awaitUninterruptibly(); }
listener.connectionAccepted(NettyIoAcceptor.this, local, remote); } catch (Exception e) { ch.close(); throw e;
public void testShutdownOutputAfterClosed(Bootstrap cb) throws Throwable { TestHandler h = new TestHandler(); ServerSocket ss = new ServerSocket(); Socket s = null; try { ss.bind(newSocketAddress()); SocketChannel ch = (SocketChannel) cb.handler(h).connect(ss.getLocalSocketAddress()).sync().channel(); assertTrue(ch.isActive()); s = ss.accept(); ch.close().syncUninterruptibly(); try { ch.shutdownInput().syncUninterruptibly(); fail(); } catch (Throwable cause) { checkThrowable(cause); } try { ch.shutdownOutput().syncUninterruptibly(); fail(); } catch (Throwable cause) { checkThrowable(cause); } } finally { if (s != null) { s.close(); } ss.close(); } }
public void testShutdownNotYetConnected(Bootstrap cb) throws Throwable { SocketChannel ch = (SocketChannel) cb.handler(new ChannelInboundHandlerAdapter()) .bind(newSocketAddress()).syncUninterruptibly().channel(); try { try { ch.shutdownInput().syncUninterruptibly(); fail(); } catch (Throwable cause) { checkThrowable(cause); } try { ch.shutdownOutput().syncUninterruptibly(); fail(); } catch (Throwable cause) { checkThrowable(cause); } } finally { ch.close().syncUninterruptibly(); } }
@Override public void handle(final PhysicalConnection connection, int rpcType, ByteString pBody, ByteBuf dBody, ResponseSender sender) throws RpcException { switch(rpcType){ case 1: sender.send(new Response(new FakeEnum(1), expectedD)); new Thread(){ @Override public void run() { try { closeLatch.await(); ((RemoteConnection)connection).getChannel().close(); } catch (InterruptedException e) { } } }.start(); return; case 2: ((RemoteConnection)connection).getChannel().close(); return; default: throw new UnsupportedOperationException(); } }