org.activiti.engine.ManagementService Java Examples

The following examples show how to use org.activiti.engine.ManagementService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessConnectorImpl.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 作业.
 */
public Page findJobs(String tenantId, Page page) {
    ManagementService managementService = processEngine
            .getManagementService();

    long count = managementService.createJobQuery().jobTenantId(tenantId)
            .count();
    List<Job> jobs = managementService.createJobQuery()
            .jobTenantId(tenantId)
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(jobs);

    page.setTotalCount(count);

    return page;
}
 
Example #2
Source File: Application.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Bean
CommandLineRunner customMybatisXmlMapper(final ManagementService managementService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... args) throws Exception {
            String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {
                @Override
                public String execute(CommandContext commandContext) {
                    return (String) commandContext
                            .getDbSqlSession()
                            .selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
                }
            });

            logger.info("Process definition deployment id = {}", processDefinitionDeploymentId);
        }
    };
}
 
Example #3
Source File: ActivitiRuleJunit4Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/activiti/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" })
public void testWaitForJobs() {
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  ManagementService managementService = activitiRule.getManagementService();

  // start process
  runtimeService.startProcessInstanceByKey("asyncTask");

  // now there should be one job in the database:
  assertEquals(1, managementService.createJobQuery().count());

  JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 5000L, 500L);

  // the job is done
  assertEquals(0, managementService.createJobQuery().count());
}
 
Example #4
Source File: ActivitiRuleJunit4Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources={"org/activiti5/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml"})
public void testWaitForJobs() {
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  ManagementService managementService = activitiRule.getManagementService();
 
  // start process 
  runtimeService.startProcessInstanceByKey("asyncTask");
 
  // now there should be one job in the database:
  assertEquals(1, managementService.createJobQuery().count());
    
  JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 5000L, 500L);
 
  // the job is done
  assertEquals(0, managementService.createJobQuery().count()); 
}
 
Example #5
Source File: InitProcessEngineBySpringAnnotation.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx =
            new AnnotationConfigApplicationContext();
    ctx.register(SpringAnnotationConfiguration.class);
    ctx.refresh();

    assertNotNull(ctx.getBean(ProcessEngine.class));
    assertNotNull(ctx.getBean(RuntimeService.class));
    TaskService bean = ctx.getBean(TaskService.class);
    assertNotNull(bean);
    assertNotNull(ctx.getBean(HistoryService.class));
    assertNotNull(ctx.getBean(RepositoryService.class));
    assertNotNull(ctx.getBean(ManagementService.class));
    assertNotNull(ctx.getBean(FormService.class));
    Task task = bean.newTask();
    task.setName("哈哈");
    bean.saveTask(task);
}
 
Example #6
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfiguration processEngineConfiguration, 
    ManagementService managementService, long maxMillisToWait, long intervalMillis, boolean shutdownExecutorWhenFinished) {
  
  AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
  asyncExecutor.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);
        try {
          areJobsAvailable = areJobsAvailable(managementService);
        } catch(Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
      // ignore
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
  	if (shutdownExecutorWhenFinished) {
     asyncExecutor.shutdown();
  	}
  }
}
 
Example #7
Source File: RevokeAccessServiceTask.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
@Autowired
public RevokeAccessServiceTask(EmailServiceWrapper emailServiceWrapper,
                               DatabaseConnectionService databaseConnectionService,
                               ManagementService managementService,
                               RdsLookupService rdsLookupService) {
    this.emailServiceWrapper = emailServiceWrapper;
    this.databaseConnectionService = databaseConnectionService;
    this.managementService = managementService;
    this.rdsLookupService = rdsLookupService;
}
 
Example #8
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(ProcessEngineConfiguration processEngineConfiguration, ManagementService managementService, long maxMillisToWait, long intervalMillis,
    boolean shutdownExecutorWhenFinished) {

  AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
  asyncExecutor.start();
  processEngineConfiguration.setAsyncExecutorActivate(true);
  
  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);
        try {
          areJobsAvailable = areJobsOrExecutableTimersAvailable(managementService);
        } catch (Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
      // ignore
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    if (shutdownExecutorWhenFinished) {
      processEngineConfiguration.setAsyncExecutorActivate(false);
      asyncExecutor.shutdown();
    }
  }
}
 
Example #9
Source File: RevokeAccessServiceTask.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
@Autowired
public RevokeAccessServiceTask(EmailServiceWrapper emailServiceWrapper,
                               SsmService ssmService,
                               SnsService snsService,
                               ManagementService managementService,
                               Ec2LookupService ec2LookupService,
                               AccessRequestService accessRequestService){
    this.emailServiceWrapper = emailServiceWrapper;
    this.ssmService = ssmService;
    this.snsService = snsService;
    this.managementService = managementService;
    this.ec2LookupService = ec2LookupService;
    this.accessRequestService = accessRequestService;
}
 
Example #10
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean areJobsOrExecutableTimersAvailable(ManagementService managementService) {
  boolean emptyJobs = managementService.createJobQuery().list().isEmpty();
  if (emptyJobs) {
    return !managementService.createTimerJobQuery().executable().list().isEmpty();
  } else {
    return true;
  }
}
 
Example #11
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean areJobsOrExecutableTimersAvailable(ManagementService managementService) {
  boolean emptyJobs = managementService.createJobQuery().list().isEmpty();
  if (emptyJobs) {
    return !managementService.createTimerJobQuery().executable().list().isEmpty();
  } else {
    return true;
  }
}
 
