ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1558341 - in /ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl: ArtifactRepositoryImpl.java AssociationRepositoryImpl.java DeploymentVersionRepositoryImpl.java ObjectRepositoryImpl.java
Date Wed, 15 Jan 2014 11:11:21 GMT
Author: jawi
Date: Wed Jan 15 11:11:21 2014
New Revision: 1558341

URL: http://svn.apache.org/r1558341
Log:
ACE-449 - ISE when reconfigurating deploymentversionlimit:

- the deployment version repository tries to purge the available versions
  on every addition to the repository using the public remove API. When 
  the repository is created from XML, all calls to the public API (including
  the remove) are blocked, as we want to avoid the caller from messing up a
  repository that is not consistent yet. This caused the illegal state 
  exception to appear;
- the solution is to make an "internal" remove method (analog to the add of
  a repository) that does not check the busy flag. The public remove method,
  after having performed the busy check, forwards its call to this internal
  remove method keeping the same semantics. The purging of deployment versions
  can now use the internal remove without any issues surrounding the busy 
  flag.


Modified:
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationRepositoryImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/DeploymentVersionRepositoryImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java?rev=1558341&r1=1558340&r2=1558341&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
Wed Jan 15 11:11:21 2014
@@ -27,7 +27,6 @@ import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,7 +43,6 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.repository.RepositoryConfiguration;
 import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationRepositoryImpl.java?rev=1558341&r1=1558340&r2=1558341&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationRepositoryImpl.java
Wed Jan 15 11:11:21 2014
@@ -59,7 +59,7 @@ public abstract class AssociationReposit
                 attributes.put(Association.LEFT_CARDINALITY, "" + leftCardinality);
                 attributes.put(Association.RIGHT_CARDINALITY, "" + rightCardinality);
                 association = (T) createNewInhabitant(attributes);
-                if (!add(association)) {
+                if (!internalAdd(association)) {
                     return null;
                 }
             }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/DeploymentVersionRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/DeploymentVersionRepositoryImpl.java?rev=1558341&r1=1558340&r2=1558341&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/DeploymentVersionRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/DeploymentVersionRepositoryImpl.java
Wed Jan 15 11:11:21 2014
@@ -101,8 +101,8 @@ public class DeploymentVersionRepository
     }
 
     @Override
