Refine search
@Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { welcomeFuture = ctx.executor().schedule(new Runnable() { @Override public void run() { if (welcome != null) { ctx.write(Unpooled.wrappedBuffer(welcome.getBytes())); ctx.writeAndFlush(Unpooled.wrappedBuffer(prompt.getBytes())); } } }, 500, TimeUnit.MILLISECONDS); }
/** * Returns {@code true} if there are no pending write operations left in this queue. */ public boolean isEmpty() { assert ctx.executor().inEventLoop(); return head == null; }
/** * Returns the number of pending write operations. */ public int size() { assert ctx.executor().inEventLoop(); return size; }
@Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { welcomeFuture = ctx.executor().schedule(new Runnable() { @Override public void run() { if (welcome != null) { ctx.write(Unpooled.wrappedBuffer(welcome.getBytes())); ctx.writeAndFlush(Unpooled.wrappedBuffer(prompt.getBytes())); } } }, 500, TimeUnit.MILLISECONDS); }
/** * 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 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; }
/** * Returns {@code true} if there are no pending write operations left in this queue. */ public boolean isEmpty() { assert ctx.executor().inEventLoop(); return head == null; }
/** * Returns the number of pending write operations. */ public int size() { assert ctx.executor().inEventLoop(); return size; }
private ScheduledFuture<?> _scheduleNextTask(ChannelHandlerContext ctx, ReadTimeoutTask task, long timeoutNanos) { try { return ctx.executor().schedule(task, timeoutNanos, TimeUnit.NANOSECONDS); } catch (Exception e) { logger.error("Failed to schedule read timeout task. Read timeout will not work on channel: " + ctx.channel(), e); throw e; } }
/** * 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; }
private void initialize(ChannelHandlerContext ctx) { if (state.get() != State.NONE) { return; } state.set(State.INITIALIZED); EventExecutor loop = ctx.executor(); lastReadTimeNanos = lastWriteTimeNanos = System.nanoTime(); if (allIdleTimeNanos > 0) { loop.schedule(new AllIdleTimeoutTask(ctx), allIdleTimeNanos, TimeUnit.SECONDS); } }
/** * 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; }
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); } }
/** * Returns {@code true} if there are no pending write operations left in this queue. */ public boolean isEmpty() { assert ctx.executor().inEventLoop(); return head == null; }
private void requestClientToCloseConnection() { if (ctx.channel().isActive()) { // Application level protocol for asking client to close connection ctx.writeAndFlush(pushProtocol.goAwayMessage()); // Force close connection if client doesn't close in reasonable time after we made request ctx.executor().schedule(() -> forceCloseConnectionFromServerSide(), CLIENT_CLOSE_GRACE_PERIOD.get(), TimeUnit.SECONDS); } else { forceCloseConnectionFromServerSide(); } }
@Override public void window(int initialWindowSize) { assert ctx == null || ctx.executor().inEventLoop(); window = processedWindow = initialStreamWindowSize = initialWindowSize; }
@Override public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { ChannelFuture f = finishEncode(ctx, ctx.newPromise()); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture f) throws Exception { ctx.close(promise); } }); if (!f.isDone()) { // Ensure the channel is closed even if the write operation completes in time. ctx.executor().schedule(new Runnable() { @Override public void run() { ctx.close(promise); } }, 10, TimeUnit.SECONDS); // FIXME: Magic number } }