Search in sources :

Example 1 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class CamelBehavior method setAppropriateCamelContext.

protected void setAppropriateCamelContext(ActivityExecution execution) {
    //Check to see if the springConfiguration has been set. If not, set it.
    if (springConfiguration == null) {
        //Get the ProcessEngineConfiguration object.
        ProcessEngineConfiguration engineConfiguration = Context.getProcessEngineConfiguration();
        // (ActivitiException extends RuntimeException.)
        try {
            springConfiguration = (SpringProcessEngineConfiguration) engineConfiguration;
        } catch (Exception e) {
            throw new ActivitiException("Expecting a SpringProcessEngineConfiguration for the Activiti Camel module.", e);
        }
    }
    //Get the appropriate String representation of the CamelContext object from ActivityExecution (if available).
    String camelContextValue = getStringFromField(camelContext, execution);
    //If the String representation of the CamelContext object from ActivityExecution is empty, use the default.
    if (StringUtils.isEmpty(camelContextValue) && camelContextObj != null) {
    //No processing required. No custom CamelContext & the default is already set.
    } else {
        if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
            camelContextValue = springConfiguration.getDefaultCamelContext();
        }
        //Get the CamelContext object and set the super's member variable.
        Object ctx = springConfiguration.getApplicationContext().getBean(camelContextValue);
        if (ctx == null || ctx instanceof CamelContext == false) {
            throw new ActivitiException("Could not find CamelContext named " + camelContextValue + ".");
        }
        camelContextObj = (CamelContext) ctx;
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ActivitiException(org.activiti.engine.ActivitiException) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivitiException(org.activiti.engine.ActivitiException)

Example 2 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class DeploymentsJMXClientTest method testDeploymentsJmxClient.

@SuppressWarnings("unchecked")
@Test
public void testDeploymentsJmxClient() throws IOException, InterruptedException, MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException, IntrospectionException {
    String hostName = Utils.getHostName();
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostName + ":10111/jndi/rmi://" + hostName + ":1099/jmxrmi/activiti");
    ProcessEngineConfiguration processEngineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    ProcessEngine processEngine = processEngineConfig.buildProcessEngine();
    // wait for jmx server to come up
    Thread.sleep(500);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName deploymentsBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=Deployments");
    Thread.sleep(500);
    // no process deployed yet
    List<List<String>> deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertEquals(0, deployments.size());
    // deploy process remotely
    URL fileName = Thread.currentThread().getContextClassLoader().getResource("org/activiti/management/jmx/trivialProcess.bpmn");
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // one process is there now, test remote deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    String firstDeploymentId = deployments.get(0).get(0);
    // test remote process definition
    List<List<String>> pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(1, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertNotNull(pdList.get(0).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    // version
    assertEquals("1", pdList.get(0).get(2));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    // redeploy the same process
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // now there should be two deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(2, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertEquals(3, deployments.get(1).size());
    // there should be two process definitions, one with version equals to two
    pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(2, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertEquals(5, pdList.get(1).size());
    // check there is one with version= = 1 and another one with version == 2, other attributed are the same
    String pidV2 = null;
    String pidV1 = null;
    if (pdList.get(0).get(2).equals("1") && pdList.get(1).get(2).equals("2")) {
        pidV2 = pdList.get(1).get(0);
        pidV1 = pdList.get(0).get(0);
    } else if (pdList.get(1).get(2).equals("1") && pdList.get(0).get(2).equals("2")) {
        pidV2 = pdList.get(0).get(0);
        pidV1 = pdList.get(1).get(0);
    } else
        fail("there should one process definition with version == 1 and another one with version == 2. It is not the case");
    assertNotNull(pdList.get(0).get(0));
    assertNotNull(pdList.get(1).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    assertEquals("My process", pdList.get(1).get(1));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    // not suspended
    assertEquals("false", pdList.get(1).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    assertEquals("This process to test JMX", pdList.get(1).get(4));
    //suspend the one with version == 2    
    mbsc.invoke(deploymentsBeanName, "suspendProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // test if it is realy suspended and not the other one
    assertTrue(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if it is reported as suspended and not the other one
    List<String> pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("true", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now reactivate the same suspended process 
    mbsc.invoke(deploymentsBeanName, "activatedProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    // test if both processes are active again
    assertFalse(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if they are properly reported as activated
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now undeploy the one with version == 1
    mbsc.invoke(deploymentsBeanName, "deleteDeployment", new String[] { firstDeploymentId }, new String[] { String.class.getName() });
    // now there should be only one deployment and only one process definition with version 2, first check it with API
    assertEquals(1, repositoryService.createDeploymentQuery().count());
    assertTrue(!repositoryService.createDeploymentQuery().singleResult().getId().equals(firstDeploymentId));
    // check if it is also affected in returned results.
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertTrue(!deployments.get(0).get(0).equals(firstDeploymentId));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) JMXConnector(javax.management.remote.JMXConnector) List(java.util.List) MBeanServerConnection(javax.management.MBeanServerConnection) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngine(org.activiti.engine.ProcessEngine) ObjectName(javax.management.ObjectName) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 3 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class Main method createJobExecutorProcessEngine.

private static void createJobExecutorProcessEngine(boolean replaceExisting, boolean isDropDatabaseSchema) {
    if (processEngine == null || replaceExisting) {
        System.out.println("Creating process engine with config activiti_with_jobexecutor.cfg.xml. Dropping db first = " + isDropDatabaseSchema);
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti_with_jobexecutor.cfg.xml");
        if (isDropDatabaseSchema) {
            processEngineConfiguration.setDatabaseSchemaUpdate("drop-create");
        }
        processEngine = processEngineConfiguration.buildProcessEngine();
    }
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration)

Example 4 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class JobEntityManager method schedule.

public void schedule(TimerEntity timer) {
    Date duedate = timer.getDuedate();
    if (duedate == null) {
        throw new ActivitiIllegalArgumentException("duedate is null");
    }
    timer.insert();
    ProcessEngineConfiguration engineConfiguration = Context.getProcessEngineConfiguration();
    if (engineConfiguration.isAsyncExecutorEnabled() == false && timer.getDuedate().getTime() <= (engineConfiguration.getClock().getCurrentTime().getTime())) {
        hintJobExecutor(timer);
    }
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Date(java.util.Date)

Example 5 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class AbstractPlaybackTest method initializeProcessEngine.

@Override
protected void initializeProcessEngine() {
    Clock clock = new DefaultClockImpl();
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    processEngineConfiguration.setClock(clock);
    this.processEngine = (new RecordableProcessEngineFactory((ProcessEngineConfigurationImpl) processEngineConfiguration, listener)).getObject();
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) RecordableProcessEngineFactory(org.activiti.crystalball.simulator.impl.RecordableProcessEngineFactory)

Aggregations

ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)24 ProcessEngine (org.activiti.engine.ProcessEngine)7 Test (org.junit.Test)7 Date (java.util.Date)4 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)4 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)4 StreamResource (com.vaadin.terminal.StreamResource)3 Embedded (com.vaadin.ui.Embedded)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Panel (com.vaadin.ui.Panel)2 URL (java.net.URL)2 GregorianCalendar (java.util.GregorianCalendar)2 MBeanServerConnection (javax.management.MBeanServerConnection)2 ObjectName (javax.management.ObjectName)2 JMXConnector (javax.management.remote.JMXConnector)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 ActivitiException (org.activiti.engine.ActivitiException)2 RepositoryService (org.activiti.engine.RepositoryService)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2