public boolean isActive() { return connection != null && connection.getChannel() != null && connection.getChannel().isActive(); }
@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 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(); } } } }
@Override public void run() { try { closeLatch.await(); ((RemoteConnection)connection).getChannel().close(); } catch (InterruptedException e) { } }
ChannelListenerWithCoordinationId futureListener = connection.createNewRpcListener(listener, clazz); OutboundRpcMessage m = new OutboundRpcMessage(RpcMode.REQUEST, rpcType, futureListener.getCoordinationId(), protobufBody, dataBodies); ChannelFuture channelFuture = connection.getChannel().writeAndFlush(m); channelFuture.addListener(futureListener); channelFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@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(); } }