You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2022/09/02 20:28:40 UTC

[qpid-protonj2] branch main updated: PROTON-2599 Create the settlement future from the callers thread

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 848fc649 PROTON-2599 Create the settlement future from the callers thread
848fc649 is described below

commit 848fc649dd1e46e0a1b614f526a5592f99d1f735
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Fri Sep 2 16:28:21 2022 -0400

    PROTON-2599 Create the settlement future from the callers thread
    
    Lazy create the settlement future from the callers thread to move this
    work out of the IO thread and avoid creating it when not ever used.
---
 .../qpid/protonj2/client/impl/ClientTrackable.java | 38 ++++++++++++++++------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientTrackable.java b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientTrackable.java
index 0fb08837..1bf4a4b8 100644
--- a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientTrackable.java
+++ b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientTrackable.java
@@ -36,8 +36,7 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
     protected final SenderType sender;
     protected final OutgoingDelivery delivery;
 
-    private final ClientFuture<TrackerType> remoteSettlementFuture;
-
+    private ClientFuture<TrackerType> remoteSettlementFuture;
     private volatile boolean remotelySettled;
     private volatile DeliveryState remoteDeliveryState;
 
@@ -53,7 +52,6 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
         this.sender = sender;
         this.delivery = delivery;
         this.delivery.deliveryStateUpdatedHandler(this::processDeliveryUpdated);
-        this.remoteSettlementFuture = sender.session().getFutureFactory().createFuture();
     }
 
     protected abstract TrackerType self();
@@ -79,7 +77,12 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
             sender.disposition(delivery, ClientDeliveryState.asProtonType(state), settle);
         } finally {
             if (settle) {
-                remoteSettlementFuture.complete(self());
+                synchronized (this) {
+                    if (remoteSettlementFuture == null) {
+                        remoteSettlementFuture = sender.session.connection().getFutureFactory().createFuture();
+                    }
+                    remoteSettlementFuture.complete(self());
+                }
             }
         }
 
@@ -90,7 +93,12 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
         try {
             sender.disposition(delivery, null, true);
         } finally {
-            remoteSettlementFuture.complete(self());
+            synchronized (this) {
+                if (remoteSettlementFuture == null) {
+                    remoteSettlementFuture = sender.session.connection().getFutureFactory().createFuture();
+                }
+                remoteSettlementFuture.complete(self());
+            }
         }
 
         return self();
@@ -101,7 +109,13 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
     }
 
     public ClientFuture<TrackerType> settlementFuture() {
-        if (delivery.isSettled()) {
+        synchronized (this) {
+            if (remoteSettlementFuture == null) {
+                remoteSettlementFuture = sender.session.connection().getFutureFactory().createFuture();
+            }
+        }
+
+        if (delivery.isSettled() || delivery.isRemotelySettled()) {
             remoteSettlementFuture.complete(self());
         }
 
@@ -189,11 +203,15 @@ public abstract class ClientTrackable<SenderType extends ClientSenderLinkType<?>
         remoteDeliveryState = ClientDeliveryState.fromProtonType(delivery.getRemoteState());
 
         if (delivery.isRemotelySettled()) {
-            remoteSettlementFuture.complete(self());
-        }
+            if (sender.options.autoSettle()) {
+                delivery.settle();
+            }
 
-        if (sender.options.autoSettle() && delivery.isRemotelySettled()) {
-            delivery.settle();
+            synchronized (this) {
+                if (remoteSettlementFuture != null) {
+                    remoteSettlementFuture.complete(self());
+                }
+            }
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org