当前位置: 首页>>代码示例>>Java>>正文


Java JobExecutionContext.setResult方法代码示例

本文整理汇总了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);
    
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:27,代码来源:NativeJob.java

示例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;
    }
}
 
开发者ID:farchanjo,项目名称:webcron,代码行数:15,代码来源:CommandLineJob.java

示例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);
    }
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:53,代码来源:MethodInvokeJob.java


注:本文中的org.quartz.JobExecutionContext.setResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。