Package org.apache.synapse.task

Examples of org.apache.synapse.task.TaskDescription


        }
       
        if (el.getQName().equals(TASK)) {
           
            SimpleQuartz simpleQuartz = new SimpleQuartz();
            TaskDescription taskDescription =
                    TaskDescriptionFactory.createTaskDescription(el,
                            XMLConfigConstants.SYNAPSE_OMNAMESPACE);
            if (taskDescription == null) {
                handleException("Invalid task - Task description can not be created  from :" + el);
                return null;
            }         
            simpleQuartz.setName(taskDescription.getName());
            simpleQuartz.setTaskDescription(taskDescription);
            simpleQuartz.setDescription(taskDescription.getDescription());
            return simpleQuartz;
        } else {
            handleException("Syntax error in the task : wrong QName for the task");
            return null;
        }
View Full Code Here


                    "kind of startup" + s.getClass().getName());
        }

        SimpleQuartz sq = (SimpleQuartz) s;
       
        TaskDescription taskDescription = sq.getTaskDescription();

        if (taskDescription != null) {
            OMElement task = TaskDescriptionSerializer.serializeTaskDescription(
                    SynapseConstants.SYNAPSE_OMNAMESPACE, taskDescription);
            if (task == null) {
View Full Code Here

        Object[] functionParams = null;
        long frequency = 0;
        Date startTime = null;
        Date endTime = null;
        final Map<String, Object> resources = new HashMap<String, Object>();
        final TaskDescription taskDescription = new TaskDescription();
        final FunctionSchedulingManager functionSchedulingManager;

        taskDescription.setGroup(FunctionSchedulingJob.MASHUP_GROUP);
        taskDescription.setTaskClass(FunctionExecutionTask.class.getName());

        OMElement propElem = FACTORY.createOMElement("property", TASK_OM_NAMESPACE);
        OMNamespace nullNS = FACTORY.createOMNamespace("", "");
        propElem.addAttribute("name", "axisService", nullNS);
        propElem.addAttribute("value", axisService.getName(), nullNS);
        taskDescription.addProperty(propElem);

        resources.put(MashupConstants.AXIS2_CONFIGURATION_CONTEXT, configurationContext);


        switch (argCount) {

            case 2://A javascript function and its execution frequency were passed

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must be " +
                                              "a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException("Invalid parameter. The second parameter " +
                                              "must be the execution frequency in milliseconds.");
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                break;

            case 3://A javascript function its execution frequency and parameters were passed

                //Extracting the javascript function from the arguments=
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must " +
                                              "be a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the " +
                            "execution frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {

                    if (arguments[2] instanceof NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);

                    } else if (arguments[2] instanceof String) {
                        taskName = (String) arguments[2];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array " +
                                "of parameters to the argument, a string value for the task name or null.");
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                break;

            case 4:// A javascript function, its execution frequnecy, function parameters and a start time is passed.

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The first parameter must be a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the execution " +
                            "frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {
                    if (arguments[2] instanceof NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                if (arguments[3] != null) {
                    if (arguments[3] instanceof String) {
                        taskName = (String) arguments[3];
                    } else {
                        try {
                            startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fourth parameter must be " +
                                    "the start time in date format or a string value " +
                                    "for the task name.", e);
                        }
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);

                break;

            case 5: // A javascript function, its execution frequnecy, function parameters, start time and an end time is passed.

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must be a " +
                                              "JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the execution " +
                            "frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {
                    if (arguments[2] instanceof NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                //Extracting the start time from the arguments
                if (arguments[3] != null) {
                    if (arguments[3] instanceof String) {
                        taskName = (String) arguments[3];
                    } else {
                        try {
                            startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fourth parameter must be " +
                                    "the start time in date format.", e);
                        }
                    }
                }

                //Extracting the end time from the arguments
                if (arguments[4] != null) {
                    if (arguments[4] instanceof String) {
                        taskName = (String) arguments[4];
                    } else {
                        try {
                            endTime = (Date) Context.jsToJava(arguments[4], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fifth parameter must be " +
                                    "the end time in date format or a string value " +
                                    "for the task name.", e);
                        }
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);
                taskDescription.setEndTime(endTime);

                break;

            case 6: // A javascript function, its execution frequnecy, function parameters, start time and an end time is passed.

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must be a " +
                                              "JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the execution " +
                            "frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {
                    if (arguments[2] instanceof NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                //Extracting the start time from the arguments
                if (arguments[3] != null) {
                    try {
                        startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                    } catch (EvaluatorException e) {
                        throw new CarbonException(
                                "Invalid parameter. The fourth parameter must be " +
                                "the start time in date format.", e);
                    }
                }

                if (arguments[4] != null) {
                    try {
                        endTime = (Date) Context.jsToJava(arguments[4], Date.class);
                    } catch (EvaluatorException e) {
                        throw new CarbonException(
                                "Invalid parameter. The fifth parameter must be " +
                                "the end time in date format.", e);
                    }
                }

                if (arguments[5] != null) {
                    if (arguments[5] instanceof String) {
                        taskName = (String) arguments[5];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The sixth parameter must be a string value " +
                                "for the task name");
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);
                taskDescription.setEndTime(endTime);

                break;

            default:
                throw new CarbonException("Invalid number of parameters.");
View Full Code Here

        Object jsFunction = null;
        Object[] functionParams = null;
        long timeout = 0;
        Date currentTime = new Date();
        final Map<String, Object> resources = new HashMap<String, Object>();
        final TaskDescription taskDescription = new TaskDescription();
        final FunctionSchedulingManager functionSchedulingManager;

        taskDescription.setGroup(FunctionSchedulingJob.MASHUP_GROUP);
        taskDescription.setTaskClass(FunctionExecutionTask.class.getName());

        OMElement propElem = FACTORY.createOMElement("property", TASK_OM_NAMESPACE);
        OMNamespace nullNS = FACTORY.createOMNamespace("", "");
        propElem.addAttribute("name", "axisService", nullNS);
        propElem.addAttribute("value", axisService.getName(), nullNS);
        taskDescription.addProperty(propElem);

        resources.put(MashupConstants.AXIS2_CONFIGURATION_CONTEXT, configurationContext);

        switch (argCount) {

            case 2://A javascript function and its timeout were passed

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must be " +
                                              "a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    timeout = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException("Invalid parameter. The second parameter " +
                                              "must be function starting timeout.");
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(1);
                taskDescription.setStartTime(new Date(currentTime.getTime() + timeout));
                break;

            case 3://A javascript function its execution frequency and parameters were passed

                //Extracting the javascript function from the arguments=
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must " +
                                              "be a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    timeout = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the " +
                            "execution frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {

                    if (arguments[2] instanceof String) {
                        taskName = (String) arguments[2];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be a string " +
                                "value for the  the task name");
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(1);
                taskDescription.setStartTime(new Date(currentTime.getTime() + timeout));
                break;

            default:
                throw new CarbonException("Invalid number of parameters.");
        }
View Full Code Here

    public TaskDescription getTaskDescription(String name, ConfigurationContext configCtx) {

        if (log.isDebugEnabled()) {
            log.debug("Returning a Startup : " + name + " from the configuration");
        }
        TaskDescription taskDescription = getTaskDescriptionRepository(configCtx).getTaskDescription(name);
        if (taskDescription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Returning a TaskDescription : " + taskDescription);

            }
View Full Code Here

    }

    // delete the task, i.e. TaskDescription and JobDataMap are deleted
    public void deleteTask(String name, ConfigurationContext configCtx) {

        TaskDescription taskDescription = getTaskDescriptionRepository(configCtx).getTaskDescription(name);
        Set<OMElement> properties = taskDescription.getProperties();
        Iterator<OMElement> iterator = properties.iterator();
        String serviceName = null;

        while (iterator.hasNext()) {
            Object property = iterator.next();
            if (property instanceof OMElement) {
                OMElement element = (OMElement) property;

                if (element.getAttributeValue(new QName("name")).equals(FunctionSchedulingJob.AXIS_SERVICE)) {
                    serviceName = element.getAttributeValue(new QName("value"));
                }
            }
        }

        getTaskDescriptionRepository(configCtx).removeTaskDescription(name);
        getTaskScheduler(configCtx).deleteTask(name, taskDescription.getGroup());

        if (serviceName != null) {

            AxisService axisService = null;
            try {
View Full Code Here

        }
    }

    // delete only the TaskDescrition, this is used when re-scheduling via admin UI
    public void deleteTaskDescription(String name, ConfigurationContext configCtx) {
        TaskDescription taskDescription = getTaskDescriptionRepository(configCtx).getTaskDescription(name);

        if (taskDescription != null) {
            getTaskDescriptionRepository(configCtx).removeTaskDescription(name);
            getTaskScheduler(configCtx).deleteTask(name, taskDescription.getGroup());
        } else {
            log.warn("Cannot delete the Task " + name
                    + ", it doesn't exists in the Repository");
        }
View Full Code Here

            String taskName, ConfigurationContext configurationContext) {
        if (log.isDebugEnabled()) {
            log.debug("Returning a Start up : " + taskName + " from the configuration");
        }

        TaskDescription taskDescription = getTaskDescriptionRepository(
                configurationContext).getTaskDescription(taskName);

        if (taskDescription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Returning a Task Description : " + taskDescription);
View Full Code Here

     *
     * @param taskName             taskName
     * @param configurationContext ConfigurationContext
     */
    public void deleteTaskDescription(String taskName, String taskGroup, ConfigurationContext configurationContext) {
        TaskDescription taskDescription = getTaskDescriptionRepository(
                configurationContext).getTaskDescription(taskName);

        if (taskDescription != null) {
            getTaskDescriptionRepository(configurationContext).removeTaskDescription(taskName);
            getTaskScheduler(configurationContext).deleteTask(taskName, taskGroup);
View Full Code Here

            TaskManagementException, XMLStreamException {
        OMElement taskElement = AXIOMUtil.stringToOM(taskElementString);
        if (log.isDebugEnabled()) {
            log.debug("Add TaskDescription - Get a Task configuration  :" + taskElement);
        }
        TaskDescription taskDescription = validateAndCreate(taskElement);
        jobDataMap = new HashMap<String, Object>();
        jobDataMap.put(TaskSchedulerConstants.DATA_SERVICE_NAME, serviceName);
        jobDataMap.put(TaskSchedulerConstants.OPERATION_NAME, operationName);
        jobDataMap.put(TaskSchedulerConstants.BACK_END_URL, backendServerUrl);
        jobDataMap.put(TaskSchedulerConstants.CONFIGURATION_CONTEXT, this.getConfigContext());

        try {
            addTaskDescription(taskDescription);
        } catch (Exception e) {
            try {
                getTaskManager().deleteTaskDescription(taskDescription.getName(),
                        taskDescription.getGroup());
            } catch (Exception ignored) {
            }
            handleException("Error creating a task : " + e.getMessage(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.task.TaskDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.