/** * Construct a new instance. * * @param channel the channel to wrap * @param receiveBuffer the receive buffer (should be direct) * @param transmitBuffer the send buffer (should be direct) */ public FramedMessageChannel(final ConnectedStreamChannel channel, final ByteBuffer receiveBuffer, final ByteBuffer transmitBuffer) { super(channel); this.receiveBuffer = Buffers.pooledWrapper(receiveBuffer); this.transmitBuffer = Buffers.pooledWrapper(transmitBuffer); log.tracef("Created new framed message channel around %s, receive buffer %s, transmit buffer %s", channel, receiveBuffer, transmitBuffer); }
/** * Push a buffer into the queue. There is no mechanism to limit the number of pushed buffers; if such a mechanism * is desired, it must be implemented externally, for example maybe using a {@link Semaphore}. * * @param buffer the buffer from which more data should be read */ public void push(final ByteBuffer buffer) { synchronized (this) { if (buffer.hasRemaining() && !eof && failure == null) { queue.add(Buffers.pooledWrapper(buffer)); notifyAll(); } } }
public Pooled<B> allocate() { return pooledWrapper(allocator.allocate(size)); } };
/** * Construct a new instance. * * @param channel the channel to wrap * @param receiveBuffer the receive buffer (should be direct) * @param transmitBuffer the send buffer (should be direct) */ public RemotingMessageChannel(ConnectedStreamChannel channel, ByteBuffer receiveBuffer, ByteBuffer transmitBuffer) { super(channel); this.receiveBuffer = Buffers.pooledWrapper(receiveBuffer); this.transmitBuffer = Buffers.pooledWrapper(transmitBuffer); log.tracef("Created new framed message channel around %s, receive buffer %s, transmit buffer %s", channel, receiveBuffer, transmitBuffer); }
/** * Construct a new instance. * * @param channel the channel to wrap * @param receiveBuffer the receive buffer (should be direct) * @param transmitBuffer the send buffer (should be direct) */ public FramedMessageChannel(final ConnectedStreamChannel channel, final ByteBuffer receiveBuffer, final ByteBuffer transmitBuffer) { super(channel); this.receiveBuffer = Buffers.pooledWrapper(receiveBuffer); this.transmitBuffer = Buffers.pooledWrapper(transmitBuffer); log.tracef("Created new framed message channel around %s, receive buffer %s, transmit buffer %s", channel, receiveBuffer, transmitBuffer); }
/** * Push a buffer into the queue. There is no mechanism to limit the number of pushed buffers; if such a mechanism * is desired, it must be implemented externally, for example maybe using a {@link Semaphore}. * * @param buffer the buffer from which more data should be read */ public void push(final ByteBuffer buffer) { synchronized (this) { if (buffer.hasRemaining() && !eof && failure == null) { queue.add(Buffers.pooledWrapper(buffer)); notifyAll(); } } }
public Pooled<B> allocate() { return pooledWrapper(allocator.allocate(size)); } };
/** * Adjusts inner buffers to required message length. For security reason, the buffer size cannot exceed value * specified in {@link RemotingOptions#MAX_RECEIVE_BUFFER_SIZE} * * @param length * message length the buffers * * @throws IllegalArgumentException * if requested length exceeds maximal allowed buffer size */ void adjustToMessageLength(int length) { if (length > RemotingOptions.MAX_RECEIVE_BUFFER_SIZE) { throw new IllegalArgumentException("Unable to adjust to message size. For security reason, the maximal buffer size is set to " + RemotingOptions.MAX_RECEIVE_BUFFER_SIZE); } if (length > receiveBuffer.getResource().capacity()) { receiveBuffer = Buffers.pooledWrapper(ByteBuffer.allocate(length + 4)); } if (length > transmitBuffer.getResource().capacity()) { transmitBuffer = Buffers.pooledWrapper(ByteBuffer.allocate(length + 4)); } }