/** * Constructs an instance with an arbitrary UUID. * * @param origin the origin connected to * @param channel the netty channel used * @param requestOperationFactory used to create operation objects that send http requests via this connection */ @VisibleForTesting public NettyConnection(Origin origin, Channel channel, HttpRequestOperationFactory requestOperationFactory) { this.origin = checkNotNull(origin); this.channel = checkNotNull(channel); this.requestOperationFactory = requestOperationFactory; this.channel.pipeline().addLast(new TimeToFirstByteHandler(this)); this.channel.closeFuture().addListener(future -> listeners.announce().connectionClosed(NettyConnection.this)); }
@Override public void close() { // To avoid infinite recursion: if (connected) { connected = false; listeners.announce().connectionClosed(this); } }