Example #12
Source File: JobExecuteFailExecutor.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
    ManagementService managementService = execution.getEngineServices().getManagementService();
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (job.getRetries() > 0) {
        throw new RuntimeException("本次作业执行失败,再次执行可以成功!");
    }
}
 
Example #13
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(ProcessEngineConfiguration processEngineConfiguration, ManagementService managementService, long maxMillisToWait, long intervalMillis,
    boolean shutdownExecutorWhenFinished) {

  AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
  asyncExecutor.start();
  processEngineConfiguration.setAsyncExecutorActivate(true);
  
  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);
        try {
          areJobsAvailable = areJobsOrExecutableTimersAvailable(managementService);
        } catch (Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
      // ignore
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    if (shutdownExecutorWhenFinished) {
      processEngineConfiguration.setAsyncExecutorActivate(false);
      asyncExecutor.shutdown();
    }
  }
}
 
Example #14
Source File: JobExecuteFailExecutor.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
    ManagementService managementService = execution.getEngineServices().getManagementService();
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (job.getRetries() > 0) {
        throw new RuntimeException("本次作业执行失败,再次执行可以成功!");
    }
}
 
Example #15
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfiguration processEngineConfiguration, ManagementService managementService, long maxMillisToWait, long intervalMillis,
    boolean shutdownExecutorWhenFinished) {

  AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
  asyncExecutor.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);
        try {
          areJobsAvailable = areJobsAvailable(managementService);
        } catch (Throwable t) {
          // Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
          // isolation level doesn't allow READ of the table
        }
      }
    } catch (InterruptedException e) {
      // ignore
    } finally {
      timer.cancel();
    }
    if (areJobsAvailable) {
      throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
    }

  } finally {
    if (shutdownExecutorWhenFinished) {
      asyncExecutor.shutdown();
    }
  }
}
 
Example #16
Source File: JobExecuteFailExecutor.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
    ManagementService managementService = execution.getEngineServices().getManagementService();
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (job.getRetries() > 0) {
        throw new RuntimeException("本次作业执行失败,再次执行可以成功!");
    }
}
 
Example #17
Source File: JobExecuteFailExecutor.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
    ManagementService managementService = execution.getEngineServices().getManagementService();
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (job.getRetries() > 0) {
        throw new RuntimeException("本次作业执行失败,再次执行可以成功!");
    }
}
 
Example #18
Source File: ProxyProcessEngine.java    From lemon with Apache License 2.0 5 votes vote down vote up
public ManagementService getManagementService() {
    if (processEngine == null) {
        return null;
    }

    return processEngine.getManagementService();
}
 
Example #19
Source File: CustomMybatisMapperConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void executeCustomMybatisXmlQuery() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
    ManagementService managementService = applicationContext.getBean(ManagementService.class);
    String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {
        @Override
        public String execute(CommandContext commandContext) {
            return (String) commandContext.getDbSqlSession().selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
        }
    });
    Assert.assertNotNull("the processDefinitionDeploymentId should not be null!", processDefinitionDeploymentId);
}
 
Example #20
Source File: CustomMybatisMapperConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void executeCustomMybatisMapperQuery() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
    ManagementService managementService = applicationContext.getBean(ManagementService.class);
    String processDefinitionId = managementService.executeCustomSql(new AbstractCustomSqlExecution<CustomMybatisMapper, String>(CustomMybatisMapper.class) {
        @Override
        public String execute(CustomMybatisMapper customMybatisMapper) {
            return customMybatisMapper.loadProcessDefinitionIdByKey("waiter");
        }
    });
    Assert.assertNotNull("the processDefinitionId should not be null!", processDefinitionId);
}
 
Example #21
Source File: JobTestHelper.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public static void waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(ProcessEngineConfiguration processEngineConfiguration, ManagementService managementService, long maxMillisToWait, long intervalMillis) {
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(processEngineConfiguration, managementService, maxMillisToWait, intervalMillis, true);
}
 
Example #22
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setManagementService(ManagementService managementService) {
	this.managementService = managementService;
}
 
Example #23
Source File: ActivitiUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @return ManagementService
 */
public ManagementService getManagementService()
{
    return managementService;
}
 
Example #24
Source File: CustomTaskQuery.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public CustomTaskQuery(ManagementService managementService) {
    super(managementService);
}
 
Example #25
Source File: AttachmentQuery.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public AttachmentQuery(ManagementService managementService) {
    super(managementService);
}
 
Example #26
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ManagementService getManagementService() {
    return managementService;
}
 
Example #27
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public ProcessEngineConfigurationImpl setManagementService(ManagementService managementService) {
    this.managementService = managementService;
    return this;
}
 
Example #28
Source File: ProcessEngineImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ManagementService getManagementService() {
    return managementService;
}
 
Example #29
Source File: AbstractQuery.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public AbstractQuery(ManagementService managementService) {
    this(((ManagementServiceImpl) managementService).getCommandExecutor());
}
 
Example #30
Source File: ServiceSpringModuleConfig.java    From herd with Apache License 2.0 4 votes vote down vote up
@Bean
public ManagementService activitiManagementService(ProcessEngine activitiProcessEngine) throws Exception
{
    return activitiProcessEngine.getManagementService();
}