@Override public void run() { channel.write(new MessageHeader(id, Rpc.MessageType.CALL)).addListener(listener); channel.writeAndFlush(msg).addListener(listener); } });
private void flushPendingWrites(PendingWrites pendingWrites) { for (;;) { final Entry<HttpObject, ChannelPromise> e = pendingWrites.poll(); if (e == null) { break; } ch.write(e.getKey(), e.getValue()); } }
private void writeQuery(final DnsQuery query, final boolean flush, final ChannelPromise writePromise) { final ChannelFuture writeFuture = flush ? parent.ch.writeAndFlush(query, writePromise) : parent.ch.write(query, writePromise); if (writeFuture.isDone()) { onQueryWriteCompletion(writeFuture); } else { writeFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { onQueryWriteCompletion(writeFuture); } }); } }
private static void writeBufferedBodyContent(final HttpRequestMessage zuulRequest, final Channel channel) { zuulRequest.getBodyContents().forEach((chunk) -> { channel.write(chunk.retain()); }); }
@Override public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { LOG.error(String.format("[%s] Closing channel due to exception in pipeline.", name()), cause); if (lastHeader != null) { // There's an RPC waiting for a reply. Exception was most probably caught while processing // the RPC, so send an error. ctx.channel().write(new Rpc.MessageHeader(lastHeader.id, Rpc.MessageType.ERROR)); ctx.channel().writeAndFlush(Throwables.getStackTraceAsString(cause)); lastHeader = null; } ctx.close(); }
private static void writeBufferedBodyContent(final HttpResponseMessage zuulResponse, final Channel channel) { zuulResponse.getBodyContents().forEach(chunk -> channel.write(chunk.retain())); }
private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, HttpResponse res, ChannelPromise promise) { channel.write(res); if (log.isTraceEnabled()) { if (msg.getSessionId() != null) { log.trace("Out message: {} - sessionId: {}", out.toString(CharsetUtil.UTF_8), msg.getSessionId()); } else { log.trace("Out message: {}", out.toString(CharsetUtil.UTF_8)); } } if (out.isReadable()) { channel.write(new DefaultHttpContent(out)); } else { out.release(); } channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, promise).addListener(ChannelFutureListener.CLOSE); }
private ChannelFuture sendPkt(Packet p, boolean doFlush) { // Assuming the packet will be sent out successfully. Because if it fails, // the channel will close and clean up queues. p.createBB(); updateLastSend(); ChannelFuture result = channel.write(Unpooled.wrappedBuffer(p.bb)); result.addListener(f -> { if (f.isSuccess()) { sentCount.getAndIncrement(); } }); if (doFlush) { channel.flush(); } return result; }
@Override public void write(Channel channel, NettyResponseFuture<?> future) throws IOException { @SuppressWarnings("resource") // netty will close the FileChannel FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel(); boolean noZeroCopy = ChannelManager.isSslHandlerConfigured(channel.pipeline()) || config.isDisableZeroCopy(); Object body = noZeroCopy ? new ChunkedNioFile(fileChannel, offset, length, config.getChunkedFileChunkSize()) : new DefaultFileRegion(fileChannel, offset, length); channel.write(body, channel.newProgressivePromise()) .addListener(new WriteProgressListener(future, false, length)); channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise()); } }
void sendPacket(byte[] wire, InetSocketAddress address) { DatagramPacket packet = new DatagramPacket(Unpooled.copiedBuffer(wire), address); channel.write(packet); channel.flush(); }
@Override public ChannelGroupFuture write(Object message, ChannelMatcher matcher, boolean voidPromise) { if (message == null) { throw new NullPointerException("message"); } if (matcher == null) { throw new NullPointerException("matcher"); } final ChannelGroupFuture future; if (voidPromise) { for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { c.write(safeDuplicate(message), c.voidPromise()); } } future = voidFuture; } else { Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.write(safeDuplicate(message))); } } future = new DefaultChannelGroupFuture(this, futures, executor); } ReferenceCountUtil.release(message); return future; }
private void writeToChannel(ByteBuf message) { channel.write(message, channel.voidPromise()); if (!needChannelFlush.getAndSet(true)) { this.lastExecutor.execute(flusher); } }
private ChannelFuture channelWrite(RedisCommand<?, ?, ?> command) { if (debugEnabled) { logger.debug("{} write() channelWrite command {}", logPrefix(), command); } return channel.write(command); }
protected int sendHttpRequest(FullHttpRequest httpRequest, AbstractHttpClientHandler callback) { final int requestId = streamId.getAndAdd(2); Channel channel = this.channel.channel(); responseChannelHandler.put(requestId, channel.write(httpRequest), callback); channel.flush(); return requestId; }
protected int sendHttpRequest(FullHttpRequest httpRequest, AbstractHttpClientHandler callback) { final int requestId = streamId.getAndAdd(2); Channel channel = this.channel.channel(); responseChannelHandler.put(requestId, channel.write(httpRequest), callback); channel.flush(); return requestId; }
private static void writeBufferedBodyContent(final HttpRequestMessage zuulRequest, final Channel channel) { zuulRequest.getBodyContents().forEach((chunk) -> { channel.write(chunk.retain()); }); }
private static void writeBufferedBodyContent(final HttpResponseMessage zuulResponse, final Channel channel) { zuulResponse.getBodyContents().forEach(chunk -> channel.write(chunk.retain())); }
@Override public void sendAppSync(Channel appChannel, int dashId, int targetId, boolean useNewSyncFormat) { if (isNotValid() || lastCommands.size() == 0) { return; } if (targetId == ANY_TARGET || this.deviceId == targetId) { for (String storedValue : lastCommands) { String body = prependDashIdAndDeviceId(dashId, deviceId, makeHardwareBody(pinType, pin, storedValue)); appChannel.write(makeUTF8StringMessage(APP_SYNC, SYNC_DEFAULT_MESSAGE_ID, body)); } } }
private void writeClientRequestToOrigin(final PooledConnection conn) { final Channel ch = conn.getChannel(); passport.setOnChannel(ch); context.set(ORIGIN_CHANNEL, ch); context.set(POOLED_ORIGIN_CONNECTION_KEY, conn); preWriteToOrigin(chosenServer.get(), zuulRequest); final ChannelPipeline pipeline = ch.pipeline(); originResponseReceiver = getOriginResponseReceiver(); pipeline.addBefore("connectionPoolHandler", OriginResponseReceiver.CHANNEL_HANDLER_NAME, originResponseReceiver); // check if body needs to be repopulated for retry repopulateRetryBody(); ch.write(zuulRequest); writeBufferedBodyContent(zuulRequest, ch); ch.flush(); //Get ready to read origin's response ch.read(); originConn = conn; channelCtx.read(); }
private void writeClientRequestToOrigin(final PooledConnection conn) { final Channel ch = conn.getChannel(); passport.setOnChannel(ch); context.set(ORIGIN_CHANNEL, ch); context.set(POOLED_ORIGIN_CONNECTION_KEY, conn); preWriteToOrigin(chosenServer.get(), zuulRequest); final ChannelPipeline pipeline = ch.pipeline(); originResponseReceiver = getOriginResponseReceiver(); pipeline.addBefore("connectionPoolHandler", OriginResponseReceiver.CHANNEL_HANDLER_NAME, originResponseReceiver); // check if body needs to be repopulated for retry repopulateRetryBody(); ch.write(zuulRequest); writeBufferedBodyContent(zuulRequest, ch); ch.flush(); //Get ready to read origin's response ch.read(); originConn = conn; channelCtx.read(); }