Search in sources :

Example 1 with JobExecutor

use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.

the class CdiProcessEngineTestCase method waitForJobExecutorToProcessAllJobs.

// ////////////////////// copied from AbstractActivitiTestcase
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.start();
    try {
        Timer timer = new Timer();
        InteruptTask task = new InteruptTask(Thread.currentThread());
        timer.schedule(task, maxMillisToWait);
        boolean areJobsAvailable = true;
        try {
            while (areJobsAvailable && !task.isTimeLimitExceeded()) {
                Thread.sleep(intervalMillis);
                areJobsAvailable = areJobsAvailable();
            }
        } catch (InterruptedException e) {
        } finally {
            timer.cancel();
        }
        if (areJobsAvailable) {
            throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
        }
    } finally {
        jobExecutor.shutdown();
    }
}
Also used : Timer(java.util.Timer) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with JobExecutor

use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.

the class JBossSubsystemXMLTest method testInstallSubsystemWithJobExecutorAndPropertiesXml.

@Test
public void testInstallSubsystemWithJobExecutorAndPropertiesXml() throws Exception {
    String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_JOB_EXECUTOR_AND_PROPERTIES);
    KernelServices services = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
    ServiceContainer container = services.getContainer();
    commonSubsystemServicesAreInstalled(container);
    // "default" job acquisition ///////////////////////////////////////////////////////////
    ServiceController<?> defaultJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("default"));
    assertNotNull("platform job acquisition service 'default' should be installed", defaultJobAcquisitionService);
    Object value = defaultJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor defaultJobExecutor = (JobExecutor) value;
    assertEquals(300000, defaultJobExecutor.getLockTimeInMillis());
    assertEquals(5000, defaultJobExecutor.getWaitTimeInMillis());
    assertEquals(3, defaultJobExecutor.getMaxJobsPerAcquisition());
    // ServiceName: 'org.camunda.bpm.platform.job-executor.job-executor-tp'
    ServiceController<ManagedQueueExecutorService> managedQueueExecutorServiceController = (ServiceController<ManagedQueueExecutorService>) container.getService(ServiceNames.forManagedThreadPool(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
    assertNotNull(managedQueueExecutorServiceController);
    ManagedQueueExecutorService managedQueueExecutorService = managedQueueExecutorServiceController.getValue();
    assertNotNull(managedQueueExecutorService);
    assertEquals("Number of core threads is wrong", SubsystemAttributeDefinitons.DEFAULT_CORE_THREADS, managedQueueExecutorService.getCoreThreads());
    assertEquals("Number of max threads is wrong", SubsystemAttributeDefinitons.DEFAULT_MAX_THREADS, managedQueueExecutorService.getMaxThreads());
    assertEquals(SubsystemAttributeDefinitons.DEFAULT_KEEPALIVE_TIME, TimeUnit.NANOSECONDS.toSeconds(managedQueueExecutorService.getKeepAlive()));
    assertEquals(false, managedQueueExecutorService.isBlocking());
    assertEquals(SubsystemAttributeDefinitons.DEFAULT_ALLOW_CORE_TIMEOUT, managedQueueExecutorService.isAllowCoreTimeout());
    ServiceController<ThreadFactoryService> threadFactoryService = (ServiceController<ThreadFactoryService>) container.getService(ServiceNames.forThreadFactoryService(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
    assertNotNull(threadFactoryService);
    // "anders" job acquisition /////////////////////////////////////////////////////////
    ServiceController<?> andersJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("anders"));
    assertNotNull("platform job acquisition service 'anders' should be installed", andersJobAcquisitionService);
    value = andersJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor andersJobExecutor = (JobExecutor) value;
    assertEquals(600000, andersJobExecutor.getLockTimeInMillis());
    assertEquals(10000, andersJobExecutor.getWaitTimeInMillis());
    assertEquals(5, andersJobExecutor.getMaxJobsPerAcquisition());
    // "mixed" job acquisition /////////////////////////////////////////////////////////
    ServiceController<?> mixedJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("mixed"));
    assertNotNull("platform job acquisition service 'mixed' should be installed", mixedJobAcquisitionService);
    value = mixedJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor mixedJobExecutor = (JobExecutor) value;
    assertEquals(500000, mixedJobExecutor.getLockTimeInMillis());
    // default values
    assertEquals(5000, mixedJobExecutor.getWaitTimeInMillis());
    assertEquals(3, mixedJobExecutor.getMaxJobsPerAcquisition());
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) ManagedQueueExecutorService(org.jboss.as.threads.ManagedQueueExecutorService) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) ThreadFactoryService(org.jboss.as.threads.ThreadFactoryService) KernelServices(org.jboss.as.subsystem.test.KernelServices) ServiceController(org.jboss.msc.service.ServiceController) AbstractSubsystemTest(org.jboss.as.subsystem.test.AbstractSubsystemTest) Test(org.junit.Test)

Example 3 with JobExecutor

use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.

the class StartProcessEngineStep method performOperationStep.

