private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id) { return allocateBuffer(allocator, id, 0); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof NettyMessage) { ByteBuf serialized = null; try { serialized = ((NettyMessage) msg).write(ctx.alloc()); } catch (Throwable t) { throw new IOException("Error while serializing message: " + msg, t); } finally { if (serialized != null) { ctx.write(serialized, promise); } } } else { ctx.write(msg, promise); } }
decodedMsg.readFrom(msg); out.add(decodedMsg);
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof NettyMessage) { ByteBuf serialized = null; try { serialized = ((NettyMessage) msg).write(ctx.alloc()); } catch (Throwable t) { throw new IOException("Error while serializing message: " + msg, t); } finally { if (serialized != null) { ctx.write(serialized, promise); } } } else { ctx.write(msg, promise); } } }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>If the <tt>contentLength</tt> is unknown, you must write the actual length after adding * the contents as an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * @param contentLength * content length (or <tt>-1</tt> if unknown) * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id, int contentLength) { return allocateBuffer(allocator, id, 0, contentLength, true); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof NettyMessage) { ByteBuf serialized = null; try { serialized = ((NettyMessage) msg).write(ctx.alloc()); } catch (Throwable t) { throw new IOException("Error while serializing message: " + msg, t); } finally { if (serialized != null) { ctx.write(serialized, promise); } } } else { ctx.write(msg, promise); } }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>Before sending the buffer, you must write the actual length after adding the contents as * an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id) { return allocateBuffer(allocator, id, -1); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof NettyMessage) { ByteBuf serialized = null; try { serialized = ((NettyMessage) msg).write(ctx.alloc()); } catch (Throwable t) { throw new IOException("Error while serializing message: " + msg, t); } finally { if (serialized != null) { ctx.write(serialized, promise); } } } else { ctx.write(msg, promise); } } }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>Before sending the buffer, you must write the actual length after adding the contents as * an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id) { return allocateBuffer(allocator, id, -1); }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>Before sending the buffer, you must write the actual length after adding the contents as * an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id) { return allocateBuffer(allocator, id, -1); }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>If the <tt>contentLength</tt> is unknown, you must write the actual length after adding * the contents as an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * @param contentLength * content length (or <tt>-1</tt> if unknown) * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id, int contentLength) { return allocateBuffer(allocator, id, 0, contentLength, true); }
/** * Allocates a new (header and contents) buffer and adds some header information for the frame * decoder. * * <p>If the <tt>contentLength</tt> is unknown, you must write the actual length after adding * the contents as an integer to position <tt>0</tt>! * * @param allocator * byte buffer allocator to use * @param id * {@link NettyMessage} subclass ID * @param contentLength * content length (or <tt>-1</tt> if unknown) * * @return a newly allocated direct buffer with header data written for {@link * NettyMessageDecoder} */ private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id, int contentLength) { return allocateBuffer(allocator, id, 0, contentLength, true); }