本文整理汇总了Java中org.quartz.JobExecutionContext类的典型用法代码示例。如果您正苦于以下问题:Java JobExecutionContext类的具体用法?Java JobExecutionContext怎么用?Java JobExecutionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JobExecutionContext类属于org.quartz包,在下文中一共展示了JobExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRunningJobList
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public List<ScheduleJobEntity> getRunningJobList() {
List<ScheduleJobEntity> jobList = null;
Scheduler scheduler = schedulerFactoryBean.getScheduler();
try {
List<JobExecutionContext> executingJobList = scheduler.getCurrentlyExecutingJobs();
jobList = new ArrayList<>(executingJobList.size());
for (JobExecutionContext executingJob : executingJobList) {
ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
this.wrapScheduleJob(scheduleJob, scheduler, jobKey, trigger);
jobList.add(scheduleJob);
}
} catch (Exception e) {
logger.error("获取计划任务列表失败", e);
throw new ServiceException("获取计划任务列表失败", e);
}
return jobList;
}
示例2: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDOExample jobDOExample = new JobDOExample();
jobDOExample.setLimit(querySupportPageSize());
JobDOExample.Criteria criteria = jobDOExample.createCriteria();
/* 查出非DONE 的job*/
criteria.andOwnSignEqualTo(CoreModule.getInstance().getOwnSign()).andStatusNotEqualTo(
JobConstant.JOB_STATUS_DONE);
try {
handle(jobDOExample);
} catch (Exception e) {
logger.error("清理流程和节点逻辑出现异常!e=" + e.getMessage());
}
}
示例3: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("AsuraJob。。。" + new Date());
boolean flag = true;
if (flag) {
return;
} else {
run(flag);
}
}
示例4: interrupt
import org.quartz.JobExecutionContext; //导入依赖的package包/类
/**
* Interrupt the identified InterruptableJob executing in this Scheduler instance.
*
* <p>
* This method is not cluster aware. That is, it will only interrupt
* instances of the identified InterruptableJob currently executing in this
* Scheduler instance, not across the entire cluster.
* </p>
*
* @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
*/
public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobException {
List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
Job job = null;
for(JobExecutionContext jec : jobs) {
if (jec.getFireInstanceId().equals(fireInstanceId)) {
job = jec.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob)job).interrupt();
return true;
} else {
throw new UnableToInterruptJobException(
"Job " + jec.getJobDetail().getKey() +
" can not be interrupted, since it does not implement " +
InterruptableJob.class.getName());
}
}
}
return false;
}
示例5: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
ShardingContexts shardingContexts = jobFacade.getShardingContexts();
int jobEventSamplingCount = shardingContexts.getJobEventSamplingCount();
int currentJobEventSamplingCount = shardingContexts.getCurrentJobEventSamplingCount();
if (jobEventSamplingCount > 0 && ++currentJobEventSamplingCount < jobEventSamplingCount) {
shardingContexts.setCurrentJobEventSamplingCount(currentJobEventSamplingCount);
jobFacade.getShardingContexts().setAllowSendJobEvent(false);
JobExecutorFactory.getJobExecutor(elasticJob, jobFacade).execute();
} else {
jobFacade.getShardingContexts().setAllowSendJobEvent(true);
executorDriver.sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskId).setState(Protos.TaskState.TASK_RUNNING).setMessage("BEGIN").build());
JobExecutorFactory.getJobExecutor(elasticJob, jobFacade).execute();
executorDriver.sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskId).setState(Protos.TaskState.TASK_RUNNING).setMessage("COMPLETE").build());
shardingContexts.setCurrentJobEventSamplingCount(0);
}
}
示例6: notifyJobListenersComplete
import org.quartz.JobExecutionContext; //导入依赖的package包/类
private boolean notifyJobListenersComplete(JobExecutionContext jec,
JobExecutionException jobExEx) {
try {
qs.notifyJobListenersWasExecuted(jec, jobExEx);
} catch (SchedulerException se) {
qs.notifySchedulerListenersError(
"Unable to notify JobListener(s) of Job that was executed: "
+ "(error will be ignored). trigger= "
+ jec.getTrigger().getFullName() + " job= "
+ jec.getJobDetail().getFullName(), se);
return false;
}
return true;
}
示例7: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
/**
* Called when the job is executed by quartz. This method delegates to the <tt>validateSessions()</tt> method on the
* associated session manager.
*
* @param context
* the Quartz job execution context for this execution.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
ValidatingSessionManager sessionManager = (ValidatingSessionManager) jobDataMap.get(SESSION_MANAGER_KEY);
if (log.isDebugEnabled()) {
log.debug("Executing session validation Quartz job...");
}
sessionManager.validateSessions();
if (log.isDebugEnabled()) {
log.debug("Session validation Quartz job complete.");
}
}
示例8: executeInternal
import org.quartz.JobExecutionContext; //导入依赖的package包/类
/**
* @see org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org.quartz.JobExecutionContext)
*/
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
IMonitoringService monitoringService = getMonitoringService(context);
//getting gate id set from scheduler
Map properties = context.getJobDetail().getJobDataMap();
Long gateId = (Long) properties.get("gateId");
if (log.isDebugEnabled()) {
log.debug("Closing gate......[" + gateId.longValue() + "]");
}
monitoringService.closeGate(gateId);
if (log.isDebugEnabled()) {
log.debug("Gate......[" + gateId.longValue() + "] Closed");
}
}
示例9: triggerRefire
import org.quartz.JobExecutionContext; //导入依赖的package包/类
private void triggerRefire(JobDataMap jobDataMap, int numberOfRetries, JobExecutionContext context, Throwable t)
throws JobExecutionException {
final long sleepTimeBetweenRetries = jobDataMap.containsKey(SLEEP_TIME_BETWEEN_RETRIES_PARAM) ?
jobDataMap.getLongValue(SLEEP_TIME_BETWEEN_RETRIES_PARAM) : DEFAULT_SLEEP_TIME_BETWEEN_RETRIES;
try {
Thread.sleep(sleepTimeBetweenRetries);
} catch (InterruptedException e) {}
context.put(Constants.JOB_EXCEPTION, t);
jobDataMap.putAsString(NUMBER_OF_RETRIES_PARAM, --numberOfRetries);
//set refire flag as true
throw new JobExecutionException(t, true);
}
示例10: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void execute(JobExecutionContext job) throws JobExecutionException {
TriggerScheduleServiceCenterToProviderServiceCenterMessage msg = new TriggerScheduleServiceCenterToProviderServiceCenterMessage();
String jobName = job.getJobDetail().getKey().getName();
JobDataMap jobDataMap = job.getJobDetail().getJobDataMap();
ConcurrentHashMap<Integer, ServiceXServerSession> rpcServers = (ConcurrentHashMap<Integer, ServiceXServerSession>) jobDataMap
.get(RPCSERVERS);
ConcurrentHashMap<String, ConcurrentHashSet<Integer>> schedules = (ConcurrentHashMap<String, ConcurrentHashSet<Integer>>) jobDataMap
.get(SCHEDULES);
ConcurrentHashSet<Integer> providerList = schedules.get(jobName);
if (providerList == null) {
log.error("Job:" + jobName + "找不到Provider");
return;
}
msg.setJobName(jobName);
// 查看是否是最有一次执行,并且移除此job
if (!job.getTrigger().mayFireAgain()) {
msg.setEnd(true);
schedules.remove(jobName);
log.info("任务生命终结,执行删除:" + jobName);
}
// 选举式触发
ArrayList<Integer> arrayList = new ArrayList<>(providerList);
int providerId = arrayList.get(RandomUtil.randomInt(0, arrayList.size() - 1));
ServiceXServerSession serviceXServerSession = rpcServers.get(providerId);
if (serviceXServerSession != null) {
serviceXServerSession.getSession().writeAndFlush(msg);
log.info(jobName + "触发!分配的ProviderId为:" + providerId + ",下次触发时间:"
+ TimeUtil.date2Str(job.getTrigger().getNextFireTime().getTime()));
}
}
示例11: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
long start = System.currentTimeMillis();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String taskType = jobDataMap.getString("taskType");
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
logger.info("定时任务开始执行: [{}.{}]", targetObject, targetMethod);
try {
ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
.get("applicationContext");
if (TaskType.local.equals(taskType)) {
Object object = applicationContext.getBean(targetObject);
MethodAccess methodAccess = MethodAccess.get(object.getClass());
methodAccess.invoke(object, targetMethod);
} else if (TaskType.dubbo.equals(taskType)) {
// Object object = DubboUtil.refer(applicationContext, targetObject);
// MethodAccess methodAccess = MethodAccess.get(object.getClass());
// methodAccess.invoke(object, targetMethod);
}
double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定时任务[{}.{}]用时:{}s", targetObject, targetMethod, time);
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例12: notifyJobListenersWasExecuted
import org.quartz.JobExecutionContext; //导入依赖的package包/类
public void notifyJobListenersWasExecuted(JobExecutionContext jec,
JobExecutionException je) throws SchedulerException {
// build a list of all job listeners that are to be notified...
List jobListeners = buildJobListenerList(jec.getJobDetail()
.getJobListenerNames());
// notify all job listeners
java.util.Iterator itr = jobListeners.iterator();
while (itr.hasNext()) {
JobListener jl = (JobListener) itr.next();
try {
jl.jobWasExecuted(jec, je);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
"JobListener '" + jl.getName() + "' threw exception: "
+ e.getMessage(), e);
se.setErrorCode(SchedulerException.ERR_JOB_LISTENER);
throw se;
}
}
}
示例13: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
/**
* Calls the cleaner to do its work
*/
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap jobData = context.getJobDetail().getJobDataMap();
// extract the content cleaner to use
Object sharedFolderPatchObj = jobData.get("sharedFolderPatch");
if (sharedFolderPatchObj == null || !(sharedFolderPatchObj instanceof SharedFolderPatch))
{
throw new AlfrescoRuntimeException(
"'sharedFolderPatch' data must contain valid 'SharedFolderPatch' reference");
}
// Job Lock Here - should probably move into the patch service at some time.
SharedFolderPatch sharedFolderPatch = (SharedFolderPatch) sharedFolderPatchObj;
sharedFolderPatch.executeAsync();
}
示例14: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
EventSchedulerJobParameters parameters =
(EventSchedulerJobParameters) context.getJobDetail().getJobDataMap().get(KEY_PARAMETERS);
// Add the event (or its clone if necessary) to the queue immediately.
parameters.getScheduler().scheduleNow(parameters.isSingle() ? parameters.getEvent() : parameters.getEvent().clone());
} catch (Throwable e) {
// Throw only JobExecutionException
if (e instanceof JobExecutionException) {
throw e;
} else {
throw new JobExecutionException(e);
}
}
}
示例15: execute
import org.quartz.JobExecutionContext; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
ApiFactoryService apiFactoryService = (ApiFactoryService) context.get(ApiFactoryService.class.getName());
try {
EntityManager em = HibernateUtil.getTransactionalEntityManager();
List<DistributedAppliance> das = HibernateUtil.getTransactionControl().required(() -> {
OSCEntityManager<DistributedAppliance> emgr = new OSCEntityManager<DistributedAppliance>(
DistributedAppliance.class, em, StaticRegistry.transactionalBroadcastUtil());
return emgr.listAll();
});
for (DistributedAppliance da : das) {
for (VirtualSystem vs : da.getVirtualSystems()) {
ApplianceManagerConnector apmc = vs.getDistributedAppliance().getApplianceManagerConnector();
ManagerDeviceMemberApi agentApi = apiFactoryService.createManagerDeviceMemberApi(apmc, vs);
if (apiFactoryService.providesDeviceStatus(vs)) {
List<ManagerDeviceMemberStatusElement> agentElems = agentApi.getFullStatus(
vs.getDistributedApplianceInstances().stream()
.map(DistributedApplianceInstanceElementImpl::new)
.collect(Collectors.toList()));
for (DistributedApplianceInstance dai : vs.getDistributedApplianceInstances()) {
getAgentFullStatus(dai, agentElems);
}
}
}
}
} catch (Exception ex) {
log.error("Fail to sync DAs", ex);
}
}