本文整理汇总了Java中org.quartz.JobExecutionException类的典型用法代码示例。如果您正苦于以下问题:Java JobExecutionException类的具体用法?Java JobExecutionException怎么用?Java JobExecutionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JobExecutionException类属于org.quartz包,在下文中一共展示了JobExecutionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jobWasExecuted
import org.quartz.JobExecutionException; //导入依赖的package包/类
/**
* @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException)
*/
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
Trigger trigger = context.getTrigger();
Object[] args = null;
if (jobException != null) {
if (!getLog().isWarnEnabled()) {
return;
}
String errMsg = jobException.getMessage();
args =
new Object[] {
context.getJobDetail().getKey().getName(),
context.getJobDetail().getKey().getGroup(), new java.util.Date(),
trigger.getKey().getName(), trigger.getKey().getGroup(),
trigger.getPreviousFireTime(), trigger.getNextFireTime(),
Integer.valueOf(context.getRefireCount()), errMsg
};
getLog().warn(MessageFormat.format(getJobFailedMessage(), args), jobException);
} else {
if (!getLog().isInfoEnabled()) {
return;
}
String result = String.valueOf(context.getResult());
args =
new Object[] {
context.getJobDetail().getKey().getName(),
context.getJobDetail().getKey().getGroup(), new java.util.Date(),
trigger.getKey().getName(), trigger.getKey().getGroup(),
trigger.getPreviousFireTime(), trigger.getNextFireTime(),
Integer.valueOf(context.getRefireCount()), result
};
getLog().info(MessageFormat.format(getJobSuccessMessage(), args));
}
}
示例2: execute
import org.quartz.JobExecutionException; //导入依赖的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()));
}
}
示例3: execute
import org.quartz.JobExecutionException; //导入依赖的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);
}
}
示例4: jobWasExecuted
import org.quartz.JobExecutionException; //导入依赖的package包/类
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
Key sj = (Key) chainLinks.get(context.getJobDetail().getKey());
if(sj == null) {
return;
}
getLog().info("Job '" + context.getJobDetail().getFullName() + "' will now chain to Job '" + sj + "'");
try {
if(context.getJobDetail().isVolatile() || context.getTrigger().isVolatile()) {
context.getScheduler().triggerJobWithVolatileTrigger(sj.getName(), sj.getGroup());
} else {
context.getScheduler().triggerJob(sj.getName(), sj.getGroup());
}
} catch(SchedulerException se) {
getLog().error("Error encountered during chaining to Job '" + sj + "'", se);
}
}
示例5: throwAndFinish
import org.quartz.JobExecutionException; //导入依赖的package包/类
private void throwAndFinish(JobDataMap jobDataMap, JobExecutionContext context, Throwable t)
throws JobExecutionException {
context.put(Constants.JOB_EXCEPTION, t);
//reset retry param, just in case
jobDataMap.putAsString(NUMBER_OF_RETRIES_PARAM, 0);
JobExecutionException e = new JobExecutionException("This trigger has thrown a terminal exception. " +
"Retries exceeded or job not retryable", t);
throw e;
}
示例6: triggerRefire
import org.quartz.JobExecutionException; //导入依赖的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);
}
示例7: execute
import org.quartz.JobExecutionException; //导入依赖的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);
}
}
示例8: save
import org.quartz.JobExecutionException; //导入依赖的package包/类
/**
* @param context {@link JobExecutionContext}
* @param jobException {@link JobExecutionException}
*/
@Trace(metricName = "JobListener{save}", async = true, dispatcher = true)
private void save(JobExecutionContext context, JobExecutionException jobException) throws IOException {
JobResult jobResult = (JobResult) context.getResult();
ExecutionStatusEntity.ExecutionStatusEntityBuilder builder = ExecutionStatusEntity.builder();
builder.created(new Date());
builder.nextFireTime(context.getNextFireTime());
builder.fireTime(context.getFireTime());
builder.jobRunTime(context.getJobRunTime());
builder.prevFireTime(context.getPreviousFireTime());
builder.scheduledFireTime(context.getScheduledFireTime());
if (jobResult != null && jobResult.getTmpFile() != null) {
builder.output(FileUtils.readFileToString(jobResult.getTmpFile().toFile()));
builder.exitCode(jobResult.getExitValue());
if (jobResult.getExitValue() != 0)
builder.errors(true);
if (jobResult.getTmpFile().toFile().delete())
logger.debug(String.format("%s file deleted", jobResult.getTmpFile().toAbsolutePath()));
} else {
builder.output("No output");
builder.exitCode(-1);
builder.errors(true);
}
if (jobException != null) {
builder.errors(true);
builder.errorMessage(jobException.getMessage());
}
builder.job(getJob());
executionStatusRepository.save(builder.build());
}
示例9: execute
import org.quartz.JobExecutionException; //导入依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap jobData = context.getJobDetail().getJobDataMap();
// extract the content Cleanup to use
Object nodeCleanupWorkerObj = jobData.get("nodeCleanupWorker");
if (nodeCleanupWorkerObj == null || !(nodeCleanupWorkerObj instanceof NodeCleanupWorker))
{
throw new AlfrescoRuntimeException(
"NodeCleanupJob data must contain valid 'nodeCleanupWorker' reference");
}
NodeCleanupWorker nodeCleanupWorker = (NodeCleanupWorker) nodeCleanupWorkerObj;
List<String> cleanupLog = nodeCleanupWorker.doClean();
// Done
if (logger.isDebugEnabled())
{
logger.debug("Node cleanup log:");
for (String log : cleanupLog)
{
logger.debug(log);
}
}
}
示例10: executeInternal
import org.quartz.JobExecutionException; //导入依赖的package包/类
@Override
protected synchronized final void executeInternal(final JobExecutionContext jobContext)
throws JobExecutionException
{
if (locker == null)
{
JobLockService jobLockServiceBean = (JobLockService) jobContext.getJobDetail()
.getJobDataMap().get("jobLockService");
if (jobLockServiceBean == null)
throw new JobExecutionException("Missing setting for bean jobLockService");
String name = (String) jobContext.getJobDetail().getJobDataMap().get("name");
String jobName = name == null ? this.getClass().getSimpleName() : name;
locker = new ScheduledJobLockExecuter(jobLockServiceBean, jobName, this);
}
locker.execute(jobContext);
}
示例11: executeInternal
import org.quartz.JobExecutionException; //导入依赖的package包/类
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobKey key = jobExecutionContext.getJobDetail().getKey();
System.out.println("Cron Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName() + " ,Time now :"+new Date());
System.out.println("======================================");
System.out.println("Accessing annotation example: "+jobService.getAllJobs());
List<Map<String, Object>> list = jobService.getAllJobs();
System.out.println("Job list :"+list);
System.out.println("======================================");
//*********** For retrieving stored key-value pairs ***********/
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
String myValue = dataMap.getString("myKey");
System.out.println("Value:" + myValue);
System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}
示例12: execute
import org.quartz.JobExecutionException; //导入依赖的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.");
}
}
示例13: execute
import org.quartz.JobExecutionException; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
HistorianEntry entry = getInitialHistorianEntry(context);
try {
job.execute(context);
entry.setOutput(context.getResult());
entry.setRunStatus(ExecutionStatus.COMPLETED_SUCCESSFULLY);
} catch (Throwable t) {
entry.setException(t);
entry.setRunStatus(ExecutionStatus.COMPLETED_WITH_EXCEPTION);
throw t;
} finally {
entry.setEndTime(Instant.now(clock));
historianDAO.writeEntry(entry);
}
}
示例14: executeInternal
import org.quartz.JobExecutionException; //导入依赖的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");
}
}
示例15: execute
import org.quartz.JobExecutionException; //导入依赖的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 refer = applicationContext.getBean(targetObject);
refer.getClass().getDeclaredMethod(targetMethod).invoke(refer);
} else if (TaskType.dubbo.equals(taskType)) {
String system = jobDataMap.getString("targetSystem");
BaseProvider provider = (BaseProvider) DubboUtil.refer(applicationContext, system);
provider.execute(new Parameter(targetObject, targetMethod));
}
double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定时任务[{}.{}]用时:{}s", targetObject, targetMethod, time);
} catch (Exception e) {
throw new JobExecutionException(e);
}
}