[jbpm-commits] JBoss JBPM SVN: r6762 - in jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm: instantiation and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Oct 15 22:10:32 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-10-15 22:10:32 -0400 (Fri, 15 Oct 2010)
New Revision: 6762

Modified:
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java
Log:
JBPM-2954 consider negative process definition versions as unknown and hence incomparable

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java	2010-10-15 05:13:50 UTC (rev 6761)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java	2010-10-16 02:10:32 UTC (rev 6762)
@@ -39,6 +39,7 @@
 import org.xml.sax.InputSource;
 
 import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.context.def.ContextDefinition;
 import org.jbpm.file.def.FileDefinition;
@@ -188,6 +189,11 @@
 
   // equals ///////////////////////////////////////////////////////////////////
 
+  /**
+   * Tells whether this process definition is equal to the given object. This method considers
+   * two process definitions equal if they are equal in name and version, the name is not null
+   * and the version is not negative.
+   */
   public boolean equals(Object o) {
     if (o == this) return true;
     if (!(o instanceof ProcessDefinition)) return false;
@@ -195,11 +201,17 @@
     ProcessDefinition other = (ProcessDefinition) o;
     if (id != 0 && id == other.getId()) return true;
 
-    return name != null && name.equals(other.getName()) && version == other.getVersion();
+    return name != null && version >= 0 && name.equals(other.getName())
+      && version == other.getVersion();
   }
 
+  /**
+   * Computes the hash code for this process definition. Process definitions with a null name or
+   * a negative version will return their {@linkplain System#identityHashCode(Object) identity
+   * hash code}.
+   */
   public int hashCode() {
-    if (name == null) return super.hashCode();
+    if (name == null || version < 0) return System.identityHashCode(this);
 
     int result = 224001527 + name.hashCode();
     result = 1568661329 * result + version;
@@ -553,6 +565,14 @@
     return version;
   }
 
+  /**
+   * Sets the version of this process. Generally the version is assigned automatically upon
+   * {@linkplain JbpmContext#deployProcessDefinition(ProcessDefinition) deployment}.
+   * 
+   * @param version the version to assign. Automatic versioning starts from 1. Any negative
+   * value is regarded as an unknown or <code>null</code> version. The meaning of version 0 is
+   * undefined.
+   */
   public void setVersion(int version) {
     this.version = version;
   }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java	2010-10-15 05:13:50 UTC (rev 6761)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java	2010-10-16 02:10:32 UTC (rev 6762)
@@ -33,8 +33,9 @@
 import org.jbpm.util.ClassLoaderUtil;
 
 /**
- * Refined process class loader factory that maintains a cache of the class loaders it returns. The
- * cache does not prevent class loaders from being discarded by the garbage collector.
+ * Factory that caches the class loaders it produces, in order to prevent duplicate class
+ * loaders from eating up the permanent generation space. The cache does not prevent class
+ * loaders from being discarded by the garbage collector.
  * 
  * @author Alejandro Guizar
  */
@@ -54,29 +55,31 @@
   }
 
   public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
-    // determine the key to lookup a cached class loader
-    // observe that the given process definition may be transient
+    // use database identifier as key to lookup cached class loader
     long id = processDefinition.getId();
-    if (id == 0L) id = System.identityHashCode(processDefinition);
-    Long key = new Long(id);
+    // if process definition is transient, use hash code as key
+    Long key = new Long(id == 0L ? processDefinition.hashCode() : id);
+
     // consider that the context class loader changes among applications
     ClassLoader parentClassLoader = ClassLoaderUtil.getClassLoader();
 
     synchronized (classLoaderRefs) {
-      // lookup the class loader reference
+      // lookup cached class loader
       ClassLoader processClassLoader = getProcessClassLoader(key, parentClassLoader);
-      // the reference may not exist or may have been cleared already
+      // if class loader is not cached,
       if (processClassLoader == null) {
-        // (re-)create the class loader and the reference
-        processClassLoader = new ProcessClassLoader(parentClassLoader, processDefinition, jbpmConfiguration);
-        // cache the reference
+        // (re-)create class loader
+        processClassLoader = new ProcessClassLoader(parentClassLoader, processDefinition,
+          jbpmConfiguration);
+        // add class loader to cache
         putProcessClassLoader(key, processClassLoader);
       }
       return processClassLoader;
     }
   }
 
-  private ClassLoader getProcessClassLoader(Long processDefinitionKey, ClassLoader parentClassLoader) {
+  private ClassLoader getProcessClassLoader(Long processDefinitionKey,
+    ClassLoader parentClassLoader) {
     List referenceList = (List) classLoaderRefs.get(processDefinitionKey);
     if (referenceList != null) {
       for (Iterator i = referenceList.iterator(); i.hasNext();) {



More information about the jbpm-commits mailing list