[jboss-cvs] JBossAS SVN: r60112 - in projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers: plugins/deployer and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 30 01:03:11 EST 2007


Author: scott.stark at jboss.org
Date: 2007-01-30 01:03:10 -0500 (Tue, 30 Jan 2007)
New Revision: 60112

Modified:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/attachments/AttachmentsImpl.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/attachments/Attachments.java
Log:
Add a change count notion to Attachments.

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/attachments/AttachmentsImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/attachments/AttachmentsImpl.java	2007-01-30 05:54:56 UTC (rev 60111)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/attachments/AttachmentsImpl.java	2007-01-30 06:03:10 UTC (rev 60112)
@@ -24,6 +24,7 @@
 import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Attachments implementation
@@ -37,6 +38,7 @@
 
    /** The attachments */
    private Map<String, Object> attachments = new ConcurrentHashMap<String, Object>();
+   private AtomicInteger changeCount = new AtomicInteger();
 
    public Map<String, Object> getAttachments()
    {
@@ -46,6 +48,7 @@
    {
       attachments.clear();
       attachments.putAll(map);
+      changeCount.addAndGet(map.size());
    }
 
    public Object addAttachment(String name, Object attachment)
@@ -54,7 +57,9 @@
          throw new IllegalArgumentException("Null name");
       if (attachment == null)
          throw new IllegalArgumentException("Null attachment");
-      return attachments.put(name, attachment);
+      Object value = attachments.put(name, attachment);
+      changeCount.incrementAndGet();
+      return value;
    }
 
    public Object getAttachment(String name)
@@ -75,16 +80,29 @@
    {
       if (name == null)
          throw new IllegalArgumentException("Null name");
-      return attachments.remove(name);
+      Object value = attachments.remove(name);
+      changeCount.incrementAndGet();
+      return value;
    }
 
    public void clear()
    {
       attachments.clear();
+      changeCount.incrementAndGet();
    }
 
    public boolean hasAttachments()
    {
       return attachments.isEmpty() == false;
    }
+
+   public int getChangeCount()
+   {
+      return changeCount.intValue();
+   }
+
+   public void clearChangeCount()
+   {
+      changeCount.set(0);
+   }
 }

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-01-30 05:54:56 UTC (rev 60111)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2007-01-30 06:03:10 UTC (rev 60112)
@@ -57,7 +57,7 @@
 
    /** The deployment context */
    private DeploymentContext deploymentContext;
-   
+
    /**
     * Create a new AbstractDeploymentUnit.
     * 
@@ -316,6 +316,27 @@
       return hasAttachments;
    }
 
+   /**
+    * Get the transientAttachments and transientManagedObjects
+    * change counts sum.
+    */
+   public int getChangeCount()
+   {
+      int count = deploymentContext.getTransientAttachments().getChangeCount()
+         + deploymentContext.getTransientManagedObjects().getChangeCount();
+      return count;
+   }
+
+   /**
+    * Clear the transientAttachments and transientManagedObjects
+    * change counts.
+    */
+   public void clearChangeCount()
+   {
+      deploymentContext.getTransientAttachments().clearChangeCount();
+      deploymentContext.getTransientManagedObjects().clearChangeCount();
+   }
+
    @SuppressWarnings("unchecked")
    // TODO optimize
    public <T> Set<? extends T> getAllMetaData(Class<T> type)

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/attachments/Attachments.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/attachments/Attachments.java	2007-01-30 05:54:56 UTC (rev 60111)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/attachments/Attachments.java	2007-01-30 06:03:10 UTC (rev 60112)
@@ -173,4 +173,16 @@
     * @return true if there are any attachments, false otherwise.
     */
    public boolean hasAttachments();
+
+   /**
+    * Get the number of changes that have happened. 
+    * @return Number of adds/removes that have happened since
+    * creation or clearChangeCount.
+    */
+   public int getChangeCount();
+
+   /**
+    * Reset the change count to zero.
+    */
+   public void clearChangeCount();
 }




More information about the jboss-cvs-commits mailing list