Package org.quartz

Examples of org.quartz.Scheduler


        }
        return isScheduled;
    }

    private void scheduleAgentInventoryOperationJob(List<Resource> platforms, List<Resource> servers) {
        Scheduler scheduler = LookupUtil.getSchedulerBean();
        try {
            final String DEFAULT_JOB_NAME = "AgentInventoryUpdateJob";
            final String DEFAULT_JOB_GROUP = "AgentInventoryUpdateGroup";
            final String TRIGGER_PREFIX = "AgentInventoryUpdateTrigger";

            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(AgentInventoryStatusUpdateJob.KEY_TRIGGER_NAME, triggerName);
            jobDataMap.put(AgentInventoryStatusUpdateJob.KEY_TRIGGER_GROUP_NAME, DEFAULT_JOB_GROUP);
            AgentInventoryStatusUpdateJob.externalizeJobValues(jobDataMap,
                AgentInventoryStatusUpdateJob.PLATFORMS_COMMA_LIST, platforms);
            AgentInventoryStatusUpdateJob.externalizeJobValues(jobDataMap,
                AgentInventoryStatusUpdateJob.SERVERS_COMMA_LIST, servers);

            trigger.setJobName(DEFAULT_JOB_NAME);
            trigger.setJobGroup(DEFAULT_JOB_GROUP);
            trigger.setJobDataMap(jobDataMap);

            if (isJobScheduled(scheduler, DEFAULT_JOB_NAME, DEFAULT_JOB_GROUP)) {
                scheduler.scheduleJob(trigger);
            } else {
                JobDetail jobDetail = new JobDetail(DEFAULT_JOB_NAME, DEFAULT_JOB_GROUP,
                    AgentInventoryStatusUpdateJob.class);
                scheduler.scheduleJob(jobDetail, trigger);
            }
        } catch (SchedulerException e) {
            LOG.error("Failed to schedule agent inventory update operation.", e);
            updateAgentInventoryStatus(platforms, servers);
        }
View Full Code Here


        return enableResourceIds;
    }

    private void scheduleAgentRequestFullAvailabilityJob(Collection<Agent> agents) {
        Scheduler scheduler = LookupUtil.getSchedulerBean();
        try {
            final String DEFAULT_JOB_NAME = "AgentRequestFullAvailabilityJob";
            final String DEFAULT_JOB_GROUP = "AgentRequestFullAvailabilityGroup";
            final String TRIGGER_PREFIX = "AgentRequestFullAvailabilityTrigger";

            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);
            trigger.setJobDataMap(jobDataMap);

            if (isJobScheduled(scheduler, DEFAULT_JOB_NAME, DEFAULT_JOB_GROUP)) {
                scheduler.scheduleJob(trigger);
            } else {
                JobDetail jobDetail = new JobDetail(DEFAULT_JOB_NAME, DEFAULT_JOB_GROUP,
                    AgentRequestFullAvailabilityJob.class);
                scheduler.scheduleJob(jobDetail, trigger);
            }
        } catch (SchedulerException e) {
            LOG.error("Failed to schedule AgentRequestFullAvailabilityJob.", e);
        }
    }
View Full Code Here

            "RHQServerPluginsJob");

        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(schedulerConfig);

        Scheduler scheduler = factory.getScheduler();
        scheduler.start();

        this.nonClusteredSchedulerFactory = factory;
        return;
    }
View Full Code Here

     * This tells all jobs to shut down.
     */
    protected void shutdownNonClusteredScheduler() {
        if (this.nonClusteredSchedulerFactory != null) {
            try {
                Scheduler scheduler = this.nonClusteredSchedulerFactory.getScheduler();
                if (scheduler != null) {
                    scheduler.shutdown(false);
                }
            } catch (Exception e) {
                log.warn("Failed to shutdown master plugin container nonclustered scheduler", e);
            } finally {
                this.nonClusteredSchedulerFactory = null;
View Full Code Here

    public static final String ENTITYCONTEXT_GROUPID = "EntityContext.groupId";
    public static final String ENTITYCONTEXT_PARENT_RESOURCEID = "EntityContext.parentResourceId";
    public static final String ENTITYCONTEXT_RESOURCETYPEID = "EntityContext.resourceTypeId";

    private void scheduleJobToPushScheduleUpdatesToAgents(EntityContext entityContext, String scheduleSubQuery) {
        Scheduler scheduler;
        try {
            scheduler = LookupUtil.getSchedulerBean();

            final String DEFAULT_AGENT_JOB = "AGENT NOTIFICATION JOB";
            final String DEFAULT_AGENT_GROUP = "AGENT NOTIFICATION GROUP";
            final String DEFAULT_AGENT_TRIGGER = "AGENT NOTIFICATION TRIGGER";

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

            final String jobName = DEFAULT_AGENT_JOB + " - " + randomSuffix;
            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);
            } else {
                scheduler.scheduleJob(jobDetail, simpleTrigger);
            }
        } catch (RuntimeException e) {
            // lookup wrapper throws runtime exceptions, no distinction between
            // types, so fallback and do the best we can.
            log.error("Failed to schedule agents update notification.", e);
View Full Code Here

    }

    public void stop() {
        if (trigger != null) {
            try {
                final Scheduler s = timerService.getScheduler();
               
                if(!s.isShutdown()){               
                    s.unscheduleJob(trigger.getName(), trigger.getGroup());
                }
            } catch (SchedulerException e) {
                throw new EJBException("fail to cancel the timer", e);
            }
        }
View Full Code Here

    public void cancel() {
        timerService.cancelled(TimerData.this);
        if (trigger != null) {
            try {
                final Scheduler s = timerService.getScheduler();
               
                if(!s.isShutdown()){
                    s.unscheduleJob(trigger.getName(), trigger.getGroup());
                }
            } catch (SchedulerException e) {
                throw new EJBException("fail to cancel the timer", e);
            }
        }
View Full Code Here

        }
        return answer;
    }

    protected Scheduler createScheduler() throws SchedulerException {
        Scheduler scheduler = getFactory().getScheduler();
        // register current camel context to scheduler so we can look it up when jobs is being triggered
        scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getName(), getCamelContext());
        return scheduler;
    }
View Full Code Here

    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = new FileSystemXmlApplicationContext(
                "./ch14/src/conf/quartzPersistent.xml");

        // get the scheduler
        Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");

        JobDetail job = scheduler.getJobDetail("otherJob",
                Scheduler.DEFAULT_GROUP);

        if (job == null) {
            // the job has not yet been created
            job = (JobDetail) ctx.getBean("job");
            job.setName("otherJob");
            job.getJobDataMap().put("message", "This is another message");

            Trigger trigger = new SimpleTrigger("simpleTrigger",
                    Scheduler.DEFAULT_GROUP, new Date(), null,
                    SimpleTrigger.REPEAT_INDEFINITELY, 3000);

            scheduler.scheduleJob(job, trigger);
        }

    }
