@Override protected EventExecutor executor() { if (ctx == null) { throw new IllegalStateException(); } return ctx.executor(); }
@Override public void window(int initialWindowSize) { assert ctx == null || ctx.executor().inEventLoop(); window = processedWindow = initialStreamWindowSize = initialWindowSize; }
@Override public void windowUpdateRatio(float ratio) { assert ctx == null || ctx.executor().inEventLoop(); streamWindowUpdateRatio = ratio; }
ClosingChannelFutureListener(final ChannelHandlerContext ctx, final ChannelPromise promise, long timeout, TimeUnit unit) { this.ctx = ctx; this.promise = promise; timeoutTask = ctx.executor().schedule(new Runnable() { @Override public void run() { ctx.close(promise); } }, timeout, unit); }
/** * Returns the number of pending write operations. */ public int size() { assert ctx.executor().inEventLoop(); return size; }
/** * Returns the total number of bytes that are pending because of pending messages. This is only an estimate so * it should only be treated as a hint. */ public long bytes() { assert ctx.executor().inEventLoop(); return bytes; }
/** * This method is visible for testing! */ ScheduledFuture<?> schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit) { return ctx.executor().schedule(task, delay, unit); }
/** * Return the current message or {@code null} if empty. */ public Object current() { assert ctx.executor().inEventLoop(); PendingWrite write = head; if (write == null) { return null; } return write.msg; }
/** * Returns {@code true} if there are no pending write operations left in this queue. */ public boolean isEmpty() { assert ctx.executor().inEventLoop(); return head == null; }
/** * Performs TLS renegotiation. */ public Future<Channel> renegotiate() { ChannelHandlerContext ctx = this.ctx; if (ctx == null) { throw new IllegalStateException(); } return renegotiate(ctx.executor().<Channel>newPromise()); }
@Override public final void handlerAdded0(ChannelHandlerContext ctx) throws Exception { if (ctx.executor() != ctx.channel().eventLoop()) { throw new IllegalStateException("EventExecutor must be EventLoop of Channel"); } this.ctx = ctx; }
@Override public void initialWindowSize(int newWindowSize) throws Http2Exception { assert ctx == null || ctx.executor().inEventLoop(); monitor.initialWindowSize(newWindowSize); }
/** * The window update ratio is used to determine when a window update must be sent. If the ratio * of bytes processed since the last update has meet or exceeded this ratio then a window update will * be sent. This is the global window update ratio that will be used for new streams. * @param ratio the ratio to use when checking if a {@code WINDOW_UPDATE} is determined necessary for new streams. * @throws IllegalArgumentException If the ratio is out of bounds (0, 1). */ public void windowUpdateRatio(float ratio) { assert ctx == null || ctx.executor().inEventLoop(); checkValidRatio(ratio); windowUpdateRatio = ratio; }
/** * The default implementation will simply call {@link AsyncMapping#map(Object, Promise)} but * users can override this method to implement custom behavior. * * @see AsyncMapping#map(Object, Promise) */ @Override protected Future<SslContext> lookup(ChannelHandlerContext ctx, String hostname) throws Exception { return mapping.map(hostname, ctx.executor().<SslContext>newPromise()); }
private void scheduleTimeout(final ChannelHandlerContext ctx, final ChannelPromise promise) { // Schedule a timeout. final WriteTimeoutTask task = new WriteTimeoutTask(ctx, promise); task.scheduledFuture = ctx.executor().schedule(task, timeoutNanos, TimeUnit.NANOSECONDS); if (!task.scheduledFuture.isDone()) { addWriteTimeoutTask(task); // Cancel the scheduled timeout if the flush promise is complete. promise.addListener(task); } }
@Override public void incrementWindowSize(Http2Stream stream, int delta) throws Http2Exception { assert ctx == null || ctx.executor().inEventLoop(); monitor.incrementWindowSize(state(stream), delta); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { TrafficCounter trafficCounter = new TrafficCounter(this, ctx.executor(), "ChannelTC" + ctx.channel().hashCode(), checkInterval); setTrafficCounter(trafficCounter); trafficCounter.start(); super.handlerAdded(ctx); }
@Override public void initialWindowSize(int newWindowSize) throws Http2Exception { assert ctx == null || ctx.executor().inEventLoop(); int delta = newWindowSize - initialWindowSize; initialWindowSize = newWindowSize; WindowUpdateVisitor visitor = new WindowUpdateVisitor(delta); connection.forEachActiveStream(visitor); visitor.throwIfError(); }
@Override public void incrementWindowSize(Http2Stream stream, int delta) throws Http2Exception { assert ctx != null && ctx.executor().inEventLoop(); FlowState state = state(stream); // Just add the delta to the stream-specific initial window size so that the next time the window // expands it will grow to the new initial size. state.incrementInitialStreamWindow(delta); state.writeWindowUpdateIfNeeded(); }
@Override public void addFlowControlled(Http2Stream stream, FlowControlled frame) { // The context can be null assuming the frame will be queued and send later when the context is set. assert ctx == null || ctx.executor().inEventLoop(); checkNotNull(frame, "frame"); try { monitor.enqueueFrame(state(stream), frame); } catch (Throwable t) { frame.error(ctx, t); } }