Java Code Examples for org.jboss.netty.channel.Channels#write()
The following examples show how to use
org.jboss.netty.channel.Channels#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyDispatcher.java From ikasoa with MIT License | 6 votes |
private void writeResponseInOrder(ChannelHandlerContext ctx, TNettyMessage response, int responseSequenceId) { synchronized (responseMap) { int currentResponseId = lastResponseWrittenId.get() + 1; if (responseSequenceId != currentResponseId) responseMap.put(responseSequenceId, response); else { // 写入下一行的response. do { Channels.write(ctx.getChannel(), response); lastResponseWrittenId.incrementAndGet(); ++currentResponseId; response = responseMap.remove(currentResponseId); } while (null != response); if (DispatcherContext.isChannelReadBlocked(ctx) && dispatcherSequenceId.get() <= lastResponseWrittenId.get() + queuedResponseLimit) DispatcherContext.unblockChannelReads(ctx); } } }
Example 2
Source File: ChannelEncoder.java From android-netty with Apache License 2.0 | 6 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent event) throws Exception { PowerManager.WakeLock wakeLock = WakeLockWrapper.getWakeLockInstance(mContext, ChannelEncoder.class.getSimpleName()); wakeLock.acquire(); try { String jsonString = event.getMessage().toString(); LogByCodeLab.i(String.format("WRITE [%s]", jsonString)); ChannelBuffer cb = new BigEndianHeapChannelBuffer(24); cb.writeBytes(new byte[24]); Channels.write(ctx, event.getFuture(), cb); } finally { wakeLock.release(); } }
Example 3
Source File: NettyUtils.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public static void write(Channel channel, ByteBuffer body, ChannelFutureListener channelFutureListner) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.limit()).array(); List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(2); components.add(ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, header)); components.add(ChannelBuffers.wrappedBuffer(body)); if (channelFutureListner == null) { Channels.write(channel, new CompositeChannelBuffer(ByteOrder.BIG_ENDIAN, components)); } else { Channels.write(channel, new CompositeChannelBuffer(ByteOrder.BIG_ENDIAN, components)) .addListener(channelFutureListner); } }
Example 4
Source File: NettyUtils.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
public static void write(Channel channel, byte[] body, ChannelFutureListener channelFutureListner) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.length).array(); if (channelFutureListner == null) { Channels.write(channel, ChannelBuffers.wrappedBuffer(header, body)); } else { Channels.write(channel, ChannelBuffers.wrappedBuffer(header, body)).addListener(channelFutureListner); } }
Example 5
Source File: RpcRequestEncode.java From voyage with Apache License 2.0 | 5 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { RpcRequest request = (RpcRequest) e.getMessage(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); //先写入标示的魔数 baos.write(Constants.MAGIC_BYTES); MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).encodeRequest(baos, request); ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(baos.toByteArray()); Channels.write(ctx, e.getFuture(), buffer); }
Example 6
Source File: RpcResponseEncode.java From voyage with Apache License 2.0 | 5 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { RpcResponse response = (RpcResponse) e.getMessage(); ByteArrayOutputStream baos = new ByteArrayOutputStream(16384); //先写入标示的魔数 baos.write(Constants.MAGIC_BYTES); MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).encodeResponse(baos, response); ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(baos.toByteArray()); Channels.write(ctx, e.getFuture(), buffer); }
Example 7
Source File: NettyDispatcher.java From ikasoa with MIT License | 5 votes |
private void writeResponse(ChannelHandlerContext ctx, TNettyMessage response, int responseSequenceId, boolean isOrderedResponsesRequired) { if (isOrderedResponsesRequired) writeResponseInOrder(ctx, response, responseSequenceId); else { Channels.write(ctx.getChannel(), response); lastResponseWrittenId.incrementAndGet(); } }
Example 8
Source File: AdminNettyUtils.java From canal with Apache License 2.0 | 5 votes |
public static void write(Channel channel, ByteBuffer body) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.limit()).array(); List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(2); components.add(ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, header)); components.add(ChannelBuffers.wrappedBuffer(body)); Channels.write(channel, new CompositeChannelBuffer(ByteOrder.BIG_ENDIAN, components)); }
Example 9
Source File: NettyUtils.java From canal with Apache License 2.0 | 5 votes |
public static void write(Channel channel, ByteBuffer body, ChannelFutureListener channelFutureListner) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.limit()).array(); List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(2); components.add(ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, header)); components.add(ChannelBuffers.wrappedBuffer(body)); if (channelFutureListner == null) { Channels.write(channel, new CompositeChannelBuffer(ByteOrder.BIG_ENDIAN, components)); } else { Channels.write(channel, new CompositeChannelBuffer(ByteOrder.BIG_ENDIAN, components)) .addListener(channelFutureListner); } }
Example 10
Source File: NettyUtils.java From canal with Apache License 2.0 | 5 votes |
public static void write(Channel channel, byte[] body, ChannelFutureListener channelFutureListner) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.length).array(); if (channelFutureListner == null) { Channels.write(channel, ChannelBuffers.wrappedBuffer(header, body)); } else { Channels.write(channel, ChannelBuffers.wrappedBuffer(header, body)).addListener(channelFutureListner); } }
Example 11
Source File: SessionHandler.java From DataLink with Apache License 2.0 | 4 votes |
private void sendResponse(ChannelHandlerContext ctx, Response response) { Channels.write(ctx.getChannel(), ChannelBuffers.wrappedBuffer(response.getBuffers())); }
Example 12
Source File: AdminNettyUtils.java From canal with Apache License 2.0 | 4 votes |
public static void write(Channel channel, byte[] body) { byte[] header = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN).putInt(body.length).array(); Channels.write(channel, ChannelBuffers.wrappedBuffer(header, body)); }
Example 13
Source File: ChannelAdaptor.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
public void sendMessage(Object msg) { Channels.write(channel, msg); }
Example 14
Source File: NettyTcpClientTransport.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
@Override protected void flushPendingBuffer(ChannelBufferOutputStream b, Channel c) { Channels.write(c, b.buffer()); b.buffer().clear(); }
Example 15
Source File: NettyTcpClientTransport.java From msgpack-rpc-java with Apache License 2.0 | 4 votes |
@Override protected void sendMessageChannel(Channel c, Object msg) { Channels.write(c, msg); }
Example 16
Source File: MongoMessageEncoder.java From usergrid with Apache License 2.0 | 3 votes |
@Override public void writeRequested( ChannelHandlerContext ctx, MessageEvent e ) { // logger.info("Mongo message encoding..."); Message message = ( Message ) e.getMessage(); ChannelBuffer buf = message.encode( null ); Channels.write( ctx, e.getFuture(), buf ); }