[jbpm-commits] JBoss JBPM SVN: r5905 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/resources/org/jbpm and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Dec 2 23:04:58 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-12-02 23:04:57 -0500 (Wed, 02 Dec 2009)
New Revision: 5905
Added:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2630/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2630/jbpm.nolog.cfg.xml
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfigurationTestHelper.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
Log:
JBPM-2630: remove JbpmConfigurations from thread-local list in LIFO as opposed to FIFO order
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2009-12-03 01:18:46 UTC (rev 5904)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2009-12-03 04:04:57 UTC (rev 5905)
@@ -46,66 +46,60 @@
import org.jbpm.svc.ServiceFactory;
import org.jbpm.svc.Services;
import org.jbpm.util.ClassLoaderUtil;
+import org.jbpm.util.ClassUtil;
/**
* configuration of one jBPM instance.
* <p>
- * During process execution, jBPM might need to use some services. A JbpmConfiguration contains the
- * knowledge on how to create those services.
+ * During process execution, jBPM might need to use some services. A
+ * JbpmConfiguration contains the knowledge on how to create those services.
* </p>
* <p>
* A JbpmConfiguration is a thread safe object and serves as a factory for
- * {@link org.jbpm.JbpmContext}s, which means one JbpmConfiguration can be used to create
- * {@link org.jbpm.JbpmContext}s for all threads. The single JbpmConfiguration can be maintained in
- * a static member or in the JNDI tree if that is available.
+ * {@link org.jbpm.JbpmContext}s, which means one JbpmConfiguration can be used
+ * to create {@link org.jbpm.JbpmContext}s for all threads. The single
+ * JbpmConfiguration can be maintained in a static member or in the JNDI tree if
+ * that is available.
* </p>
* <p>
* A JbpmConfiguration can be obtained in following ways:
* </p>
* <ul>
* <li>from a resource (by default <code>jbpm.cfg.xml</code> is used):
- *
* <pre>
- *
* JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
* </pre>
- *
* or
- *
* <pre>
- *
* String myXmlResource = "...";
- * JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(myXmlResource);
+ * JbpmConfiguration jbpmConfiguration =
+ * JbpmConfiguration.getInstance(myXmlResource);
* </pre>
+ * </li>
*
- * </li>
* <li>from an XML string:
- *
* <pre>
* JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
* "<jbpm-configuration>" +
* ...
- * "</jbpm-configuration>"
- * );
+ * "</jbpm-configuration>");
* </pre>
- *
* </li>
- * <li>By specifying a custom implementation of an object factory. This can be used to specify a
- * JbpmConfiguration in other bean-style notations such as used by JBoss Microcontainer or Spring.
*
+ * <li>By specifying a custom implementation of an object factory. This can be
+ * used to specify a JbpmConfiguration in other bean-style notations such as
+ * used by JBoss Microcontainer or Spring.
* <pre>
* ObjectFactory of = new <i>MyCustomObjectFactory</i>();
* JbpmConfiguration.Configs.setDefaultObjectFactory(of);
* JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
* </pre>
- *
* </li>
* </ul>
* <p>
- * JbpmConfigurations can be configured using a spring-like XML notation (in relax ng compact
- * notation):
+ * JbpmConfigurations can be configured using a spring-like XML notation (in
+ * relax ng compact notation):
* </p>
- *
* <pre>
* datatypes xs = "http://www.w3.org/2001/XMLSchema-datatypes"
*
@@ -233,21 +227,7 @@
* false = element false {}
* null = element null {}
* </pre>
- *
* </p>
- * <p>
- * Other configuration properties
- * </p>
- * <table>
- * <tr>
- * <td>jbpm.files.dir</td>
- * <td/>
- * </tr>
- * <tr>
- * <td>jbpm.types</td>
- * <td/>
- * </tr>
- * </table>
*/
public class JbpmConfiguration implements Serializable {
@@ -258,9 +238,10 @@
static final ThreadLocal jbpmConfigurationStacks = new StackThreadLocal();
private final ObjectFactory objectFactory;
- private final ThreadLocal jbpmContextStacks = new StackThreadLocal();
+ private final String resourceName;
private JobExecutor jobExecutor;
private boolean isClosed;
+ private final ThreadLocal jbpmContextStacks = new StackThreadLocal();
static class StackThreadLocal extends ThreadLocal {
@@ -271,8 +252,14 @@
public JbpmConfiguration(ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
+ this.resourceName = null;
}
+ JbpmConfiguration(ObjectFactory objectFactory, String resourceName) {
+ this.objectFactory = objectFactory;
+ this.resourceName = resourceName;
+ }
+
public static JbpmConfiguration getInstance() {
return getInstance(null);
}
@@ -290,20 +277,23 @@
// configuration does not exist or was evicted, construct it
if (defaultObjectFactory != null) {
if (log.isDebugEnabled()) {
- log.debug("creating configuration from default object factory: " + defaultObjectFactory);
+ log.debug("creating configuration from default object factory: "
+ + defaultObjectFactory);
}
instance = new JbpmConfiguration(defaultObjectFactory);
}
else {
log.info("using configuration resource: " + resource);
- InputStream jbpmCfgXmlStream = ClassLoaderUtil.getStream(resource, false);
+ InputStream jbpmCfgXmlStream =
+ ClassLoaderUtil.getStream(resource, false);
/*
- * if a custom resource is specified, but not found in the classpath, log a warning;
- * otherwise, users who want to load custom stuff will not receive any feedback when their
- * resource cannot be found
+ * if a custom resource is specified, but not found in the classpath,
+ * log a warning; otherwise, users who want to load custom stuff will
+ * not receive any feedback when their resource cannot be found
*/
if (jbpmCfgXmlStream == null && !"jbpm.cfg.xml".equals(resource)) {
- log.warn("configuration resource '" + resource + "' could not be found");
+ log.warn("configuration resource '" + resource
+ + "' could not be found");
}
ObjectFactory objectFactory = parseObjectFactory(jbpmCfgXmlStream);
instance = createJbpmConfiguration(objectFactory);
@@ -343,13 +333,15 @@
return createJbpmConfiguration(objectFactory);
}
- protected static JbpmConfiguration createJbpmConfiguration(ObjectFactory objectFactory) {
+ protected static JbpmConfiguration createJbpmConfiguration(
+ ObjectFactory objectFactory) {
JbpmConfiguration jbpmConfiguration = new JbpmConfiguration(objectFactory);
// make the bean jbpm.configuration always available
if (objectFactory instanceof ObjectFactoryImpl) {
ObjectFactoryImpl objectFactoryImpl = (ObjectFactoryImpl) objectFactory;
- ObjectInfo jbpmConfigurationInfo = new ValueInfo("jbpmConfiguration", jbpmConfiguration);
+ ObjectInfo jbpmConfigurationInfo =
+ new ValueInfo("jbpmConfiguration", jbpmConfiguration);
objectFactoryImpl.addObjectInfo(jbpmConfigurationInfo);
if (getHideStaleObjectExceptions(objectFactory)) {
@@ -360,10 +352,13 @@
return jbpmConfiguration;
}
- private static boolean getHideStaleObjectExceptions(ObjectFactory objectFactory) {
- if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions")) return true;
+ private static boolean getHideStaleObjectExceptions(
+ ObjectFactory objectFactory) {
+ if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions"))
+ return true;
- Object object = objectFactory.createObject("jbpm.hide.stale.object.exceptions");
+ Object object =
+ objectFactory.createObject("jbpm.hide.stale.object.exceptions");
return object instanceof Boolean ? ((Boolean) object).booleanValue() : true;
}
@@ -406,7 +401,8 @@
return getServiceFactory(serviceName, JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName) {
+ public ServiceFactory getServiceFactory(String serviceName,
+ String jbpmContextName) {
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
try {
return jbpmContext.getServices().getServiceFactory(serviceName);
@@ -416,10 +412,12 @@
}
}
- public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
+ public static ClassLoader getProcessClassLoader(
+ ProcessDefinition processDefinition) {
ProcessClassLoaderFactory factory;
if (Configs.hasObject("process.class.loader.factory")) {
- factory = (ProcessClassLoaderFactory) Configs.getObject("process.class.loader.factory");
+ factory =
+ (ProcessClassLoaderFactory) Configs.getObject("process.class.loader.factory");
}
else {
factory = new DefaultProcessClassLoaderFactory();
@@ -428,7 +426,8 @@
}
/**
- * gives the jbpm domain model access to configuration information via the current JbpmContext.
+ * gives the jbpm domain model access to configuration information via the
+ * current JbpmContext.
*/
public static class Configs {
@@ -503,7 +502,8 @@
getPersistenceServiceFactory(jbpmContextName).dropSchema();
}
- private DbPersistenceServiceFactory getPersistenceServiceFactory(String jbpmContextName) {
+ private DbPersistenceServiceFactory getPersistenceServiceFactory(
+ String jbpmContextName) {
return (DbPersistenceServiceFactory) getServiceFactory(Services.SERVICENAME_PERSISTENCE, jbpmContextName);
}
@@ -561,7 +561,8 @@
JbpmConfiguration currentJbpmConfiguration = null;
List stack = getJbpmConfigurationStack();
if (!stack.isEmpty()) {
- currentJbpmConfiguration = (JbpmConfiguration) stack.get(stack.size() - 1);
+ currentJbpmConfiguration =
+ (JbpmConfiguration) stack.get(stack.size() - 1);
}
return currentJbpmConfiguration;
}
@@ -595,7 +596,21 @@
}
synchronized void popJbpmConfiguration() {
- getJbpmConfigurationStack().remove(this);
+ List stack = getJbpmConfigurationStack();
+ int index = stack.lastIndexOf(this);
+ if (index == -1) {
+ throw new JbpmException(this
+ + " does not appear in the thread-local stack");
+ }
+ else {
+ if (index != stack.size() - 1) {
+ log.warn(this
+ + " was closed in some order that differs from creation\n"
+ + "check your try-finally clauses around JbpmContext blocks");
+ }
+ // prevent configuration from remaining in the stack, no matter what
+ stack.remove(index);
+ }
}
public JbpmContext getCurrentJbpmContext() {
@@ -619,15 +634,19 @@
void popJbpmContext(JbpmContext jbpmContext) {
List stack = getJbpmContextStack();
- int size = stack.size();
- if (size == 0) {
- log.warn("closed JbpmContext more than once... "
- + "check your try-finally clauses around JbpmContext blocks");
+ int index = stack.lastIndexOf(jbpmContext);
+ if (index == -1) {
+ log.warn(jbpmContext + " does not appear in the thread-local stack\n"
+ + "avoid manipulating JbpmContext instances from multiple threads");
}
- else if (jbpmContext != stack.remove(size - 1)) {
- stack.remove(jbpmContext); // prevent context from remaining in the stack
- log.warn("closed JbpmContext in some order that differs from creation... "
- + "check your try-finally clauses around JbpmContext blocks");
+ else {
+ if (index != stack.size() - 1) {
+ log.warn(jbpmContext
+ + " was closed in some order that differs from creation\n"
+ + "check your try-finally clauses around JbpmContext blocks");
+ }
+ // prevent context from remaining in the stack, no matter what
+ stack.remove(index);
}
}
@@ -649,17 +668,17 @@
ensureOpen();
if (jobExecutor == null) {
- Object object = objectFactory.createObject("jbpm.job.executor");
- if (object instanceof JobExecutor) {
- jobExecutor = (JobExecutor) object;
- }
- else if (object != null) {
- throw new JbpmException("configuration object 'jbpm.job.executor' is not an "
- + JobExecutor.class.getName());
- }
+ jobExecutor =
+ (JobExecutor) objectFactory.createObject("jbpm.job.executor");
}
return jobExecutor;
}
+ public String toString() {
+ return ClassUtil.getSimpleName(JbpmConfiguration.class)
+ + (resourceName != null ? resourceName : "@"
+ + Integer.toHexString(hashCode()));
+ }
+
private static Log log = LogFactory.getLog(JbpmConfiguration.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfigurationTestHelper.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfigurationTestHelper.java 2009-12-03 01:18:46 UTC (rev 5904)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfigurationTestHelper.java 2009-12-03 04:04:57 UTC (rev 5905)
@@ -21,11 +21,9 @@
*/
package org.jbpm;
-public class JbpmConfigurationTestHelper
-{
- public static void reset()
- {
- JbpmConfiguration.defaultObjectFactory = null;
- JbpmConfiguration.instances.clear();
+public class JbpmConfigurationTestHelper {
+
+ public static JbpmConfiguration getCurrentJbpmConfiguration() {
+ return JbpmConfiguration.getCurrentJbpmConfiguration();
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2009-12-03 01:18:46 UTC (rev 5904)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2009-12-03 04:04:57 UTC (rev 5905)
@@ -1,11 +1,16 @@
<jbpm-configuration>
- <!--
- This configuration is used when there is no jbpm.cfg.xml file found in the
- root of the classpath. It is a very basic configuration without persistence
- and message services. Only the authorization service installed.
- You can parse and create processes, but when you try to use one of the
- unavailable services, you'll get an exception.
+ <!--
+ This file provides the default jBPM configuration. All available services
+ are enabled. Objects described in custom configuration files add to the
+ objects described here and override any object with the same name.
+
+ To customize specific objects, the custom configuration needs only contain
+ descriptions for those objects alone. For instance, to load a custom
+ Hibernate configuration resource, the following document suffices.
+ <jbpm-configuration>
+ <string name="resource.hibernate.cfg.xml" value="my.hibernate.cfg.xml" />
+ </jbpm-configuration>
-->
<jbpm-context>
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java 2009-12-03 04:04:57 UTC (rev 5905)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jbpm2630;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfigurationTestHelper;
+import org.jbpm.JbpmContext;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class JBPM2630Test extends AbstractJbpmTestCase {
+
+ JbpmConfiguration testConfiguration;
+ JbpmConfiguration noLogConfiguration;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ testConfiguration =
+ JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
+ noLogConfiguration =
+ JbpmConfiguration.getInstance("org/jbpm/jbpm2630/jbpm.nolog.cfg.xml");
+ }
+
+ protected void tearDown() throws Exception {
+ noLogConfiguration.close();
+ testConfiguration.close();
+ super.tearDown();
+ }
+
+ public void testPopJbpmConfiguration() {
+ JbpmContext testContext1 = testConfiguration.createJbpmContext();
+ try {
+ JbpmContext noLogContext = noLogConfiguration.createJbpmContext();
+ try {
+ JbpmContext testContext2 = testConfiguration.createJbpmContext();
+ try {
+ assertSame(testConfiguration, JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+ }
+ finally {
+ testContext2.close();
+ }
+ assertSame(noLogConfiguration, JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+ }
+ finally {
+ noLogContext.close();
+ }
+ assertSame(testConfiguration, JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+ }
+ finally {
+ testContext1.close();
+ }
+ }
+}
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2630/jbpm.nolog.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2630/jbpm.nolog.cfg.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2630/jbpm.nolog.cfg.xml 2009-12-03 04:04:57 UTC (rev 5905)
@@ -0,0 +1,10 @@
+<jbpm-configuration>
+ <jbpm-context>
+ <service name="authentication"
+ factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
+ <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
+ <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
+ <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
+ <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
+ </jbpm-context>
+</jbpm-configuration>
More information about the jbpm-commits
mailing list