This is an automated email from the ASF dual-hosted git repository.
tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new 398c916b PROTON-2599 Cleanup handling of the performative pool
envelope create
398c916b is described below
commit 398c916b4f5df3a4ae84a8e24acdb916d52218ea
Author: Timothy Bish <[email protected]>
AuthorDate: Thu Sep 1 15:36:52 2022 -0400
PROTON-2599 Cleanup handling of the performative pool envelope create
Minor cleanup to prevent temporary object when getting an envelope from
the pool
---
.../protonj2/engine/AMQPPerformativeEnvelopePool.java | 17 +++++++----------
.../qpid/protonj2/engine/IncomingAMQPEnvelope.java | 8 ++++----
.../qpid/protonj2/engine/OutgoingAMQPEnvelope.java | 8 ++++----
3 files changed, 15 insertions(+), 18 deletions(-)
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/AMQPPerformativeEnvelopePool.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/AMQPPerformativeEnvelopePool.java
index 2805168a..af7ddff6 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/AMQPPerformativeEnvelopePool.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/AMQPPerformativeEnvelopePool.java
@@ -17,6 +17,7 @@
package org.apache.qpid.protonj2.engine;
import java.util.function.Function;
+import java.util.function.Supplier;
import org.apache.qpid.protonj2.buffer.ProtonBuffer;
import org.apache.qpid.protonj2.engine.util.RingQueue;
@@ -29,15 +30,15 @@ import
org.apache.qpid.protonj2.types.transport.Performative;
*/
public class AMQPPerformativeEnvelopePool<E extends
PerformativeEnvelope<Performative>> {
- /**
- * The default maximum pool size to use if not otherwise configured.
- */
+ /**
+ * The default maximum pool size to use if not otherwise configured.
+ */
public static final int DEFAULT_MAX_POOL_SIZE = 10;
private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
private final RingQueue<E> pool;
- private final Function<AMQPPerformativeEnvelopePool<E>, E> envelopeBuilder;
+ private final Supplier<E> envelopeSupplier;
/**
* Create a new envelope pool using the default pool size.
@@ -60,7 +61,7 @@ public class AMQPPerformativeEnvelopePool<E extends
PerformativeEnvelope<Perform
public
AMQPPerformativeEnvelopePool(Function<AMQPPerformativeEnvelopePool<E>, E>
envelopeBuilder, int maxPoolSize) {
this.pool = new RingQueue<>(getMaxPoolSize());
this.maxPoolSize = maxPoolSize;
- this.envelopeBuilder = envelopeBuilder;
+ this.envelopeSupplier = () -> envelopeBuilder.apply(this);
}
/**
@@ -85,17 +86,13 @@ public class AMQPPerformativeEnvelopePool<E extends
PerformativeEnvelope<Perform
*/
@SuppressWarnings("unchecked")
public E take(Performative body, int channel, ProtonBuffer payload) {
- return (E) pool.poll(this::supplyPooledResource).initialize(body,
channel, payload);
+ return (E) pool.poll(envelopeSupplier).initialize(body, channel,
payload);
}
void release(E pooledEnvelope) {
pool.offer(pooledEnvelope);
}
- private E supplyPooledResource() {
- return envelopeBuilder.apply(this);
- }
-
/**
* @param maxPoolSize
* The maximum number of protocol envelopes to store in the pool.
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/IncomingAMQPEnvelope.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/IncomingAMQPEnvelope.java
index b1414545..eda6088f 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/IncomingAMQPEnvelope.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/IncomingAMQPEnvelope.java
@@ -24,9 +24,9 @@ import
org.apache.qpid.protonj2.types.transport.Performative.PerformativeHandler
*/
public class IncomingAMQPEnvelope extends PerformativeEnvelope<Performative> {
- /**
- * The AMQP Frame type marker value used when processing incoming
frames.
- */
+ /**
+ * The AMQP Frame type marker value used when processing incoming frames.
+ */
public static final byte AMQP_FRAME_TYPE = (byte) 0;
private AMQPPerformativeEnvelopePool<IncomingAMQPEnvelope> pool;
@@ -47,7 +47,7 @@ public class IncomingAMQPEnvelope extends
PerformativeEnvelope<Performative> {
* contents of the Frame are invalid and cannot be used again inside the
* same context.
*/
- public void release() {
+ public final void release() {
initialize(null, -1, null);
if (pool != null) {
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/OutgoingAMQPEnvelope.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/OutgoingAMQPEnvelope.java
index 1e825ba4..d060ae81 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/OutgoingAMQPEnvelope.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/OutgoingAMQPEnvelope.java
@@ -26,9 +26,9 @@ import
org.apache.qpid.protonj2.types.transport.Performative.PerformativeHandler
*/
public class OutgoingAMQPEnvelope extends PerformativeEnvelope<Performative> {
- /**
- * The frame type value to used when encoding the outgoing AMQP frame.
- */
+ /**
+ * The frame type value to used when encoding the outgoing AMQP frame.
+ */
public static final byte AMQP_FRAME_TYPE = (byte) 0;
private AMQPPerformativeEnvelopePool<OutgoingAMQPEnvelope> pool;
@@ -115,7 +115,7 @@ public class OutgoingAMQPEnvelope extends
PerformativeEnvelope<Performative> {
* contents of the Frame are invalid and cannot be used again inside the
* same context.
*/
- public void release() {
+ public final void release() {
initialize(null, -1, null);
payloadToLargeHandler = this::defaultPayloadToLargeHandler;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]