-    boolean add(DeploymentVersionObject entity) {
-        boolean result = super.add(entity);
+    boolean internalAdd(DeploymentVersionObject entity) {
+        boolean result = super.internalAdd(entity);
 
         int deploymentVersionLimit = getDeploymentVersionLimit();
         if (deploymentVersionLimit > 0) {
@@ -160,7 +160,9 @@ public class DeploymentVersionRepository
             SortedSet<DeploymentVersionObject> versions = entry.getValue();
             while (versions.size() > deploymentVersionLimit) {
                 DeploymentVersionObject head = versions.first();
-                remove(head);
+                // We can be called while unmarshalling the database, hence we need to ensure
that we do not use the
+                // public API as this one throws an exception while this repository is busy.
See ACE-449.
+                internalRemove(head);
                 versions.remove(head);
             }
         }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java?rev=1558341&r1=1558340&r2=1558341&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
Wed Jan 15 11:11:21 2014
@@ -87,7 +87,7 @@ abstract class ObjectRepositoryImpl<I ex
             throw new IllegalStateException("The repository is currently busy, so no new
objects can be created.");
         }
         T result = (T) createNewInhabitant(attributes, tags);
-        if (add(result)) {
+        if (internalAdd(result)) {
             return result;
         }
         throw new IllegalArgumentException("Failed to add new object: entity already exists!");
@@ -185,30 +185,11 @@ abstract class ObjectRepositoryImpl<I ex
         m_notifier.notifyChanged(topic, props, internalOnly);
     }
 
-    @SuppressWarnings("unchecked")
     public void remove(T entity) {
         if (m_busy) {
             throw new IllegalStateException("The repository is currently busy, so no objects
can be removed.");
         }
-
-        boolean result = false;
-
-        Lock writeLock = m_lock.writeLock();
-        writeLock.lock();
-        try {
-            if (m_repo.remove(entity)) {
-                m_index.remove(entity.getDefinition());
-                ((I) entity).setDeleted();
-                result = true;
-            }
-        }
-        finally {
-            writeLock.unlock();
-        }
-
-        if (result) {
-            notifyEntityChanged(entity, RepositoryObject.TOPIC_REMOVED_SUFFIX);
-        }
+        internalRemove(entity);
     }
 
     /**
@@ -243,7 +224,7 @@ abstract class ObjectRepositoryImpl<I ex
                 reader.moveDown();
                 I newInhabitant = createNewInhabitant(reader);
                 newInhabitant.setBusy(m_busy);
-                add((T) newInhabitant);
+                internalAdd((T) newInhabitant);
                 reader.moveUp();
             }
         }
@@ -255,6 +236,30 @@ abstract class ObjectRepositoryImpl<I ex
         }
     }
 
+    Filter createFilter(String filter) throws InvalidSyntaxException {
+        return m_context.createFilter(filter);
+    }
+
+    /**
+     * Creates a new inhabitant of the repository based on an XML representation.
+     * 
+     * @param reader
+     *            A reader for the XML representation.
+     * @return The new inhabitant.
+     */
+    abstract I createNewInhabitant(HierarchicalStreamReader reader);
+
+    /**
+     * Creates a new inhabitant of the repository based on a map of attributes.
+     * 
+     * @param attributes
+     *            A map of attributes
+     * @param tags
+     *            A map of tags
+     * @return The new inhabitant.
+     */
+    abstract I createNewInhabitant(Map<String, String> attributes, Map<String, String>
tags);
+
     /**
      * Helper method that stores an object in the repository, taking care of the right events.
      * 
@@ -262,7 +267,7 @@ abstract class ObjectRepositoryImpl<I ex
      *            the object to be stored.
      * @return true only when the object (or at least one identical to it) did not yet exist
in the repository.
      */
-    boolean add(T entity) {
+    boolean internalAdd(T entity) {
         boolean result = false;
 
         Lock writeLock = m_lock.writeLock();
@@ -285,29 +290,29 @@ abstract class ObjectRepositoryImpl<I ex
         return result;
     }
 
-    Filter createFilter(String filter) throws InvalidSyntaxException {
-        return m_context.createFilter(filter);
-    }
+    @SuppressWarnings("unchecked")
+    boolean internalRemove(T entity) {
+        boolean result = false;
 
-    /**
-     * Creates a new inhabitant of the repository based on an XML representation.
-     * 
-     * @param reader
-     *            A reader for the XML representation.
-     * @return The new inhabitant.
-     */
-    abstract I createNewInhabitant(HierarchicalStreamReader reader);
+        Lock writeLock = m_lock.writeLock();
+        writeLock.lock();
+        try {
+            if (m_repo.remove(entity)) {
+                m_index.remove(entity.getDefinition());
+                ((I) entity).setDeleted();
+                result = true;
+            }
+        }
+        finally {
+            writeLock.unlock();
+        }
 
-    /**
-     * Creates a new inhabitant of the repository based on a map of attributes.
-     * 
-     * @param attributes
-     *            A map of attributes
-     * @param tags
-     *            A map of tags
-     * @return The new inhabitant.
-     */
-    abstract I createNewInhabitant(Map<String, String> attributes, Map<String, String>
tags);
+        if (result) {
+            notifyEntityChanged(entity, RepositoryObject.TOPIC_REMOVED_SUFFIX);
+        }
+
+        return result;
+    }
 
     /**
      * Removes all objects in this repository, without caring for the consistency and correct
event firing.



Mime
View raw message