public RemoteConnection(SocketChannel channel, String name, boolean blockOnSocket) { super(); this.channel = channel; this.clientName = name; this.writeManager = new WriteManager(); this.requestIdMap = new RequestIdMap(getName()); if(!blockOnSocket){ writeManager.disable(); } channel.pipeline() .addLast(BACK_PRESSURE_HANDLER, new BackPressureHandler()); }
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { writeManager.setWritable(ctx.channel().isWritable()); ctx.fireChannelWritabilityChanged(); }
boolean blockOnNotWritable(RpcOutcomeListener<?> listener) { try { writeManager.waitForWritable(); return true; } catch (final InterruptedException e) { listener.interrupted(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(); return false; } }
/** * Called from the RpcBus's channel close handler to close all remaining * resources associated with this connection. Ensures that any pending * back-pressure items are also unblocked so they can be thrown away. * * @param ex * The exception that caused the channel to close. */ void channelClosed(RpcException ex) { // this could possibly overrelease but it doesn't matter since we're only // going to do this to ensure that we // fail out any pending messages writeManager.disable(); writeManager.setWritable(true); // ensure outstanding requests are cleaned up. requestIdMap.channelClosed(ex); }
protected RemoteConnection(RemoteConnection connection){ this.channel = connection.channel; this.clientName = connection.clientName; this.writeManager = new WriteManager(); this.requestIdMap = new RequestIdMap(getName()); writeManager.disable(); }