Java Code Examples for org.quartz.JobExecutionContext#setResult()

The following examples show how to use org.quartz.JobExecutionContext#setResult() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AsuraFramework   File: NativeJob.java    License: Apache License 2.0 6 votes vote down vote up
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);
    
}
 
Example 2
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    context.setResult("this is the result");
}
 
Example 3
Source Project: quartz-web   File: MethodInvokeJob.java    License: Apache License 2.0 4 votes vote down vote up
@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);
    }
}
 
Example 4
Source Project: AsuraFramework   File: JMXInvokerJob.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
        Object[] params=null;
        String[] types=null;
        String objName = null;
        String objMethod = null;
        
        JobDataMap jobDataMap = context.getMergedJobDataMap();
        
        String[] keys = jobDataMap.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String value = jobDataMap.getString(keys[i]);
            if ("JMX_OBJECTNAME".equalsIgnoreCase(keys[i])) {
                objName = value;
            } else if ("JMX_METHOD".equalsIgnoreCase(keys[i])) {
                objMethod = value;
            } else if("JMX_PARAMDEFS".equalsIgnoreCase(keys[i])) {
                String[] paramdefs=split(value, ",");
                params=new Object[paramdefs.length];
                types=new String[paramdefs.length];
                for(int k=0;k<paramdefs.length;k++) {
                    String parts[]=  split(paramdefs[k], ":");
                    if (parts.length<2) {
                        throw new Exception("Invalid parameter definition: required parts missing "+paramdefs[k]);
                    }
                    switch(parts[0].charAt(0)) {
                        case 'i':
                            params[k]=new Integer(jobDataMap.getString(parts[1]));
                            types[k]=Integer.TYPE.getName();
                            break;
                        case 'I':
                            params[k]=new Integer(jobDataMap.getString(parts[1]));
                            types[k]=Integer.class.getName();
                            break;
                        case 'l':
                            params[k]=new Long(jobDataMap.getString(parts[1]));
                            types[k]=Long.TYPE.getName();
                            break;
                        case 'L':
                            params[k]=new Long(jobDataMap.getString(parts[1]));
                            types[k]=Long.class.getName();
                            break;
                        case 'f':
                            params[k]=new Float(jobDataMap.getString(parts[1]));
                            types[k]=Float.TYPE.getName();
                            break;
                        case 'F':
                            params[k]=new Float(jobDataMap.getString(parts[1]));
                            types[k]=Float.class.getName();
                            break;
                        case 'd':
                            params[k]=new Double(jobDataMap.getString(parts[1]));
                            types[k]=Double.TYPE.getName();
                            break;
                        case 'D':
                            params[k]=new Double(jobDataMap.getString(parts[1]));
                            types[k]=Double.class.getName();
                            break;
                        case 's':
                            params[k]=jobDataMap.getString(parts[1]);
                            types[k]=String.class.getName();
                            break;
                        case 'b':
                            params[k]=new Boolean(jobDataMap.getString(parts[1]));
                            types[k]=Boolean.TYPE.getName();
                            break;
                        case 'B':
                            params[k]=new Boolean(jobDataMap.getString(parts[1]));
                            types[k]=Boolean.class.getName();
                            break;
                    }
                }
            }
        }
        
        if (objName==null || objMethod==null) { 
            throw new Exception("Required parameters missing");
        }
        
        context.setResult(invoke(objName, objMethod, params, types));
    } catch (Exception e) {
        String m = "Caught a " + e.getClass().getName() + " exception : " + e.getMessage();
        getLog().error(m, e);
        throw new JobExecutionException(m, e, false);
    }
}
 
Example 5
Source Project: olat   File: SchedulerTestJob.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void executeWithDB(JobExecutionContext arg0) throws JobExecutionException {
    String testValueFromSchedulerTest = arg0.getMergedJobDataMap().getString("testValue");
    arg0.setResult(testValueFromSchedulerTest);
    System.out.println("SchedulerTestJob data: " + testValueFromSchedulerTest);
}
 
Example 6
Source Project: olat   File: SchedulerTestJob.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void executeWithDB(JobExecutionContext arg0) throws JobExecutionException {
    String testValueFromSchedulerTest = arg0.getMergedJobDataMap().getString("testValue");
    arg0.setResult(testValueFromSchedulerTest);
    System.out.println("SchedulerTestJob data: " + testValueFromSchedulerTest);
}