[jbpm-commits] JBoss JBPM SVN: r4177 - in jbpm4/branches/hbraun/modules: distro/src/main/resources/installer and 10 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Mar 6 13:29:34 EST 2009
Author: heiko.braun at jboss.com
Date: 2009-03-06 13:29:34 -0500 (Fri, 06 Mar 2009)
New Revision: 4177
Added:
jbpm4/branches/hbraun/modules/integration/spi/src/main/java/org/jbpm/integration/spi/JBPMServiceLocator.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PolicyEvaluation.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SavePolicy.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java
Modified:
jbpm4/branches/hbraun/modules/config/src/main/config/jbpm/wire.bindings/part1.jbpm.wire.bindings.xml
jbpm4/branches/hbraun/modules/distro/src/main/resources/installer/install-definition.xml
jbpm4/branches/hbraun/modules/enterprise/src/main/resources/jbpm.cfg.xml
jbpm4/branches/hbraun/modules/integration/jboss5/integration-jboss5.iml
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeploymentMetaData.java
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMMetaDataDeployer.java
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMServiceImpl.java
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/resources/META-INF/jbpm-deployers-jboss-beans.xml
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/deploy/SaveDeployer.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SaveBinding.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Binding.java
Log:
AS 5 deployer, work in progress
Modified: jbpm4/branches/hbraun/modules/config/src/main/config/jbpm/wire.bindings/part1.jbpm.wire.bindings.xml
===================================================================
--- jbpm4/branches/hbraun/modules/config/src/main/config/jbpm/wire.bindings/part1.jbpm.wire.bindings.xml 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/config/src/main/config/jbpm/wire.bindings/part1.jbpm.wire.bindings.xml 2009-03-06 18:29:34 UTC (rev 4177)
@@ -72,6 +72,7 @@
<binding class="org.jbpm.pvm.internal.wire.binding.CheckProcessBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.CheckProblemsBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.SaveBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.VersionPolicySaveBinding" />
<!-- interceptors -->
<binding class="org.jbpm.pvm.internal.wire.binding.EnvironmentInterceptorBinding" />
Modified: jbpm4/branches/hbraun/modules/distro/src/main/resources/installer/install-definition.xml
===================================================================
--- jbpm4/branches/hbraun/modules/distro/src/main/resources/installer/install-definition.xml 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/distro/src/main/resources/installer/install-definition.xml 2009-03-06 18:29:34 UTC (rev 4177)
@@ -175,8 +175,7 @@
<!--fileset dir="@{deploy.artifacts.dir}/resources/jbpm-integration-config" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm/jbpm-service.sar" override="true">
<include name="bpm-process-deployer.xml" />
</fileset-->
- <fileset dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm/jbpm-service.sar" override="true">
- <include name="jbpm-log.jar" />
+ <fileset dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm/jbpm-service.sar" override="true">
<include name="jbpm-pvm.jar" />
<include name="jbpm-jpdl.jar" />
<include name="jbpm-task.jar" />
@@ -227,6 +226,7 @@
condition="isJBoss422">
<include name="jbpm-api.jar"/>
<include name="jbpm-spi.jar"/>
+ <include name="jbpm-log.jar" />
</fileset>
@@ -242,6 +242,7 @@
condition="isJBoss423">
<include name="jbpm-api.jar"/>
<include name="jbpm-spi.jar"/>
+ <include name="jbpm-log.jar" />
</fileset>
<!--
@@ -257,6 +258,7 @@
<include name="jbpm-api.jar"/>
<include name="jbpm-spi.jar"/>
<include name="jbpm-jboss5.jar"/>
+ <include name="jbpm-log.jar" />
</fileset>
<fileset dir="@{deploy.artifacts.dir}/resources/jbpm-jboss5-config/META-INF"
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/jbpm.deployer"
Modified: jbpm4/branches/hbraun/modules/enterprise/src/main/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/branches/hbraun/modules/enterprise/src/main/resources/jbpm.cfg.xml 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/enterprise/src/main/resources/jbpm.cfg.xml 2009-03-06 18:29:34 UTC (rev 4177)
@@ -15,19 +15,25 @@
<file extension=".jpdl.xml" type="jpdl" />
</assign-file-type>
<parse-jpdl />
- <check-process />
+ <!--check-process / Covered by VersionTimestampPolicy -->
<check-problems />
- <save />
+ <save policy="org.jbpm.pvm.internal.wire.binding.VersionTimestampPolicy"/>
</deployer-manager>
<process-service />
<execution-service />
<management-service />
- <ejb-local-command-service>
+ <!--ejb-local-command-service>
<home jndi-name="java:jbpm/CommandExecutor"/>
- </ejb-local-command-service>
+ </ejb-local-command-service-->
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <standard-transaction-interceptor />
+ </command-service>
+
<hibernate-configuration resource="hibernate.cfg.xml"/>
<hibernate-session-factory />
@@ -47,7 +53,8 @@
</process-engine-context>
<transaction-context>
- <hibernate-session current="true" />
+ <hibernate-session />
+ <transaction />
<pvm-db-session />
<job-db-session />
<ejb-timer-session />
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/integration-jboss5.iml
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/integration-jboss5.iml 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/integration-jboss5.iml 2009-03-06 18:29:34 UTC (rev 4177)
@@ -10,6 +10,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="toplevel" />
+ <orderEntry type="module" module-name="integration-spi" />
<orderEntry type="module-library" exported="">
<library name="M2 Dep: org.jboss.identity:idm-spi:jar:1.0.0-SNAPSHOT:compile">
<CLASSES>
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -21,22 +21,33 @@
*/
package org.jbpm.integration.jboss5;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-
+import org.jbpm.Deployment;
+import org.jbpm.ProcessService;
+import org.jbpm.env.Environment;
+import org.jbpm.env.EnvironmentFactory;
import org.jbpm.integration.spi.JBPMService;
-import org.jbpm.integration.util.KernelAwareSPIFactory;
+import org.jbpm.integration.spi.JBPMServiceLocator;
+import org.jbpm.internal.log.Log;
+import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
+import javax.transaction.SystemException;
+import java.io.File;
+
/**
* Deploys JBPM processes and associates a classloader.
- *
+ *
* @author Heiko.Braun <heiko.braun at jboss.com>
*/
public class JBPMDeployer extends AbstractSimpleVFSRealDeployer<JBPMDeploymentMetaData>
{
+ private static final Log log = Log.getLog(JBPMDeployer.class.getName());
+
public JBPMDeployer()
{
super(JBPMDeploymentMetaData.class);
@@ -45,19 +56,59 @@
public void deploy(VFSDeploymentUnit unit, JBPMDeploymentMetaData deployment)
throws DeploymentException
{
- System.out.println("*** JBPM : Working on " + deployment);
+ JBPMService jbpmService = JBPMServiceLocator.locateService();
- JBPMService jbpmService = new KernelAwareSPIFactory().getKernelProvidedSPI(
- "org.jbpm:service=ProcessEngine", JBPMService.class
- );
+ // associate classloader
+ deployment.setClassloader(unit.getClassLoader());
- System.out.println("*** JBPM Service: " + jbpmService);
+ log.info("Deploy " + deployment);
+
+ UserTransaction tx = null;
+
+ try
+ {
+
+ InitialContext ctx = new InitialContext();
+ tx = (UserTransaction)ctx.lookup("UserTransaction");
+
+ tx.begin();
+
+
+ // deploy to process engine
+ ProcessService processService = jbpmService.getProcessEngine().getProcessService();
+ String pathToDeployment = unit.getTopLevel().getRoot().toURL().getPath();
+ File deploymentFile = new File(pathToDeployment);
+
+ Deployment dpl = processService.createDeployment()
+ .addUrl(deployment.getProcessDescriptor())
+ .addObject("jbpmdeployer.deploymentArtifact.timestamp", Long.valueOf(deploymentFile.lastModified()))
+ .addObject("jbpmdeployer.deploymentArtifact.location", deployment.getDeploymentUnit());
+
+ dpl.deploy();
+
+ tx.commit();
+
+ }
+ catch(Exception e)
+ {
+ if(tx!=null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e1) {}
+ }
+
+ throw new DeploymentException("Failed to deploy process", e);
+ }
+
}
public void undeploy(DeploymentUnit unit, JBPMDeploymentMetaData deployment)
{
- System.out.println("*** JBPM : Undeploy "+deployment);
-
+ log.info("Undeploy "+deployment);
+
super.undeploy(unit, deployment);
}
}
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeploymentMetaData.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeploymentMetaData.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeploymentMetaData.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -21,9 +21,49 @@
*/
package org.jbpm.integration.jboss5;
+import java.net.URL;
+
/**
* @author Heiko.Braun <heiko.braun at jboss.com>
*/
public class JBPMDeploymentMetaData
{
+ private URL deploymentUnit;
+ private URL processDescriptor;
+ private ClassLoader classloader;
+
+ public void setProcessDescriptor(URL processDescriptor)
+ {
+ this.processDescriptor = processDescriptor;
+ }
+
+ public void setDeploymentUnit(URL deploymentUnit)
+ {
+ this.deploymentUnit = deploymentUnit;
+ }
+
+ public void setClassloader(ClassLoader classloader)
+ {
+ this.classloader = classloader;
+ }
+
+ public URL getDeploymentUnit()
+ {
+ return deploymentUnit;
+ }
+
+ public URL getProcessDescriptor()
+ {
+ return processDescriptor;
+ }
+
+ public ClassLoader getClassloader()
+ {
+ return classloader;
+ }
+
+ public String toString()
+ {
+ return "JBPMDeploymentMetaData {unit="+deploymentUnit+", jpdl="+processDescriptor+", cl="+classloader+"}";
+ }
}
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMMetaDataDeployer.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMMetaDataDeployer.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMMetaDataDeployer.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -23,7 +23,10 @@
import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.virtual.VirtualFile;
+import org.jbpm.internal.log.Log;
/**
* Prepares {@link org.jbpm.integration.jboss5.JBPMDeploymentMetaData}
@@ -32,18 +35,24 @@
*/
public class JBPMMetaDataDeployer extends AbstractVFSParsingDeployer<JBPMDeploymentMetaData>
{
+ private static final Log log = Log.getLog(JBPMMetaDataDeployer.class.getName());
public JBPMMetaDataDeployer()
{
super(JBPMDeploymentMetaData.class);
}
- protected JBPMDeploymentMetaData parse(VFSDeploymentUnit unit, VirtualFile file, JBPMDeploymentMetaData root) throws Exception
+ protected JBPMDeploymentMetaData parse(
+ VFSDeploymentUnit unit,
+ VirtualFile file, JBPMDeploymentMetaData root) throws Exception
{
- System.out.println("*** JBPM: Creating structure from " + file);
+ log.debug("Creating structure from " + file);
- // TODO: implement parsing logic
+ JBPMDeploymentMetaData md = new JBPMDeploymentMetaData();
+
+ md.setProcessDescriptor(file.toURL());
+ md.setDeploymentUnit(unit.getRoot().toURL());
- return new JBPMDeploymentMetaData();
+ return md;
}
}
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMServiceImpl.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMServiceImpl.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMServiceImpl.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -24,24 +24,27 @@
import org.jbpm.integration.spi.JBPMService;
import org.jbpm.ProcessEngine;
import org.jbpm.Configuration;
+import org.jbpm.internal.log.Log;
/**
* @author Heiko.Braun <heiko.braun at jboss.com>
*/
public class JBPMServiceImpl implements JBPMService
{
+ private static final Log log = Log.getLog(JBPMServiceImpl.class.getName());
+
private ProcessEngine processEngine;
public void start()
{
this.processEngine = new Configuration().buildProcessEngine();
- System.out.println("** JBPMService started: " + this.processEngine);
+ log.info("JBPMService started: " + this.processEngine);
}
public void stop()
{
this.processEngine = null;
- System.out.println("** JBPMService stopped");
+ log.info("JBPMService stopped");
}
public ProcessEngine getProcessEngine()
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/resources/META-INF/jbpm-deployers-jboss-beans.xml
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/resources/META-INF/jbpm-deployers-jboss-beans.xml 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/resources/META-INF/jbpm-deployers-jboss-beans.xml 2009-03-06 18:29:34 UTC (rev 4177)
@@ -5,29 +5,39 @@
<!--
Locate the single instance of the kernel
-->
- <bean name="org.jbpm:service=KernelLocator" class="org.jbpm.integration.util.KernelLocator">
- <property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
+ <bean name="org.jbpm:service=KernelLocator"
+ class="org.jbpm.integration.util.KernelLocator">
+ <property name="kernel">
+ <inject bean="jboss.kernel:service=Kernel" />
+ </property>
</bean>
<!--
The JBPM Meta Data Deployer
-->
- <bean name="org.jbpm:service=MetaDataDeployer" class="org.jbpm.integration.jboss5.JBPMMetaDataDeployer">
- <property name="suffix">jpdl.xml</property>
- <property name="jarExtension">par</property>
+ <bean name="org.jbpm:service=MetaDataDeployer"
+ class="org.jbpm.integration.jboss5.JBPMMetaDataDeployer">
+
+ <property name="suffix">.jpdl.xml</property>
+
+ <!-- Move to .par when https://jira.jboss.org/jira/browse/JBAS-6274 is done -->
+ <property name="jarExtension">jar</property>
+
<property name="allowMultipleFiles">true</property>
<!-- files the deployer can process -->
<!--property name="names">
<set elementClass="java.lang.String">
- <value>processdefinition.xml</value>
+ <value>process.jpdl.xml</value>
</set>
</property-->
+
</bean>
<!--
The actual jBPM Deployer
-->
- <bean name="org.jbpm:service=Deployer" class="org.jbpm.integration.jboss5.JBPMDeployer"/>
-
+ <bean name="org.jbpm:service=Deployer"
+ class="org.jbpm.integration.jboss5.JBPMDeployer"/>
+
</deployment>
\ No newline at end of file
Added: jbpm4/branches/hbraun/modules/integration/spi/src/main/java/org/jbpm/integration/spi/JBPMServiceLocator.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/spi/src/main/java/org/jbpm/integration/spi/JBPMServiceLocator.java (rev 0)
+++ jbpm4/branches/hbraun/modules/integration/spi/src/main/java/org/jbpm/integration/spi/JBPMServiceLocator.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.integration.spi;
+
+import org.jbpm.integration.util.KernelAwareSPIFactory;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class JBPMServiceLocator
+{
+ public static JBPMService locateService()
+ {
+ return new KernelAwareSPIFactory().getKernelProvidedSPI(
+ "org.jbpm:service=ProcessEngine", JBPMService.class
+ );
+ }
+
+ public static JBPMService locateService(String configName)
+ {
+ return new KernelAwareSPIFactory().getKernelProvidedSPI(
+ "org.jbpm:service=ProcessEngine,name="+configName, JBPMService.class
+ );
+ }
+}
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/deploy/SaveDeployer.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/deploy/SaveDeployer.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/deploy/SaveDeployer.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -23,12 +23,15 @@
import java.io.InputStream;
import java.io.Serializable;
+import java.util.Map;
import org.jbpm.ProcessDefinition;
import org.jbpm.env.Environment;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.svc.DeploymentImpl;
+import org.jbpm.pvm.internal.wire.binding.SavePolicy;
+import org.jbpm.pvm.internal.wire.binding.PolicyEvaluation;
import org.jbpm.session.PvmDbSession;
/**
@@ -38,7 +41,20 @@
private static final long serialVersionUID = 1L;
private static Log log = Log.getLog(SaveDeployer.class.getName());
-
+
+ // the default policy does always apply
+ private final static SavePolicy DEFAULT_POLICY = new SavePolicy()
+ {
+ public PolicyEvaluation evaluate(DeploymentImpl deployment)
+ {
+ PolicyEvaluation evaluation = new PolicyEvaluation();
+ evaluation.setDoesApply(true);
+ return evaluation;
+ }
+ };
+
+ private SavePolicy policy = DEFAULT_POLICY;
+
public void deploy(DeploymentImpl deployment) {
Environment environment = Environment.getCurrent();
if (environment==null) {
@@ -46,21 +62,30 @@
return;
}
+ // if the save policy doesn't apply,
+ // then the process will not be stored
+ PolicyEvaluation policyEvaluation = policy.evaluate(deployment);
+ if( policyEvaluation.doesApply() == false)
+ {
+ log.info("Policy " + policy.getClass().getName() + " doesn't appply. Skip deployment.");
+ return;
+ }
+
PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
if (pvmDbSession==null) {
deployment.addProblem(PvmDbSession.class.getName()+" is required in the environment by "+getClass().getName());
return;
}
-
+
ProcessDefinitionImpl lastProcessDefinition = null;
-
+
boolean deployedProcess = false;
for (String objectName : deployment.getObjectNames()) {
Object object = deployment.getObject(objectName);
if (object instanceof ProcessDefinition) {
deployedProcess = true;
- lastProcessDefinition = (ProcessDefinitionImpl) object;
-
+ lastProcessDefinition = (ProcessDefinitionImpl) object;
+
log.debug("saving process definition "+object);
pvmDbSession.save(object);
}
@@ -70,6 +95,16 @@
for (String fileName : deployment.getFileNames()) {
InputStream inputStream = deployment.getFile(fileName);
lastProcessDefinition.addAttachment(fileName, inputStream);
+
+ // persist policy evaluation results
+ // policies may require this information upon subsequent calls
+ // i.e. redeployment of process definitions
+ Map<String,String> policyEvaluationResults = policyEvaluation.getResults();
+ for(String key : policyEvaluationResults.keySet())
+ {
+ lastProcessDefinition.addAttachment(key, policyEvaluationResults.get(key).getBytes());
+ }
+
}
}
@@ -81,4 +116,9 @@
public String toString() {
return "save";
}
+
+ public void setPolicy(SavePolicy policy)
+ {
+ this.policy = policy;
+ }
}
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -40,7 +40,8 @@
/**
* @author Tom Baeyens
*/
-public class ProcessDefinitionImpl extends CompositeElementImpl implements OpenProcessDefinition, ClientProcessDefinition {
+public class ProcessDefinitionImpl extends CompositeElementImpl
+ implements OpenProcessDefinition, ClientProcessDefinition {
private static final long serialVersionUID = 1L;
private static final Log log = Log.getLog(ProcessDefinitionImpl.class.getName());
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -28,8 +28,11 @@
import org.jbpm.pvm.internal.svc.Interceptor;
-/** calls setRollbackOnly on the transaction in the environment
+/**
+ * Calls setRollbackOnly on the transaction in the environment
* in case an exception occurs during execution of the command.
+ * <p>
+ * Models "requires-new" semantic.
*
* @author Tom Baeyens
*/
Added: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PolicyEvaluation.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PolicyEvaluation.java (rev 0)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PolicyEvaluation.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.pvm.internal.wire.binding;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class PolicyEvaluation
+{
+ private boolean doesApply = true;
+ private Map<String, String> results = new HashMap<String,String>();
+
+ public boolean doesApply()
+ {
+ return doesApply;
+ }
+
+ public void setDoesApply(boolean doesApply)
+ {
+ this.doesApply = doesApply;
+ }
+
+ public Map<String, String> getResults()
+ {
+ return results;
+ }
+}
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SaveBinding.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SaveBinding.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SaveBinding.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -42,6 +42,23 @@
public Object parse(Element element, Parse parse, Parser parser) {
SaveDeployer saveDeployer = new SaveDeployer();
+
+ if (element.hasAttribute("policy")) {
+ String policyClassName = element.getAttribute("policy");
+ SavePolicy policy = null;
+ try
+ {
+ Class<?> policyClass = Thread.currentThread().getContextClassLoader().loadClass(policyClassName);
+ policy = (SavePolicy)policyClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Failed to load policy " +policyClassName, e);
+ }
+
+ saveDeployer.setPolicy(policy);
+ }
+
return new ProvidedObjectDescriptor(saveDeployer);
}
}
Added: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SavePolicy.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SavePolicy.java (rev 0)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SavePolicy.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.pvm.internal.wire.binding;
+
+import org.jbpm.pvm.internal.svc.DeploymentImpl;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface SavePolicy
+{
+ PolicyEvaluation evaluate(DeploymentImpl deployment);
+}
Added: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java (rev 0)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.pvm.internal.wire.binding;
+
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.svc.DeploymentImpl;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.env.Environment;
+import org.jbpm.ProcessService;
+import org.jbpm.ProcessDefinitionQuery;
+import org.jbpm.ProcessDefinition;
+import org.jbpm.client.ClientProcessDefinition;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import java.io.Serializable;
+import java.util.List;
+import java.net.URL;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class VersionTimestampPolicy implements SavePolicy, Serializable
+{
+ private static Log log = Log.getLog(VersionTimestampPolicy.class.getName());
+
+ private static final String DEPLOYER_TIMESTAMP = "jbpmdeployer.deploymentArtifact.timestamp";
+ private static final String DEPLOYER_LOCATION = "jbpmdeployer.deploymentArtifact.location";
+
+ public PolicyEvaluation evaluate(DeploymentImpl deployment)
+ {
+ log.debug("Apply " + this.getClass().getName());
+
+ PolicyEvaluation evaluation = new PolicyEvaluation();
+
+ for (String fileName: deployment.getFileNamesForType("jpdl"))
+ {
+ Document doc = deployment.getDocument(fileName);
+ if(null==doc)
+ throw new IllegalArgumentException("Policy expects JPDL document");
+
+ Element processEl = doc.getDocumentElement();
+ String nameAttribute = XmlUtil.attribute(processEl, "name");
+ String keyAttribute = XmlUtil.attribute(processEl, "key");
+ String versionAttribute = XmlUtil.attribute(processEl, "version");
+
+ // @see JBPMDeployer, it provides the timestamp
+ long currentTimestamp = (Long)deployment.getObject(DEPLOYER_TIMESTAMP);
+ URL deloymentLocation = (URL)deployment.getObject(DEPLOYER_LOCATION);
+
+ // provide evaluation properties
+ evaluation.getResults().put(DEPLOYER_TIMESTAMP, String.valueOf(currentTimestamp));
+ evaluation.getResults().put(DEPLOYER_LOCATION, String.valueOf(deloymentLocation.getPath()));
+
+ // can either be key or name given
+ String identifier = nameAttribute!=null ? nameAttribute : keyAttribute;
+
+ // query exisisting processes
+ ProcessService processService = getEnvironment().get(ProcessService.class);
+ ProcessDefinitionQuery query = processService.createProcessDefinitionQuery();
+ if(nameAttribute!=null)
+ query.nameLike(nameAttribute);
+ else
+ query.keyLike(keyAttribute);
+ List<ProcessDefinition> deployedProcesses = query.execute();
+
+ // apply either version or timestamp policy
+ if(versionAttribute!=null)
+ {
+ log.info("Version driven policy evaluation: process '"+identifier+"', version " +versionAttribute);
+
+ long processVersion = Long.valueOf(versionAttribute);
+ for(ProcessDefinition pd : deployedProcesses)
+ {
+ if(processVersion == pd.getVersion())
+ {
+ // explicit version version match
+ // the process will not be saved
+ evaluation.setDoesApply(false);
+
+ log.info("A process definition '"+identifier+"' with version "+versionAttribute+
+ " does already exist. The process will not be deployed: " + deloymentLocation);
+ break;
+ }
+ }
+ }
+ else
+ {
+ log.info("Timestamp driven policy evaluation: process '"+identifier+"', timestamp " +currentTimestamp);
+
+ for(ProcessDefinition pd : deployedProcesses)
+ {
+
+ byte[] bytes = ((ClientProcessDefinition)pd).getAttachment(DEPLOYER_TIMESTAMP);
+ if(null==bytes)
+ {
+ log.error("Failed to retrieve 'jbpmdeployer.deploymentArtifact.timestamp' from process attachments");
+ continue;
+ }
+
+ String s = new String(bytes);
+ long processTimestamp = Long.valueOf(s);
+
+ if(currentTimestamp <= processTimestamp)
+ {
+ // the timestamp of a given deployment artifact
+ // is less or equal to the already deployed process definition
+ // this prevents redeployments upon AS boot
+ evaluation.setDoesApply(false);
+
+ log.info("The deployment artifact doesn't seem to have changed: '"+deloymentLocation+"'."
+ +" Process "+identifier+" will not be deployed");
+ break;
+ }
+
+ }
+ }
+
+ }
+
+ return evaluation;
+ }
+
+ private Environment getEnvironment()
+ {
+ Environment environment = Environment.getCurrent();
+ if (environment==null)
+ throw new RuntimeException("Failed to access current environment");
+ return environment;
+
+ }
+}
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Binding.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Binding.java 2009-03-06 18:28:27 UTC (rev 4176)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Binding.java 2009-03-06 18:29:34 UTC (rev 4177)
@@ -34,7 +34,7 @@
String getCategory();
- /** does this binding apply to the given element? */
+ /** does this binding appliesTo to the given element? */
boolean matches(Element element);
/** translates the given element into a domain model java object.
More information about the jbpm-commits
mailing list