本文整理匯總了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);
}
}