本文整理汇总了Java中org.activiti.engine.impl.jobexecutor.JobExecutor类的典型用法代码示例。如果您正苦于以下问题:Java JobExecutor类的具体用法?Java JobExecutor怎么用?Java JobExecutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JobExecutor类属于org.activiti.engine.impl.jobexecutor包,在下文中一共展示了JobExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: schedule
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void schedule(TimerEntity timer) {
Date duedate = timer.getDuedate();
if (duedate==null) {
throw new ActivitiException("duedate is null");
}
CommandContext commandContext = Context.getCommandContext();
commandContext
.getDbSqlSession()
.insert(timer);
// Check if this timer fires before the next time the job executor will check for new timers to fire.
// This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds)
// and timers are usually set further in the future
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
int waitTimeInMillis = jobExecutor.getWaitTimeInMillis();
if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime()+waitTimeInMillis)) {
// then notify the job executor.
commandContext
.getTransactionContext()
.addTransactionListener(TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
}
}
示例2: waitForJobExecutorToProcessAllJobs
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public static void waitForJobExecutorToProcessAllJobs(ProcessEngineConfigurationImpl processEngineConfiguration, 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(processEngineConfiguration);
}
} catch (InterruptedException e) {
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
jobExecutor.shutdown();
}
}
示例3: waitForJobExecutorToProcessAllJobs
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
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 ActivitiException("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
jobExecutor.shutdown();
}
}
示例4: execute
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public Object execute(CommandContext commandContext) {
JobEntity job = Context
.getCommandContext()
.getJobManager()
.findJobById(jobId);
job.setRetries(job.getRetries() - 1);
job.setLockOwner(null);
job.setLockExpirationTime(null);
if(exception != null) {
job.setExceptionMessage(exception.getMessage());
job.setExceptionStacktrace(getExceptionStacktrace());
}
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
TransactionContext transactionContext = commandContext.getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
return null;
}
示例5: schedule
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void schedule(TimerEntity timer) {
Date duedate = timer.getDuedate();
if (duedate==null) {
throw new ActivitiException("duedate is null");
}
CommandContext commandContext = Context.getCommandContext();
commandContext
.getDbSqlSession()
.insert(timer);
// Check if this timer fires before the next time the job executor will check for new timers to fire.
// This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds)
// and timers are usually set further in the future
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
int waitTimeInMillis = jobExecutor.getWaitTimeInMillis();
if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime()+waitTimeInMillis)) {
hintJobExecutor(timer);
}
}
示例6: schedule
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void schedule(TimerEntity timer) {
Date duedate = timer.getDuedate();
if (duedate==null) {
throw new ActivitiIllegalArgumentException("duedate is null");
}
timer.insert();
// Check if this timer fires before the next time the job executor will check for new timers to fire.
// This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds)
// and timers are usually set further in the future
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
int waitTimeInMillis = jobExecutor.getWaitTimeInMillis();
if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime()+waitTimeInMillis)) {
hintJobExecutor(timer);
}
}
示例7: execute
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public Object execute(CommandContext commandContext) {
JobEntity job = Context
.getCommandContext()
.getJobEntityManager()
.findJobById(jobId);
job.setRetries(job.getRetries() - 1);
job.setLockOwner(null);
job.setLockExpirationTime(null);
if(exception != null) {
job.setExceptionMessage(exception.getMessage());
job.setExceptionStacktrace(getExceptionStacktrace());
}
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
TransactionContext transactionContext = commandContext.getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
return null;
}
示例8: send
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void send(MessageEntity message) {
CommandContext commandContext = Context.getCommandContext();
commandContext
.getDbSqlSession()
.insert(message);
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
commandContext
.getTransactionContext()
.addTransactionListener(TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
}
示例9: run
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void run() {
try {
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
processEngineConfiguration
.getCommandExecutorTxRequired()
.execute(new ControlledCommand(activeThread, new AcquireJobsCmd(jobExecutor)));
} catch (ActivitiOptimisticLockingException e) {
this.exception = e;
}
log.fine(getName()+" ends");
}
示例10: testJobCommandsWithMessage
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void testJobCommandsWithMessage() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = createTweetMessage("i'm coding a test");
commandContext.getJobManager().send(message);
return message.getId();
}
});
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
List<List<String>> jobIdsList = acquiredJobs.getJobIdsList();
assertEquals(1, jobIdsList.size());
List<String> jobIds = jobIdsList.get(0);
List<String> expectedJobIds = new ArrayList<String>();
expectedJobIds.add(jobId);
assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteJobsCmd(jobId));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
示例11: testJobCommandsWithTimer
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void testJobCommandsWithTimer() {
// clock gets automatically reset in LogTestCase.runTest
ClockUtil.setCurrentTime(new Date(SOME_TIME));
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
commandContext.getJobManager().schedule(timer);
return timer.getId();
}
});
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
List<List<String>> jobIdsList = acquiredJobs.getJobIdsList();
assertEquals(0, jobIdsList.size());
List<String> expectedJobIds = new ArrayList<String>();
ClockUtil.setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
jobIdsList = acquiredJobs.getJobIdsList();
assertEquals(1, jobIdsList.size());
List<String> jobIds = jobIdsList.get(0);
expectedJobIds.add(jobId);
assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteJobsCmd(jobId));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
示例12: moveByMinutes
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
private void moveByMinutes(int minutes) throws Exception {
ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + ((minutes * 60 * 1000) + 5000)));
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
Thread.sleep(1000);
jobExecutor.shutdown();
}
示例13: moveByHours
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
private void moveByHours(int hours) throws Exception {
ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + ((hours * 60 * 1000 * 60) + 5000)));
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
Thread.sleep(1000);
jobExecutor.shutdown();
}
示例14: testJobCommandsWithMessage
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void testJobCommandsWithMessage() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = createTweetMessage("i'm coding a test");
commandContext.getJobManager().send(message);
return message.getId();
}
});
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
List<List<String>> jobIdsList = acquiredJobs.getJobIdBatches();
assertEquals(1, jobIdsList.size());
List<String> jobIds = jobIdsList.get(0);
List<String> expectedJobIds = new ArrayList<String>();
expectedJobIds.add(jobId);
assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteJobsCmd(jobId));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}
示例15: testJobCommandsWithTimer
import org.activiti.engine.impl.jobexecutor.JobExecutor; //导入依赖的package包/类
public void testJobCommandsWithTimer() {
// clock gets automatically reset in LogTestCase.runTest
ClockUtil.setCurrentTime(new Date(SOME_TIME));
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
commandContext.getJobManager().schedule(timer);
return timer.getId();
}
});
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
List<List<String>> jobIdsList = acquiredJobs.getJobIdBatches();
assertEquals(0, jobIdsList.size());
List<String> expectedJobIds = new ArrayList<String>();
ClockUtil.setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
jobIdsList = acquiredJobs.getJobIdBatches();
assertEquals(1, jobIdsList.size());
List<String> jobIds = jobIdsList.get(0);
expectedJobIds.add(jobId);
assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
assertEquals(0, tweetHandler.getMessages().size());
commandExecutor.execute(new ExecuteJobsCmd(jobId));
assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
assertEquals(1, tweetHandler.getMessages().size());
}