View Full Code Here

    @Override
    protected void doStart() throws MuleException
    {
        try
        {
            Scheduler scheduler = connector.getQuartzScheduler();

            JobConfig jobConfig = (JobConfig) endpoint.getProperty(QuartzConnector.PROPERTY_JOB_CONFIG);
            if (jobConfig == null)
            {
                throw new IllegalArgumentException(CoreMessages.objectIsNull(QuartzConnector.PROPERTY_JOB_CONFIG).getMessage());
            }
           
            JobDetail jobDetail = new JobDetail();
            jobDetail.setName(endpoint.getEndpointURI().getAddress());
            jobDetail.setJobClass(jobConfig.getJobClass());
            JobDataMap jobDataMap = new JobDataMap();
            jobDataMap.put(QUARTZ_RECEIVER_PROPERTY, this.getReceiverKey());
            jobDataMap.put(QUARTZ_CONNECTOR_PROPERTY, this.connector.getName());
            jobDataMap.putAll(endpoint.getProperties());

            if (jobConfig instanceof EventGeneratorJobConfig)
            {
                jobDataMap.put(QuartzConnector.PROPERTY_PAYLOAD, ((EventGeneratorJobConfig) jobConfig).getPayload());
            }
            jobDataMap.put(QuartzConnector.PROPERTY_JOB_CONFIG, jobConfig);
           
            Job job = null;
            if (jobConfig instanceof CustomJobConfig)
            {
                job = ((CustomJobConfig) jobConfig).getJob();
            }
            // If there has been a job created or found then we default to a custom Job configuration
            if (job != null)
            {
                jobDataMap.put(QuartzConnector.PROPERTY_JOB_OBJECT, job);
                jobDetail.setJobClass(jobConfig.getJobClass());
            }

            jobDetail.setJobDataMap(jobDataMap);
           
            Trigger trigger;
            String cronExpression = (String)endpoint.getProperty(QuartzConnector.PROPERTY_CRON_EXPRESSION);
            String repeatInterval = (String)endpoint.getProperty(QuartzConnector.PROPERTY_REPEAT_INTERVAL);
            String repeatCount = (String)endpoint.getProperty(QuartzConnector.PROPERTY_REPEAT_COUNT);
            String startDelay = (String)endpoint.getProperty(QuartzConnector.PROPERTY_START_DELAY);
            String groupName = jobConfig.getGroupName();
            String jobGroupName = jobConfig.getJobGroupName();

            if (groupName == null)
            {
                groupName = QuartzConnector.DEFAULT_GROUP_NAME;
            }
            if (jobGroupName == null)
            {
                jobGroupName = groupName;
            }

            jobDetail.setGroup(groupName);

            if (cronExpression != null)
            {
                CronTrigger ctrigger = new CronTrigger();
                ctrigger.setCronExpression(cronExpression);
                trigger = ctrigger;
            }
            else if (repeatInterval != null)
            {
                SimpleTrigger strigger = new SimpleTrigger();
                strigger.setRepeatInterval(Long.parseLong(repeatInterval));
                if (repeatCount != null)
                {
                    strigger.setRepeatCount(Integer.parseInt(repeatCount));
                }
                else
                {
                    strigger.setRepeatCount(-1);
                }
                trigger = strigger;
            }
            else
            {
                throw new IllegalArgumentException(
                        QuartzMessages.cronExpressionOrIntervalMustBeSet().getMessage());
            }

            trigger.setName(endpoint.getEndpointURI().getAddress());
            trigger.setGroup(groupName);
            trigger.setJobName(endpoint.getEndpointURI().getAddress());
            trigger.setJobGroup(jobGroupName);

            // Minimize the the time window capturing the start time and scheduling the job.
            long start = System.currentTimeMillis();
            if (startDelay != null)
            {
                start += Long.parseLong(startDelay);
            }
            trigger.setStartTime(new Date(start));

            // We need to handle cases when the job has already been persisted
            try
            {
                scheduler.scheduleJob(jobDetail, trigger);
            }
            catch (ObjectAlreadyExistsException oaee)
            {
                logger.warn("A quartz Job with name: " + endpoint.getEndpointURI().getAddress() +
                        " has already been registered. Cannot register again");
View Full Code Here

TOP

Related Classes of org.quartz.Scheduler

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.