@Override public ChannelPromise voidPromise() { return ctx.voidPromise(); }
@Override public ChannelPromise voidPromise() { return ctx.voidPromise(); }
@Override public ChannelPromise voidPromise() { return ctx.voidPromise(); }
@Override public ChannelPromise voidPromise() { return ctx.voidPromise(); }
@Override @SuppressWarnings("unchecked") public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { final Channel channel = ctx.channel(); final String request = (String)msg; try { ctx.writeAndFlush(request, ctx.voidPromise()); LOGGER.info("client:" + msg); } catch (Exception e) { LOGGER.error("when try flush error", e); } }
private static void writeVoidPromise(ChannelHandlerContext ctx, CodecOutputList out) { final ChannelPromise voidPromise = ctx.voidPromise(); for (int i = 0; i < out.size(); i++) { ctx.write(out.getUnsafe(i), voidPromise); } }
if (entry == null) { if (previousBuf != null) { ctx.write(previousBuf, ctx.voidPromise()); ctx.write(previousBuf, ctx.voidPromise());
private static void writeVoidPromise(ChannelHandlerContext ctx, CodecOutputList out) { final ChannelPromise voidPromise = ctx.voidPromise(); for (int i = 0; i < out.size(); i++) { ctx.write(out.getUnsafe(i), voidPromise); } }
private void sendRedirectResponse(ChannelHandlerContext ctx, String token, String server, int msgId) { MessageBase response; if (server == null || server.equals(holder.props.host)) { log.debug("HardwareLogic token is invalid. Token '{}', '{}'", token, ctx.channel().remoteAddress()); response = invalidToken(msgId); } else { log.debug("Redirecting token '{}' to {}", token, server); response = makeASCIIStringMessage(CONNECT_REDIRECT, msgId, server + BODY_SEPARATOR + listenPort); } ctx.writeAndFlush(response, ctx.voidPromise()); }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var dashId = Integer.parseInt(message.body); deleteDash(holder, state, dashId); state.user.lastModifiedTs = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { if (ctx.channel().isWritable()) { ctx.writeAndFlush(makeASCIIStringMessage(GET_ENERGY, message.id, "" + user.energy), ctx.voidPromise()); } }
@Override public void run() { if (log.isDebugEnabled()) { log.debug("[{}] [{}] Sending message cnx {}, sequenceId {}", producer.topic, producer.producerName, cnx, sequenceId); } try { cnx.ctx().writeAndFlush(cmd, cnx.ctx().voidPromise()); } finally { recycle(); } }
/** * send the flow command to have the broker start pushing messages */ void sendFlowPermitsToBroker(ClientCnx cnx, int numMessages) { if (cnx != null) { if (log.isDebugEnabled()) { log.debug("[{}] [{}] Adding {} additional permits", topic, subscription, numMessages); } cnx.ctx().writeAndFlush(Commands.newFlow(consumerId, numMessages), cnx.ctx().voidPromise()); } }
private void writeResponse(ChannelHandlerContext ctx, HttpRequest request, ByteBuf buf, CharSequence contentType, CharSequence contentLength) { // Build the response object. FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf, false); HttpHeaders headers = response.headers(); headers.set(CONTENT_TYPE_ENTITY, contentType); headers.set(SERVER_ENTITY, SERVER_NAME); headers.set(DATE_ENTITY, date); headers.set(CONTENT_LENGTH_ENTITY, contentLength); // Close the non-keep-alive connection after the write operation is done. ctx.write(response, ctx.voidPromise()); } });
@Override public FullHttpResponse onByteBuf(Object byteBuf) { var httpResponse = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode())); for (Map.Entry<String, String> next : response.headers().entrySet()) { httpResponse.headers().set(next.getKey(), next.getValue()); } // Write the initial line and the header. if (request.keepAlive()) { httpResponse.headers().set(HttpConst.CONNECTION, KEEP_ALIVE); } context.write(httpResponse, context.voidPromise()); ChannelFuture lastContentFuture = context.writeAndFlush(byteBuf); if (!request.keepAlive()) { lastContentFuture.addListener(ChannelFutureListener.CLOSE); } return null; }
@Override public FullHttpResponse onByteBuf(Object byteBuf) { var httpResponse = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode())); for (Map.Entry<String, String> next : response.headers().entrySet()) { httpResponse.headers().set(next.getKey(), next.getValue()); } // Write the initial line and the header. if (request.keepAlive()) { httpResponse.headers().set(HttpConst.CONNECTION, KEEP_ALIVE); } context.write(httpResponse, context.voidPromise()); ChannelFuture lastContentFuture = context.writeAndFlush(byteBuf); if (!request.keepAlive()) { lastContentFuture.addListener(ChannelFutureListener.CLOSE); } return null; }
@Override public void write(HttpRequest<?> request, MutableHttpResponse<?> response, ChannelHandlerContext context) { if (response instanceof NettyMutableHttpResponse) { FullHttpResponse nettyResponse = ((NettyMutableHttpResponse) response).getNativeResponse(); // Write the request data context.write(new DefaultHttpResponse(nettyResponse.protocolVersion(), nettyResponse.status(), nettyResponse.headers()), context.voidPromise()); context.writeAndFlush(new HttpChunkedInput(new ChunkedStream(getInputStream()))); } else { throw new IllegalArgumentException("Unsupported response type. Not a Netty response: " + response); } } }
private void discardMessage(MessageIdData messageId, ClientCnx currentCnx, ValidationError validationError) { ByteBuf cmd = Commands.newAck(consumerId, messageId.getLedgerId(), messageId.getEntryId(), AckType.Individual, validationError, Collections.emptyMap()); currentCnx.ctx().writeAndFlush(cmd, currentCnx.ctx().voidPromise()); increaseAvailablePermits(currentCnx); stats.incrementNumReceiveFailed(); }
private boolean doImmediateAck(MessageIdImpl msgId, AckType ackType, Map<String, Long> properties) { ClientCnx cnx = consumer.getClientCnx(); if (cnx == null) { return false; } final ByteBuf cmd = Commands.newAck(consumer.consumerId, msgId.getLedgerId(), msgId.getEntryId(), ackType, null, properties); cnx.ctx().writeAndFlush(cmd, cnx.ctx().voidPromise()); return true; }
public void channelInactive(ChannelHandlerContext ctx) throws Exception { // Connection has terminated, close the encoder and decoder. encoder().close(); decoder().close(); // We need to remove all streams (not just the active ones). // See https://github.com/netty/netty/issues/4838. connection().close(ctx.voidPromise()); }