You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2020/02/19 03:10:57 UTC

[GitHub] [activemq-artemis] clebertsuconic commented on a change in pull request #2986: ARTEMIS-1975 Real Large Message support into AMQP

clebertsuconic commented on a change in pull request #2986: ARTEMIS-1975 Real Large Message support into AMQP
URL: https://github.com/apache/activemq-artemis/pull/2986#discussion_r381055760
 
 

 ##########
 File path: artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/RefCountMessage.java
 ##########
 @@ -19,66 +19,155 @@
 
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 
-public abstract class RefCountMessage implements Message {
+// import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet; -- #ifdef DEBUG
+
+public class RefCountMessage {
 
    private static final AtomicIntegerFieldUpdater<RefCountMessage> DURABLE_REF_COUNT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(RefCountMessage.class, "durableRefCount");
    private static final AtomicIntegerFieldUpdater<RefCountMessage> REF_COUNT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(RefCountMessage.class, "refCount");
+   private static final AtomicIntegerFieldUpdater<RefCountMessage> REF_USAGE_UPDATER = AtomicIntegerFieldUpdater.newUpdater(RefCountMessage.class, "usageCount");
 
    private volatile int durableRefCount = 0;
 
    private volatile int refCount = 0;
 
-   private RefCountMessageListener context;
+   private volatile int usageCount = 0;
+
+   private volatile boolean fired = false;
 
-   @Override
-   public Message setContext(RefCountMessageListener context) {
-      this.context = context;
-      return this;
+   public int getRefCount() {
+      return REF_COUNT_UPDATER.get(this);
    }
 
-   @Override
-   public RefCountMessageListener getContext() {
-      return context;
+   public int getUsage() {
+      return REF_USAGE_UPDATER.get(this);
    }
 
-   @Override
-   public int getRefCount() {
-      return refCount;
+   public int getDurableCount() {
+      return DURABLE_REF_COUNT_UPDATER.get(this);
    }
 
-   @Override
-   public int incrementRefCount() throws Exception {
-      int count = REF_COUNT_UPDATER.incrementAndGet(this);
-      if (context != null) {
-         context.nonDurableUp(this, count);
+   /**
+    * in certain cases the large message is copied from another LargeServerMessage
+    * and the ref count needs to be on that place.
+    */
+   private volatile RefCountMessage parentRef;
+
+   public RefCountMessage getParentRef() {
+      return parentRef;
+   }
+   // I am usually against keeping commented out code
+   // However this is very useful for me to debug referencing counting.
+   // Uncomment out anything between #ifdef DEBUG and #endif
+
+   // #ifdef DEBUG -- comment out anything before endif if you want to debug REFERENCE COUNTS
+   //final ConcurrentHashSet<Exception> upSet = new ConcurrentHashSet<>();
+   // #endif
+
+   private void onUp() {
+      // #ifdef DEBUG -- comment out anything before endif if you want to debug REFERENCE COUNTS
+      // upSet.add(new Exception("upEvent(" + debugString() + ")"));
+      // #endif
+   }
+
+   private void onDown() {
+      // #ifdef DEBUG -- comment out anything before endif if you want to debug REFERENCE COUNTS
+      // upSet.add(new Exception("upEvent(" + debugString() + ")"));
+      // #endif
+      if (getRefCount() <= 0 && getUsage() <= 0 && getDurableCount() <= 0 && !fired) {
+
+         debugRefs();
+         fired = true;
+         releaseComplete();
+      }
+   }
+   /**
+    *
+    * This method will be useful if you remove commented out code around #ifdef AND #endif COMMENTS
+    * */
+   public final void debugRefs() {
 
 Review comment:
   I'm keeping these if I ever need to debug these again.
   
   Too bad there's no IFDEF in java.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services