public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
@Override public ByteBuf decode(ByteBuf encoded, int uncompressedLength) throws IOException { ByteBuf uncompressed = PooledByteBufAllocator.DEFAULT.heapBuffer(uncompressedLength, uncompressedLength);
@Override public ByteBuf encode(ByteBuf source) { byte[] array; int length = source.readableBytes(); int sizeEstimate = (int) Math.ceil(source.readableBytes() * 1.001) + 14; ByteBuf compressed = PooledByteBufAllocator.DEFAULT.heapBuffer(sizeEstimate); int offset = 0; if (source.hasArray()) { array = source.array(); offset = source.arrayOffset() + source.readerIndex(); } else { // If it's a direct buffer, we need to copy it array = new byte[length]; source.getBytes(source.readerIndex(), array); } Deflater deflater = this.deflater.get(); deflater.reset(); deflater.setInput(array, offset, length); while (!deflater.needsInput()) { deflate(deflater, compressed); } return compressed; }
static ByteBuf serialize(byte[] value, long revision) { int serializedSize = value.length + Long.BYTES; ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(serializedSize); buffer.writeLong(revision); buffer.writeBytes(value); return buffer; }
static ByteBuf serialize(ByteBuf valBuf, long revision) { int serializedSize = valBuf.readableBytes() + Long.BYTES; ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(serializedSize); buffer.writeLong(revision); buffer.writeBytes(valBuf); return buffer; }
public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
public static ActiveMQBuffer pooledBuffer(final int size) { return new ChannelBufferWrapper(ALLOCATOR.heapBuffer(size),true, true); }
private void encodeProtonMessage() { int estimated = Math.max(1500, data != null ? data.capacity() + 1000 : 0); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(estimated); try { getProtonMessage().encode(new NettyWritable(buffer)); byte[] bytes = new byte[buffer.writerIndex()]; buffer.readBytes(bytes); data = ReadableBuffer.ByteBufferReader.wrap(ByteBuffer.wrap(bytes)); bufferValid = true; } finally { buffer.release(); } }
@Override public ByteBuf decode(ByteBuf encoded, int uncompressedLength) throws IOException { ByteBuf uncompressed = PooledByteBufAllocator.DEFAULT.heapBuffer(uncompressedLength, uncompressedLength);
@Override public ByteBuf encode(ByteBuf source) { byte[] array; int length = source.readableBytes(); int sizeEstimate = (int) Math.ceil(source.readableBytes() * 1.001) + 14; ByteBuf compressed = PooledByteBufAllocator.DEFAULT.heapBuffer(sizeEstimate); int offset = 0; if (source.hasArray()) { array = source.array(); offset = source.arrayOffset() + source.readerIndex(); } else { // If it's a direct buffer, we need to copy it array = new byte[length]; source.getBytes(source.readerIndex(), array); } synchronized (deflater) { deflater.setInput(array, offset, length); while (!deflater.needsInput()) { deflate(compressed); } deflater.reset(); } return compressed; }
@Override public ByteBuf encode(ByteBuf source) { byte[] array; int length = source.readableBytes(); int sizeEstimate = (int) Math.ceil(source.readableBytes() * 1.001) + 14; ByteBuf compressed = PooledByteBufAllocator.DEFAULT.heapBuffer(sizeEstimate); int offset = 0; if (source.hasArray()) { array = source.array(); offset = source.arrayOffset() + source.readerIndex(); } else { // If it's a direct buffer, we need to copy it array = new byte[length]; source.getBytes(source.readerIndex(), array); } Deflater deflater = this.deflater.get(); deflater.reset(); deflater.setInput(array, offset, length); while (!deflater.needsInput()) { deflate(deflater, compressed); } return compressed; }
public PulsarStats(PulsarService pulsar) { this.topicStatsBuf = PooledByteBufAllocator.DEFAULT.heapBuffer(16 * 1024); this.tempTopicStatsBuf = PooledByteBufAllocator.DEFAULT.heapBuffer(16 * 1024); this.nsStats = new NamespaceStats(); this.clusterReplicationMetrics = new ClusterReplicationMetrics(pulsar.getConfiguration().getClusterName(), pulsar.getConfiguration().isReplicationMetricsEnabled()); this.bundleStats = Maps.newHashMap(); this.tempMetricsCollection = Lists.newArrayList(); this.metricsCollection = Lists.newArrayList(); this.brokerOperabilityMetrics = new BrokerOperabilityMetrics(pulsar.getConfiguration().getClusterName(), pulsar.getAdvertisedAddress()); }
private ReadableBuffer createCopyWithoutDeliveryAnnotations() { assert headerEnds != messagePaylodStart; // The original message had delivery annotations and so we must copy into a new // buffer skipping the delivery annotations section as that is not meant to survive // beyond this hop. ReadableBuffer duplicate = data.duplicate(); final ByteBuf result = PooledByteBufAllocator.DEFAULT.heapBuffer(getEncodeSize()); result.writeBytes(duplicate.limit(headerEnds).byteBuffer()); duplicate.clear(); duplicate.position(messagePaylodStart); result.writeBytes(duplicate.byteBuffer()); return new NettyReadable(result); }
private ReadableBuffer createCopyWithSkippedOrExplicitlySetDeliveryAnnotations() { // The original message had delivery annotations, or delivery annotations for the send buffer are set. // That means we must copy into a new buffer skipping the original delivery annotations section // (not meant to survive beyond this hop) and including the delivery annotations for the send buffer if set. ReadableBuffer duplicate = data.duplicate(); final ByteBuf result = PooledByteBufAllocator.DEFAULT.heapBuffer(getEncodeSize()); result.writeBytes(duplicate.limit(encodedHeaderSize).byteBuffer()); writeDeliveryAnnotationsForSendBuffer(result); duplicate.clear(); // skip existing delivery annotations of the original message duplicate.position(encodedHeaderSize + encodedDeliveryAnnotationsSize); result.writeBytes(duplicate.byteBuffer()); return new NettyReadable(result); }
@Override public void onMessage(Delivery delivery) throws ActiveMQAMQPException { ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024); try { synchronized (connection.getLock()) { readDelivery(receiver, buffer); MessageImpl clientMessage = decodeMessageImpl(buffer); // This second method could be better // clientMessage.decode(buffer.nioBuffer()); receiver.advance(); delivery.disposition(Accepted.getInstance()); queues.add(clientMessage); } } finally { buffer.release(); } }
private ReadableBuffer createCopyWithNewDeliveryCount(int deliveryCount) { assert deliveryCount > 1; final int amqpDeliveryCount = deliveryCount - 1; final ByteBuf result = PooledByteBufAllocator.DEFAULT.heapBuffer(getEncodeSize()); // If this is re-delivering the message then the header must be re-encoded // otherwise we want to write the original header if present. When a // Header is present we need to copy it as we are updating the re-delivered // message and not the stored version which we don't want to invalidate here. Header header = this.header; if (header == null) { header = new Header(); } else { header = new Header(header); } header.setDeliveryCount(UnsignedInteger.valueOf(amqpDeliveryCount)); TLSEncode.getEncoder().setByteBuffer(new NettyWritable(result)); TLSEncode.getEncoder().writeObject(header); TLSEncode.getEncoder().setByteBuffer((WritableBuffer) null); writeDeliveryAnnotationsForSendBuffer(result); // skip existing delivery annotations of the original message data.position(encodedHeaderSize + encodedDeliveryAnnotationsSize); result.writeBytes(data.byteBuffer()); data.position(0); return new NettyReadable(result); }
private ReadableBuffer createCopyWithNewDeliveryCount(int deliveryCount) { assert deliveryCount > 1; final int amqpDeliveryCount = deliveryCount - 1; // If the re-delivering the message then the header must be re-encoded // (or created if not previously present). Any delivery annotations should // be skipped as well in the resulting buffer. final ByteBuf result = PooledByteBufAllocator.DEFAULT.heapBuffer(getEncodeSize()); Header header = getHeader(); if (header == null) { header = new Header(); header.setDurable(durable); } synchronized (header) { // Updates or adds a Header section with the correct delivery count header.setDeliveryCount(UnsignedInteger.valueOf(amqpDeliveryCount)); TLSEncode.getEncoder().setByteBuffer(new NettyWritable(result)); TLSEncode.getEncoder().writeObject(header); TLSEncode.getEncoder().setByteBuffer((WritableBuffer) null); } // This will skip any existing delivery annotations that might have been present // in the original message. data.position(messagePaylodStart); result.writeBytes(data.byteBuffer()); data.position(0); return new NettyReadable(result); }