Java Code Examples for org.quartz.impl.StdSchedulerFactory#getDefaultScheduler()
The following examples show how to use
org.quartz.impl.StdSchedulerFactory#getDefaultScheduler() .
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 File: Quartz2Adapter.java From javamelody with Apache License 2.0 | 6 votes |
@Override public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException { final Scheduler defaultScheduler; final List<Matcher<JobKey>> allJobs = new ArrayList<Matcher<JobKey>>(); allJobs.add(EverythingMatcher.allJobs()); if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) { defaultScheduler = null; LOG.debug("Initialization of Quartz default listener has been disabled"); } else { defaultScheduler = StdSchedulerFactory.getDefaultScheduler(); defaultScheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs); } for (final Scheduler scheduler : JobInformations.getAllSchedulers()) { if (scheduler != defaultScheduler) { scheduler.getListenerManager().addJobListener(jobGlobalListener, allJobs); } } }
Example 2
Source File: SchedulerBean.java From boubei-tss with Apache License 2.0 | 6 votes |
SchedulerBean() { // 根据配置决定是否启用定时Job if( Config.TRUE.equals(Config.getAttribute(PX.ENABLE_JOB)) ) { log.info("SchedulerBean is starting....." ); defsMap = new HashMap<String, JobDef>(); try { scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); } catch (SchedulerException e) { throw new BusinessException("start SchedulerBean error", e); } refresh(true); } }
Example 3
Source File: QuartzPluginIT.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void executeApp() throws Exception { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); JobDetail job; Trigger trigger; try { job = createJob2x(); trigger = createTrigger2x(); } catch (ClassNotFoundException e) { job = createJob1x(); trigger = createTrigger1x(); } scheduler.scheduleJob(job, trigger); SECONDS.sleep(1); scheduler.shutdown(); }
Example 4
Source File: GCalPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Schedules new quartz scheduler job for uploading calendar entries to Google */ private void scheduleUploadJob() { try { scheduler = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(SynchronizationJob.class).withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP) .build(); SimpleTrigger trigger = newTrigger().withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP) .withSchedule(repeatSecondlyForever(uploadInterval)).build(); scheduler.scheduleJob(job, trigger); logger.debug("Scheduled Google Calendar Upload-Job with interval '{}'", uploadInterval); } catch (SchedulerException e) { logger.warn("Could not create Google Calendar Upload-Job: {}", e.getMessage()); } }
Example 5
Source File: ScheduleManager.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Constructor * @param dbmgr allows ScheduleManager to access the database. * @param idxmgr allows the ScheduleManager to access the indexer. */ public ScheduleManager(DatabaseManager dbmgr, IndexManager idxmgr) { databaseManager = dbmgr; indexManager = idxmgr; try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (SchedulerException e) { throw new RuntimeException(e); } }
Example 6
Source File: Db4oPersistenceService.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Delete all quartz scheduler jobs of the group <code>Dropbox</code>. */ private void cancelAllJobs() { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); Set<JobKey> jobKeys = sched.getJobKeys(jobGroupEquals(SCHEDULER_GROUP)); if (jobKeys.size() > 0) { sched.deleteJobs(new ArrayList<JobKey>(jobKeys)); logger.debug("Found {} DB4O-Jobs to delete from DefaultScheduler (keys={})", jobKeys.size(), jobKeys); } } catch (SchedulerException e) { logger.warn("Couldn't remove Commit-Job: {}", e.getMessage()); } }
Example 7
Source File: QuarzSchedulerDAOImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public QuarzSchedulerDAOImpl() { logger.debug("IN"); try { scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (Throwable t) { throw new SpagoBIDAOException("Impossible to access to the default quartz scheduler", t); } finally { logger.debug("OUT"); } }
Example 8
Source File: ExportResource.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
@POST @Path("/cockpitData") @Produces(MediaType.APPLICATION_JSON) public Response exportCockpitDocumentWidgetData(DocumentExportConf documentExportConf) { logger.debug("IN"); logger.debug(String.format("document id: %s", documentExportConf.getDocumentId())); logger.debug(String.format("document label: %s", documentExportConf.getDocumentLabel())); logger.debug(String.format("export type: %s", documentExportConf.getExportType())); logger.debug(String.format("parameters: %s", documentExportConf.getParameters())); JobDetail exportJob = new CockpitDataExportJobBuilder().setDocumentExportConf(documentExportConf).setLocale(request.getLocale()) .setUserProfile(UserProfileManager.getProfile()).build(); logger.debug("Created export job"); try { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.addJob(exportJob, true); scheduler.triggerJob(exportJob.getName(), exportJob.getGroup()); logger.debug("Export job triggered "); } catch (SchedulerException e) { String msg = String.format("Error during scheduling of export job for cokcpit document %d", documentExportConf.getDocumentLabel()); logger.error(msg, e); throw new SpagoBIRuntimeException(msg); } logger.debug("OUT"); return Response.ok().entity(exportJob.getName()).build(); }
Example 9
Source File: TestJobGlobalListener.java From javamelody with Apache License 2.0 | 5 votes |
/** Test. * @throws SchedulerException e * @throws InterruptedException e */ @Test public void testJobGlobalListener() throws SchedulerException, InterruptedException { final Counter jobCounter = JobGlobalListener.getJobCounter(); jobCounter.clear(); jobCounter.setDisplayed(true); // job quartz JobGlobalListener.initJobGlobalListener(); //Grab the Scheduler instance from the Factory final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); try { // and start it off scheduler.start(); final Random random = new Random(); // on lance 10 jobs pour être à peu près sûr qu'il y en a un qui fait une erreur // (aléatoirement il y en a 2/10 qui font une erreur) for (int i = 0; i < 10; i++) { //Define job instance final JobDetail job = new JobDetail("job" + random.nextInt(), null, JobTestImpl.class); //Define a Trigger that will fire "now" final Trigger trigger = new SimpleTrigger("trigger" + random.nextInt(), null, new Date()); //Schedule the job with the trigger scheduler.scheduleJob(job, trigger); } // JobTestImpl fait un sleep de 2s au plus, donc on attend les jobs pour les compter Thread.sleep(3000); assertTrue("requestsCount", jobCounter.getRequestsCount() > 0); } finally { scheduler.shutdown(); JobGlobalListener.destroyJobGlobalListener(); } }
Example 10
Source File: SchedulerServiceSupplier.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
/** * Gets the job list. * * @return the job list */ public String getJobList() { String xml = ""; try { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); List toReturn = new ArrayList(); String[] groups = scheduler.getJobGroupNames(); if (groups == null || groups.length == 0) { SpagoBITracer.warning(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "getJobList", "No job groups defined!"); } else { for (int i = 0; i < groups.length; i++) { String group = groups[i]; String[] jobNames = scheduler.getJobNames(group); if (jobNames == null || jobNames.length == 0) { SpagoBITracer.warning(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "getJobList", "No job defined for group " + group + "!"); } else { for (int j = 0; j < jobNames.length; j++) { JobDetail aJob = scheduler.getJobDetail(jobNames[j], group); toReturn.add(aJob); } } } } xml = buildJobListXmlString(toReturn); } catch (Exception e) { SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "getJobList", "Error while recovering job list"); xml = "<ROWS></ROWS>"; } return xml; }
Example 11
Source File: QuartzApplication.java From spring-boot-study with MIT License | 5 votes |
public static void main(String[] args) { SpringApplication.run(QuartzApplication.class, args); try { // Grab the Scheduler instance from the Factory Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); //启动 scheduler.start(); //新建一个 Job WelcomeJob JobDetail job = JobBuilder.newJob(WelcomeJob.class) .withIdentity("mySimpleJob", "simpleGroup") .build(); // 触发器 定义多长时间触发 JobDetail Trigger trigger = org.quartz.TriggerBuilder.newTrigger() .withIdentity("simpleTrigger", "simpleGroup") .startNow() .withSchedule(simpleSchedule() .withIntervalInSeconds(10) .repeatForever()) .build(); scheduler.scheduleJob(job,trigger); //关闭 //scheduler.shutdown(); } catch (SchedulerException se) { se.printStackTrace(); } }
Example 12
Source File: QuartzAdapter.java From javamelody with Apache License 2.0 | 5 votes |
public void addGlobalJobListener(JobListener jobGlobalListener) throws SchedulerException { final Scheduler defaultScheduler; if (Parameter.QUARTZ_DEFAULT_LISTENER_DISABLED.getValueAsBoolean()) { defaultScheduler = null; LOG.debug("Initialization of Quartz default listener has been disabled"); } else { defaultScheduler = StdSchedulerFactory.getDefaultScheduler(); defaultScheduler.addGlobalJobListener(jobGlobalListener); } for (final Scheduler scheduler : JobInformations.getAllSchedulers()) { if (scheduler != defaultScheduler) { scheduler.addGlobalJobListener(jobGlobalListener); } } }
Example 13
Source File: JobScheduler.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
public JobScheduler(AstroContext context) { try { this.context = context; scheduler = StdSchedulerFactory.getDefaultScheduler(); } catch (SchedulerException ex) { logger.error(ex.getMessage(), ex); } }
Example 14
Source File: PlugwiseBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override protected void execute() { if (isProperlyConfigured()) { try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); scheduleJobs(sched); } catch (SchedulerException e) { logger.error("An exception occurred while getting a reference to the Quartz Scheduler ({})", e.getMessage()); } } }
Example 15
Source File: BatchImportJobTest.java From proarc with GNU General Public License v3.0 | 4 votes |
@Before public void initScheduler() throws SchedulerException { scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.start(); }
Example 16
Source File: SubscriptionCronScheduler.java From incubator-pinot with Apache License 2.0 | 4 votes |
public SubscriptionCronScheduler() throws SchedulerException { this.scheduler = StdSchedulerFactory.getDefaultScheduler(); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); this.alertConfigDAO = DAORegistry.getInstance().getDetectionAlertConfigManager(); }
Example 17
Source File: DetectionCronScheduler.java From incubator-pinot with Apache License 2.0 | 4 votes |
public DetectionCronScheduler(DetectionConfigManager detectionDAO) throws Exception { this.detectionDAO = detectionDAO; this.scheduler = StdSchedulerFactory.getDefaultScheduler(); this.executorService = Executors.newSingleThreadScheduledExecutor(); }
Example 18
Source File: ExportResource.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * Schedula a job to clean old export. * * @throws SchedulerException In case of error during scheduling */ private void scheduleCleanUp() throws SchedulerException { UserProfile userProfile = UserProfileManager.getProfile(); String resoursePath = SpagoBIUtilities.getResourcePath(); String jobName = String.format("delete-old-export-for-%s", userProfile.getUserId()); String jobGroup = "delete-old-export"; String jobDescription = String.format("Delete old exports for user %s", userProfile.getUserId()); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(ExportDeleteOldJob.MAP_KEY_RESOURCE_PATH, resoursePath); jobDataMap.put(ExportDeleteOldJob.MAP_KEY_USER_PROFILE, userProfile); JobDetail job = new JobDetail(jobName, jobGroup, ExportDeleteOldJob.class); job.setDescription(jobDescription); job.setJobDataMap(jobDataMap); Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.addJob(job, true); scheduler.triggerJob(job.getName(), job.getGroup()); }
Example 19
Source File: FritzboxBinding.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String ip = Objects.toString(config.get("ip"), null); if (StringUtils.isNotBlank(ip)) { if (!ip.equals(FritzboxBinding.ip)) { // only do something if the ip has changed FritzboxBinding.ip = ip; conditionalDeActivate(); // schedule a daily reconnection as sometimes the FritzBox // stops sending data // and thus blocks the monitor thread try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobKey jobKey = jobKey("Reconnect", "FritzBox"); TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox"); if (sched.checkExists(jobKey)) { logger.debug("Daily reconnection job already exists"); } else { CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule); JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build(); CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder) .build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT); } } catch (SchedulerException e) { logger.warn("Could not create daily reconnection job", e); } } } String password = Objects.toString(config.get("password"), null); if (StringUtils.isNotBlank(password)) { FritzboxBinding.password = password; } String username = Objects.toString(config.get("user"), null); if (StringUtils.isNotBlank(username)) { FritzboxBinding.username = username; } } }
Example 20
Source File: QuartzTest.java From fixflow with Apache License 2.0 | 4 votes |
public void testCronTrigger() throws SchedulerException { // SchedulerFactory // schedulerFactory=scheduleService.getSchedulerFactory(); // Scheduler scheduler=schedulerFactory.getScheduler(); Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); assertNotNull(scheduler); scheduler.start(); JobDetail job = newJob(SimpleJob.class).withIdentity("job1", "group1") .build(); Date nowDate = new Date(); long startDate = nowDate.getTime() + (24 * 60 * 60 * 1000); Date triggerStartTime = new Date(startDate); @SuppressWarnings("deprecation") int hour = nowDate.getHours(); String cronExpr = "* * 7/24 * * ?"; cronExpr = "* * "+hour+"/24 ? * 2-6"; System.out.println("cronExpr:" + cronExpr); CronTrigger trigger = newTrigger().withIdentity("trigger3", "group1") .withSchedule(cronSchedule(cronExpr)).startAt(triggerStartTime) .forJob("job1", "group1").build(); scheduler.scheduleJob(job, trigger); // trigger. Date date = trigger.getNextFireTime(); // trigger. // trigger.get SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("下次执行时间:" + df.format(date)); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, +24); System.out.println("Calendar:" + cal.get(Calendar.HOUR_OF_DAY)); scheduler.shutdown(); assertTrue(true); }