@Override public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { if (message == null) { LOGGER.error("Message is null"); return; } if (!(message instanceof RemotingCommand)) { LOGGER.error("{} is not instanceof RemotingCommand", message); return; } RemotingCommand remotingCommand = (RemotingCommand) message; try { ByteBuffer byteBuffer = codec.encode(remotingCommand); IoBuffer ioBuffer = bufferAllocator.wrap(byteBuffer); out.write(ioBuffer); out.flush(); } catch (Exception e) { Channel channel = new MinaChannel(session); LOGGER.error("encode exception, addr={}, remotingCommand={}", RemotingHelper.parseChannelRemoteAddr(channel), remotingCommand.toString(), e); RemotingHelper.closeChannel(channel); } } };
@Override public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { if (message == null) { LOGGER.error("Message is null"); return; } if (!(message instanceof RemotingCommand)) { LOGGER.error("{} is not instanceof RemotingCommand", message); return; } RemotingCommand remotingCommand = (RemotingCommand) message; try { ByteBuffer byteBuffer = codec.encode(remotingCommand); IoBuffer ioBuffer = bufferAllocator.wrap(byteBuffer); out.write(ioBuffer); out.flush(); } catch (Exception e) { Channel channel = new MinaChannel(session); LOGGER.error("encode exception, addr={}, remotingCommand={}", RemotingHelper.parseChannelRemoteAddr(channel), remotingCommand.toString(), e); RemotingHelper.closeChannel(channel); } } };
/** * Wraps the specified NIO {@link ByteBuffer} into a MINA buffer (either direct or heap). * * @param nioBuffer The {@link ByteBuffer} to wrap * @return a IoBuffer containing the bytes stored in the {@link ByteBuffer} */ public static IoBuffer wrap(ByteBuffer nioBuffer) { return allocator.wrap(nioBuffer); }
/** * Wraps the specified NIO {@link ByteBuffer} into a MINA buffer (either direct or heap). * * @param nioBuffer The {@link ByteBuffer} to wrap * @return a IoBuffer containing the bytes stored in the {@link ByteBuffer} */ public static IoBuffer wrap(ByteBuffer nioBuffer) { return allocator.wrap(nioBuffer); }
/** * Wraps the specified NIO {@link ByteBuffer} into MINA buffer. */ public static IoBuffer wrap(ByteBuffer nioBuffer) { return allocator.wrap(nioBuffer); }
@Override public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { if (message == null) { LOGGER.error("Message is null"); return; } if (!(message instanceof RemotingCommand)) { LOGGER.error("{} is not instanceof RemotingCommand", message); return; } RemotingCommand remotingCommand = (RemotingCommand) message; try { ByteBuffer byteBuffer = codec.encode(remotingCommand); IoBuffer ioBuffer = bufferAllocator.wrap(byteBuffer); out.write(ioBuffer); out.flush(); } catch (Exception e) { Channel channel = new MinaChannel(session); LOGGER.error("encode exception, addr={}, remotingCommand={}", RemotingHelper.parseChannelRemoteAddr(channel), remotingCommand.toString(), e); RemotingHelper.closeChannel(channel); } } };