Search in sources :

Example 21 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project tutorials by eugenp.

the class ProcessEngineCreationIntegrationTest method givenXMLConfig_whenCreateDefaultConfiguration_thenGotProcessEngine.

@Test
public void givenXMLConfig_whenCreateDefaultConfiguration_thenGotProcessEngine() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("root", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 22 with ProcessEngineConfiguration

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

the class AbstractActviti6Test method initializeH2WebApp.

protected void initializeH2WebApp(ProcessEngine processEngine) {
    try {
        final Server server = Server.createWebServer("-web");
        // Shutdown hook
        final ProcessEngineConfiguration processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
        final ProcessEngineLifecycleListener originalLifecycleListener = processEngineConfiguration.getProcessEngineLifecycleListener();
        processEngineConfiguration.setProcessEngineLifecycleListener(new ProcessEngineLifecycleListener() {

            @Override
            public void onProcessEngineClosed(ProcessEngine processEngine) {
                server.stop();
                originalLifecycleListener.onProcessEngineClosed(processEngine);
            }

            @Override
            public void onProcessEngineBuilt(ProcessEngine processEngine) {
                originalLifecycleListener.onProcessEngineBuilt(processEngine);
            }
        });
        // Actually start the web server
        server.start();
    } catch (SQLException e) {
        logger.warn("Could not start H2 webapp", e);
    }
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) Server(org.h2.tools.Server) SQLException(java.sql.SQLException) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) ProcessEngineLifecycleListener(org.activiti.engine.ProcessEngineLifecycleListener) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 23 with ProcessEngineConfiguration

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

the class JobRetryCmd method execute.

public Object execute(CommandContext commandContext) {
    JobEntity job = commandContext.getJobEntityManager().findById(jobId);
    if (job == null) {
        return null;
    }
    ProcessEngineConfiguration processEngineConfig = commandContext.getProcessEngineConfiguration();
    ExecutionEntity executionEntity = fetchExecutionEntity(commandContext, job.getExecutionId());
    FlowElement currentFlowElement = executionEntity != null ? executionEntity.getCurrentFlowElement() : null;
    String failedJobRetryTimeCycleValue = null;
    if (currentFlowElement instanceof ServiceTask) {
        failedJobRetryTimeCycleValue = ((ServiceTask) currentFlowElement).getFailedJobRetryTimeCycleValue();
    }
    AbstractJobEntity newJobEntity = null;
    if (currentFlowElement == null || failedJobRetryTimeCycleValue == null) {
        log.debug("activity or FailedJobRetryTimerCycleValue is null in job " + jobId + ". only decrementing retries.");
        if (job.getRetries() <= 1) {
            newJobEntity = commandContext.getJobManager().moveJobToDeadLetterJob(job);
        } else {
            newJobEntity = commandContext.getJobManager().moveJobToTimerJob(job);
        }
        newJobEntity.setRetries(job.getRetries() - 1);
        if (job.getDuedate() == null || JobEntity.JOB_TYPE_MESSAGE.equals(job.getJobType())) {
            // add wait time for failed async job
            newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getAsyncFailedJobWaitTime(), null));
        } else {
            // add default wait time for failed job
            newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getDefaultFailedJobWaitTime(), job.getDuedate()));
        }
    } else {
        try {
            DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycleValue, processEngineConfig.getClock());
            int jobRetries = job.getRetries();
            if (job.getExceptionMessage() == null) {
                // change default retries to the ones configured
                jobRetries = durationHelper.getTimes();
            }
            if (jobRetries <= 1) {
                newJobEntity = commandContext.getJobManager().moveJobToDeadLetterJob(job);
            } else {
                newJobEntity = commandContext.getJobManager().moveJobToTimerJob(job);
            }
            newJobEntity.setDuedate(durationHelper.getDateAfter());
            if (job.getExceptionMessage() == null) {
                // is it the first exception
                log.debug("Applying JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' the first time for job " + job.getId() + " with " + durationHelper.getTimes() + " retries");
            } else {
                log.debug("Decrementing retries of JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' for job " + job.getId());
            }
            newJobEntity.setRetries(jobRetries - 1);
        } catch (Exception e) {
            throw new ActivitiException("failedJobRetryTimeCylcle has wrong format:" + failedJobRetryTimeCycleValue, exception);
        }
    }
    if (exception != null) {
        newJobEntity.setExceptionMessage(exception.getMessage());
        newJobEntity.setExceptionStacktrace(getExceptionStacktrace());
    }
    // Dispatch both an update and a retry-decrement event
    ActivitiEventDispatcher eventDispatcher = commandContext.getEventDispatcher();
    if (eventDispatcher.isEnabled()) {
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, newJobEntity));
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_RETRIES_DECREMENTED, newJobEntity));
    }
    return null;
}
Also used : AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) ServiceTask(org.activiti.bpmn.model.ServiceTask) ActivitiException(org.activiti.engine.ActivitiException) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) FlowElement(org.activiti.bpmn.model.FlowElement) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) ActivitiException(org.activiti.engine.ActivitiException) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 24 with ProcessEngineConfiguration

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

the class ResourceActivitiTestCase method initializeProcessEngine.

@Override
protected void initializeProcessEngine() {
    ProcessEngineConfiguration config = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(activitiConfigurationResource);
    if (processEngineName != null) {
        logger.info("Initializing process engine with name '" + processEngineName + "'");
        config.setProcessEngineName(processEngineName);
    }
    additionalConfiguration(config);
    processEngine = config.buildProcessEngine();
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration)

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