Package org.quartz

Examples of org.quartz.JobDataMap


        // Make the name unique - we may already have our cron job schedules.
        // What happens if this is triggered when our cron job is triggered? the job will abort and let the current job finish
        JobDetail job = new JobDetail(ContentProviderSyncJob.createUniqueJobName(contentSource),
            CONTENT_SRC_SYNC_JOB_GROUP_NAME, ContentProviderSyncJob.class, false, false, false);

        JobDataMap jobDataMap = ContentProviderSyncJob.createJobDataMap(contentSource, job);
        jobDataMap.putAsString(ContentProviderSyncJob.DATAMAP_SYNC_IMPORTED_REPOS, true);

        SimpleTrigger trigger = new SimpleTrigger(job.getName(), job.getGroup());
        trigger.setVolatility(false);

        SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
View Full Code Here


            final String randomSuffix = UUID.randomUUID().toString();

            final String triggerName = TRIGGER_PREFIX + " - " + randomSuffix;
            SimpleTrigger trigger = new SimpleTrigger(triggerName, DEFAULT_JOB_GROUP, new Date());

            JobDataMap jobDataMap = new JobDataMap();
            jobDataMap.put(AgentRequestFullAvailabilityJob.KEY_TRIGGER_NAME, triggerName);
            jobDataMap.put(AgentRequestFullAvailabilityJob.KEY_TRIGGER_GROUP_NAME, DEFAULT_JOB_GROUP);
            AgentRequestFullAvailabilityJob.externalizeJobValues(jobDataMap, AgentRequestFullAvailabilityJob.AGENTS,
                agents);

            trigger.setJobName(DEFAULT_JOB_NAME);
            trigger.setJobGroup(DEFAULT_JOB_GROUP);
View Full Code Here

     * @see ScheduledJob#execute(String, Properties)
     */
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.debug("scheduled server plugin job triggered");

        JobDataMap dataMap = context.getJobDetail().getJobDataMap();

        // obtain our internal values that we need from the datamap
        String pluginName = dataMap.getString(DATAMAP_PLUGIN_NAME);
        String pluginTypeString = dataMap.getString(DATAMAP_PLUGIN_TYPE);
        String jobId = dataMap.getString(DATAMAP_JOB_ID);
        String jobClass = dataMap.getString(DATAMAP_JOB_CLASS);
        String jobMethodName = dataMap.getString(DATAMAP_JOB_METHOD_NAME);
        boolean isConcurrent = Boolean.parseBoolean(dataMap.getString(DATAMAP_IS_CONCURRENT));
        boolean isClustered = Boolean.parseBoolean(dataMap.getString(DATAMAP_IS_CLUSTERED));
        String scheduleTypeStr = dataMap.getString(DATAMAP_SCHEDULE_TYPE);
        String scheduleTrigger = dataMap.getString(DATAMAP_SCHEDULE_TRIGGER);

        // verify the datamap has all the things we require
        if (pluginName == null) {
            throwJobExecutionException(pluginName, pluginTypeString, jobId, "Datamap missing plugin name", null);
        }
        if (pluginTypeString == null) {
            throwJobExecutionException(pluginName, pluginTypeString, jobId, "Datamap missing plugin type", null);
        }
        if (jobId == null) {
            throwJobExecutionException(pluginName, pluginTypeString, jobId, "Datamap missing job ID", null);
        }
        if (jobMethodName == null) {
            throwJobExecutionException(pluginName, pluginTypeString, jobId, "Datamap missing method name", null);
        }

        // obtain the plugin's own callback data from the datamap
        Properties callbackData = new Properties();
        for (String key : dataMap.getKeys()) {
            if (!key.startsWith(DATAMAP_LEADER)) {
                callbackData.setProperty(key, dataMap.getString(key));
            }
        }

        // determine what type of plugin is being triggered
        ServerPluginType pluginType = null;
