本文整理汇总了Java中org.quartz.JobExecutionContext.setResult方法的典型用法代码示例。如果您正苦于以下问题:Java JobExecutionContext.setResult方法的具体用法?Java JobExecutionContext.setResult怎么用?Java JobExecutionContext.setResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.JobExecutionContext
的用法示例。
在下文中一共展示了JobExecutionContext.setResult方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
public void execute(JobExecutionContext context)
throws JobExecutionException {
JobDataMap data = context.getMergedJobDataMap();
String command = data.getString(PROP_COMMAND);
String parameters = data.getString(PROP_PARAMETERS);
if (parameters == null) {
parameters = "";
}
boolean wait = true;
if(data.containsKey(PROP_WAIT_FOR_PROCESS)) {
wait = data.getBooleanValue(PROP_WAIT_FOR_PROCESS);
}
boolean consumeStreams = false;
if(data.containsKey(PROP_CONSUME_STREAMS)) {
consumeStreams = data.getBooleanValue(PROP_CONSUME_STREAMS);
}
Integer exitCode = this.runNativeCommand(command, parameters, wait, consumeStreams);
context.setResult(exitCode);
}
示例2: runCommand
import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
private void runCommand(JobExecutionContext context) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder();
setEnvironments(pb);
Path output = setOutputs(pb);
pb.command(getCommand(getJob().getCommand()));
try {
Process process = pb.start();
int exitCode = process.waitFor();
context.setResult(JobResult.builder().exitValue(exitCode).tmpFile(output).build());
} catch (Exception e) {
output.toFile().delete();
throw e;
}
}
示例3: execute
import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Date startDate = new Date();
LOG.debug("methodInvokeJob start : " + DateUtils.formart(startDate));
long startTime = startDate.getTime();
JobDataMap jobDataMap = context.getMergedJobDataMap();
//Object methodInvokerObj = jobDataMap.get("methodInvoker");
Object jobClassObj = jobDataMap.get("jobClass");
Object constructorArgumentsObj = jobDataMap.get("constructorArguments");
Object jobClassMethodNameObj = jobDataMap.get("jobClassMethodName");
Object jobClassMethodArgsObj = jobDataMap.get("jobClassMethodArgs");
try {
String jobClass = (String) jobClassObj;
Object[] constructorArguments = (Object[]) constructorArgumentsObj;
String jobClassMethodName = (String) jobClassMethodNameObj;
Object[] jobClassMethodArgs = (Object[]) jobClassMethodArgsObj;
Object jobBean;
LOG.debug("methodInvokeJob jobClass:" + jobClass);
LOG.debug("methodInvokeJob jobClassMethodName:" + jobClassMethodName);
QuartzBeanManagerFacade quartzBeanManagerFacade = QuartzBeanManagerFacade.getInstance();
if (constructorArguments != null && constructorArguments.length > 0) {
jobBean = quartzBeanManagerFacade.getBean(jobClass, constructorArguments);
} else {
jobBean = quartzBeanManagerFacade.getBean(jobClass);
}
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetMethod(jobClassMethodName);
methodInvoker.setArguments(jobClassMethodArgs);
methodInvoker.setTargetObject(jobBean);
boolean prepared = methodInvoker.isPrepared();
if (!prepared) {
methodInvoker.prepare();
}
Object result = methodInvoker.invoke();
context.setResult(result);
Date endDate = new Date();
long endTime = endDate.getTime();
LOG.debug("methodInvokeJob end : " + DateUtils.formart(endDate) + "," + (endTime - startTime));
} catch (Exception e) {
LOG.error("MethodInvokeJob exception message:" + e.getMessage(), e);
e.printStackTrace();
throw new JobExecutionException(e);
}
}