public void performOperationStep(DeploymentOperation operationContext) {
    final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
    final AbstractProcessApplication processApplication = operationContext.getAttachment(PROCESS_APPLICATION);
    ClassLoader classLoader = null;
    if (processApplication != null) {
        classLoader = processApplication.getProcessApplicationClassloader();
    }
    String configurationClassName = processEngineXml.getConfigurationClass();
    if (configurationClassName == null || configurationClassName.isEmpty()) {
        configurationClassName = StandaloneProcessEngineConfiguration.class.getName();
    }
    // create & instantiate configuration class
    Class<? extends ProcessEngineConfigurationImpl> configurationClass = loadClass(configurationClassName, classLoader, ProcessEngineConfigurationImpl.class);
    ProcessEngineConfigurationImpl configuration = createInstance(configurationClass);
    // set UUid generator
    // TODO: move this to configuration and use as default?
    ProcessEngineConfigurationImpl configurationImpl = configuration;
    configurationImpl.setIdGenerator(new StrongUuidGenerator());
    // set configuration values
    String name = processEngineXml.getName();
    configuration.setProcessEngineName(name);
    String datasourceJndiName = processEngineXml.getDatasource();
    configuration.setDataSourceJndiName(datasourceJndiName);
    // apply properties
    Map<String, String> properties = processEngineXml.getProperties();
    setJobExecutorActivate(configuration, properties);
    PropertyHelper.applyProperties(configuration, properties);
    // instantiate plugins:
    configurePlugins(configuration, processEngineXml, classLoader);
    if (processEngineXml.getJobAcquisitionName() != null && !processEngineXml.getJobAcquisitionName().isEmpty()) {
        JobExecutor jobExecutor = getJobExecutorService(serviceContainer);
        ensureNotNull("Cannot find referenced job executor with name '" + processEngineXml.getJobAcquisitionName() + "'", "jobExecutor", jobExecutor);
        // set JobExecutor on process engine
        configurationImpl.setJobExecutor(jobExecutor);
    }
    // start the process engine inside the container.
    JmxManagedProcessEngine managedProcessEngineService = createProcessEngineControllerInstance(configuration);
    serviceContainer.startService(ServiceTypes.PROCESS_ENGINE, configuration.getProcessEngineName(), managedProcessEngineService);
}
Also used : AbstractProcessApplication(org.camunda.bpm.application.AbstractProcessApplication) JmxManagedProcessEngine(org.camunda.bpm.container.impl.jmx.services.JmxManagedProcessEngine) StandaloneProcessEngineConfiguration(org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration) PlatformServiceContainer(org.camunda.bpm.container.impl.spi.PlatformServiceContainer) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) StrongUuidGenerator(org.camunda.bpm.engine.impl.persistence.StrongUuidGenerator) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 4 with JobExecutor

use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.

the class JobRetryCmd method notifyAcquisition.

protected void notifyAcquisition(CommandContext commandContext) {
    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
    TransactionContext transactionContext = commandContext.getTransactionContext();
    transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
}
Also used : MessageAddedNotification(org.camunda.bpm.engine.impl.jobexecutor.MessageAddedNotification) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) TransactionContext(org.camunda.bpm.engine.impl.cfg.TransactionContext)

Example 5 with JobExecutor

use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.

the class AbstractProcessEngineTestCase method waitForJobExecutorOnCondition.

public void waitForJobExecutorOnCondition(long maxMillisToWait, Callable<Boolean> condition) {
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    jobExecutor.start();
    long intervalMillis = 500;
    if (maxMillisToWait < (jobExecutor.getWaitTimeInMillis() * 2)) {
        maxMillisToWait = (jobExecutor.getWaitTimeInMillis() * 2);
    }
    try {
        Timer timer = new Timer();
        InterruptTask task = new InterruptTask(Thread.currentThread());
        timer.schedule(task, maxMillisToWait);
        boolean conditionIsViolated = true;
        try {
            while (conditionIsViolated && !task.isTimeLimitExceeded()) {
                Thread.sleep(intervalMillis);
                conditionIsViolated = !condition.call();
            }
        } catch (InterruptedException e) {
        } catch (Exception e) {
            throw new ProcessEngineException("Exception while waiting on condition: " + e.getMessage(), e);
        } finally {
            timer.cancel();
        }
        if (conditionIsViolated) {
            throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
        }
    } finally {
        jobExecutor.shutdown();
    }
}
Also used : Timer(java.util.Timer) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)21 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)6 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)6 Timer (java.util.Timer)5 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)4 Test (org.junit.Test)4 Date (java.util.Date)3 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 Job (org.camunda.bpm.engine.runtime.Job)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractProcessApplication (org.camunda.bpm.application.AbstractProcessApplication)2 PlatformServiceContainer (org.camunda.bpm.container.impl.spi.PlatformServiceContainer)2 ProcessEngineConfiguration (org.camunda.bpm.engine.ProcessEngineConfiguration)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 HashMap (java.util.HashMap)1