View Full Code Here

        OperationDefinition opDef = validateOperationNameAndParameters(resource.getResourceType(), operationName,
            parameters);

        String uniqueJobId = createUniqueJobName(resource, operationName);

        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put(OperationJob.DATAMAP_STRING_OPERATION_NAME, operationName);
        putDisplayName(jobDataMap, resource.getResourceType().getId(), operationName);

        if (parameters != null) {
            if (parameters.getId() == 0) {
                entityManager.persist(parameters);
            }

            jobDataMap.putAsString(OperationJob.DATAMAP_INT_PARAMETERS_ID, parameters.getId());
        }

        jobDataMap.putAsString(OperationJob.DATAMAP_INT_SUBJECT_ID, subject.getId());
        jobDataMap.putAsString(ResourceOperationJob.DATAMAP_INT_RESOURCE_ID, resource.getId());
        jobDataMap.put("description", notes);

        JobDetail jobDetail = new JobDetail();
        jobDetail.setName(uniqueJobId);
        String jobGroupName = createJobGroupName(resource);
        jobDetail.setGroup(jobGroupName);
        jobDetail.setDescription(notes);
        jobDetail.setVolatility(false); // we want it persisted
        jobDetail.setDurability(false);
        jobDetail.setRequestsRecovery(false);
        jobDetail.setJobClass(ResourceOperationJob.class);
        jobDetail.setJobDataMap(jobDataMap);

        trigger.setName(jobDetail.getName());
        trigger.setGroup(jobDetail.getGroup());
        trigger.setJobName(jobDetail.getName());
        trigger.setJobGroup(jobDetail.getGroup());

        // We need to create our own schedule tracking entity.
        ResourceOperationScheduleEntity schedule;
        schedule = new ResourceOperationScheduleEntity(jobDetail.getName(), jobDetail.getGroup(),
            trigger.getStartTime(), resource);
        entityManager.persist(schedule);

        // Add the id of the entity bean, so we can easily map the Quartz job to the associated entity bean.
        jobDataMap.put(OperationJob.DATAMAP_INT_ENTITY_ID, String.valueOf(schedule.getId()));

        // Create an IN_PROGRESS item
        // - we need a copy of parameters to avoid constraint violations upon delete
        ResourceOperationHistory history;
        history = new ResourceOperationHistory(uniqueJobId, jobGroupName, subject.getName(), opDef,
View Full Code Here

        ensureControlPermission(subject, group);

        validateOperationNameAndParameters(group.getResourceType(), operationName, parameters);

        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put(OperationJob.DATAMAP_STRING_OPERATION_NAME, operationName);
        putDisplayName(jobDataMap, group.getResourceType().getId(), operationName);

        if (parameters != null) {
            if (parameters.getId() == 0) {
                entityManager.persist(parameters);
            }

            jobDataMap.putAsString(OperationJob.DATAMAP_INT_PARAMETERS_ID, parameters.getId());
        }

        jobDataMap.putAsString(OperationJob.DATAMAP_INT_SUBJECT_ID, subject.getId());
        jobDataMap.putAsString(GroupOperationJob.DATAMAP_INT_GROUP_ID, group.getId());
        jobDataMap.putAsString(GroupOperationJob.DATAMAP_BOOL_HALT_ON_FAILURE, haltOnFailure);

        if ((executionOrderResourceIds != null) && (executionOrderResourceIds.length > 0)) {
            StringBuilder orderString = new StringBuilder();
            orderString.append(executionOrderResourceIds[0]);
            for (int i = 1; i < executionOrderResourceIds.length; i++) {
                orderString.append(',');
                orderString.append(executionOrderResourceIds[i]);
            }

            jobDataMap.put(GroupOperationJob.DATAMAP_INT_ARRAY_EXECUTION_ORDER, orderString.toString());
        }

        JobDetail jobDetail = new JobDetail();
        jobDetail.setName(createUniqueJobName(group, operationName));
        jobDetail.setGroup(createJobGroupName(group));
        jobDetail.setDescription(notes);
        jobDetail.setVolatility(false); // we want it persisted
        jobDetail.setDurability(false);
        jobDetail.setRequestsRecovery(false);
        jobDetail.setJobClass(GroupOperationJob.class);
        jobDetail.setJobDataMap(jobDataMap);

        trigger.setName(jobDetail.getName());
        trigger.setGroup(jobDetail.getGroup());
        trigger.setJobName(jobDetail.getName());
        trigger.setJobGroup(jobDetail.getGroup());

        // we need to create our own schedule tracking entity
        GroupOperationScheduleEntity schedule;
        schedule = new GroupOperationScheduleEntity(jobDetail.getName(), jobDetail.getGroup(), trigger.getStartTime(),
            group);
        entityManager.persist(schedule);

        // Add the id of the entity bean, so we can easily map the Quartz job to the associated entity bean.
        jobDataMap.put(OperationJob.DATAMAP_INT_ENTITY_ID, String.valueOf(schedule.getId()));

        // now actually schedule it
        Date next = scheduler.scheduleJob(jobDetail, trigger);
        GroupOperationSchedule newSchedule = getGroupOperationSchedule(subject, jobDetail);
View Full Code Here

        // if the jobDetail is null assume the job is no longer scheduled
        if (null == jobDetail) {
            return null;
        }

        JobDataMap jobDataMap = jobDetail.getJobDataMap();

        String jobName = jobDetail.getName();
        String jobGroup = jobDetail.getGroup();
        String description = jobDataMap.getString("description");
        String operationName = jobDataMap.getString(OperationJob.DATAMAP_STRING_OPERATION_NAME);
        String displayName = jobDataMap.getString(OperationJob.DATAMAP_STRING_OPERATION_DISPLAY_NAME);
        int subjectId = jobDataMap.getIntFromString(OperationJob.DATAMAP_INT_SUBJECT_ID);
        Configuration parameters = null;

        if (jobDataMap.containsKey(OperationJob.DATAMAP_INT_PARAMETERS_ID)) {
            int configId = jobDataMap.getIntFromString(OperationJob.DATAMAP_INT_PARAMETERS_ID);
            parameters = entityManager.find(Configuration.class, configId);
        }

        int resourceId = jobDataMap.getIntFromString(ResourceOperationJob.DATAMAP_INT_RESOURCE_ID);
        Resource resource = getResourceIfAuthorized(whoami, resourceId);

        Integer entityId = getOperationScheduleEntityId(jobDetail);

        // note that we throw an exception if the subject does not exist!
View Full Code Here

        return sched;
    }

    private int getOperationScheduleEntityId(JobDetail jobDetail) {
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        Object entityIdObj = jobDataMap.get(OperationJob.DATAMAP_INT_ENTITY_ID);
        int entityId;
        if (entityIdObj != null) {
            // for jobs created using RHQ 4.0 or later, the map will contain an entityId entry
            entityId = Integer.valueOf((String) entityIdObj);
        } else {
View Full Code Here

        // if the jobDetail is null assume the job is no longer scheduled
        if (null == jobDetail) {
            return null;
        }

        JobDataMap jobDataMap = jobDetail.getJobDataMap();

        String description = jobDetail.getDescription();
        String operationName = jobDataMap.getString(OperationJob.DATAMAP_STRING_OPERATION_NAME);
        String displayName = jobDataMap.getString(OperationJob.DATAMAP_STRING_OPERATION_DISPLAY_NAME);
        int subjectId = jobDataMap.getIntFromString(OperationJob.DATAMAP_INT_SUBJECT_ID);
        Configuration parameters = null;

        if (jobDataMap.containsKey(OperationJob.DATAMAP_INT_PARAMETERS_ID)) {
            int configId = jobDataMap.getIntFromString(OperationJob.DATAMAP_INT_PARAMETERS_ID);
            parameters = entityManager.find(Configuration.class, configId);
        }

        int groupId = jobDataMap.getIntFromString(GroupOperationJob.DATAMAP_INT_GROUP_ID);
        ResourceGroup group = getCompatibleGroupIfAuthorized(subject, groupId);

        List<Resource> executionOrder = null;

        if (jobDataMap.containsKey(GroupOperationJob.DATAMAP_INT_ARRAY_EXECUTION_ORDER)) {
            // if this property exists in the data map, we are assured that it has at least one ID in it
            String orderCommaSeparated = jobDataMap.getString(GroupOperationJob.DATAMAP_INT_ARRAY_EXECUTION_ORDER);
            String[] orderArray = orderCommaSeparated.split(",");
            for (String resourceIdString : orderArray) {
                int resourceId = Integer.parseInt(resourceIdString);
                Resource memberResource = entityManager.find(Resource.class, resourceId);

                if (memberResource != null) {
                    if (executionOrder == null) {
                        executionOrder = new ArrayList<Resource>();
                    }

                    if (!executionOrder.contains(memberResource)) {
                        executionOrder.add(memberResource);
                    }
                } else if (LOG.isDebugEnabled()) {
                    LOG.debug("Resource [" + resourceId
                        + "] looks like it was deleted and is no longer a member of group [" + group
                        + "] - ignoring it");
                }
            }
        }

        boolean haltOnFailure = jobDataMap.getBooleanValueFromString(GroupOperationJob.DATAMAP_BOOL_HALT_ON_FAILURE);

        Integer entityId = getOperationScheduleEntityId(jobDetail);

        GroupOperationSchedule sched = new GroupOperationSchedule();
        sched.setId(entityId);
View Full Code Here

            JobDetail jobDetail = new JobDetail(jobName, DEFAULT_AGENT_GROUP, NotifyAgentsOfScheduleUpdatesJob.class);

            final String triggerName = DEFAULT_AGENT_TRIGGER + " - " + randomSuffix;
            SimpleTrigger simpleTrigger = new SimpleTrigger(triggerName, DEFAULT_AGENT_GROUP, new Date());

            JobDataMap jobDataMap = simpleTrigger.getJobDataMap();
            jobDataMap.put(TRIGGER_NAME, triggerName);
            jobDataMap.put(TRIGGER_GROUP_NAME, DEFAULT_AGENT_GROUP);
            jobDataMap.put(SCHEDULE_SUBQUERY, scheduleSubQuery);
            jobDataMap.put(ENTITYCONTEXT_RESOURCEID, Integer.toString(entityContext.getResourceId()));
            jobDataMap.put(ENTITYCONTEXT_GROUPID, Integer.toString(entityContext.getGroupId()));
            jobDataMap.put(ENTITYCONTEXT_PARENT_RESOURCEID, Integer.toString(entityContext.getParentResourceId()));
            jobDataMap.put(ENTITYCONTEXT_RESOURCETYPEID, Integer.toString(entityContext.getResourceTypeId()));

            if (isJobScheduled(scheduler, DEFAULT_AGENT_JOB, DEFAULT_AGENT_GROUP)) {
                simpleTrigger.setJobName(DEFAULT_AGENT_JOB);
                simpleTrigger.setJobGroup(DEFAULT_AGENT_GROUP);
                scheduler.scheduleJob(simpleTrigger);
View Full Code Here

        } else {
            jobClass = StatefulJobWrapper.class;
        }

        // build the data map for the job, setting some values we need, plus adding the callback data for the plugin itself
        JobDataMap jobData = new JobDataMap();
        jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_NAME, pluginKey.getPluginName());
        jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_TYPE, pluginKey.getPluginType());
        jobData.put(AbstractJobWrapper.DATAMAP_JOB_ID, schedule.getJobId());
        jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TYPE, schedule.getScheduleType().getTypeName());
        jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TRIGGER, schedule.getScheduleType().getScheduleTrigger());
        jobData.putAsString(AbstractJobWrapper.DATAMAP_IS_CONCURRENT, schedule.getScheduleType().isConcurrent());
        jobData.putAsString(AbstractJobWrapper.DATAMAP_IS_CLUSTERED, schedule.getScheduleType().isClustered());
        jobData.put(AbstractJobWrapper.DATAMAP_JOB_METHOD_NAME, schedule.getMethodName());
        if (schedule.getClassName() != null) {
            jobData.put(AbstractJobWrapper.DATAMAP_JOB_CLASS, schedule.getClassName());
        }
        if (schedule.getCallbackData() != null) {
            jobData.putAll(schedule.getCallbackData());
        }

        // schedule the job now
        EnhancedScheduler scheduler;
View Full Code Here

TOP

Related Classes of org.quartz.JobDataMap

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.