List of usage examples for javax.ejb ScheduleExpression second
public ScheduleExpression second(int s)
From source file:eu.agilejava.snoop.scan.SnoopClient.java
public void register(final String clientId) { sendMessage(REGISTER_ENDPOINT, clientId); ScheduleExpression schedule = new ScheduleExpression(); schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); TimerConfig config = new TimerConfig(); config.setPersistent(false);//ww w .j a va2 s . c o m Timer timer = timerService.createCalendarTimer(schedule, config); LOGGER.config(() -> timer.getSchedule().toString()); }
From source file:eu.agilejava.snoop.eureka.scan.EurekaClient.java
@PostConstruct private void init() { LOGGER.config("Checking if snoop eureka is enabled"); LOGGER.config(() -> "YES: " + SnoopEurekaExtensionHelper.isEurekaEnabled()); if (SnoopEurekaExtensionHelper.isEurekaEnabled()) { readProperties();//w ww . java 2 s. c om EurekaConfig eurekaConfig = new EurekaConfig(); eurekaConfig.setHostName(applicationName); eurekaConfig.setApp(applicationName); eurekaConfig.setIpAddr("localhost"); eurekaConfig.setPort(8080); eurekaConfig.setStatus("UP"); eurekaConfig.setHomePageUrl(applicationHome); Entity<InstanceConfig> entity = Entity.entity(new InstanceConfig(eurekaConfig), MediaType.APPLICATION_JSON); Response response = ClientBuilder.newClient().target(serviceUrl + "apps/" + applicationName).request() .post(entity); LOGGER.config(() -> "POST resulted in: " + response.getStatus() + ", " + response.getEntity()); ScheduleExpression schedule = new ScheduleExpression(); schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); TimerConfig config = new TimerConfig(); config.setPersistent(false); Timer timer = timerService.createCalendarTimer(schedule, config); LOGGER.config(() -> timer.getSchedule().toString()); } else { LOGGER.config("Snoop Eureka is not enabled. Use @EnableEurekaClient!"); } }
From source file:eu.agilejava.snoop.scan.SnoopRegistrationClient.java
public void register(final String clientId) { sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON()); ScheduleExpression schedule = new ScheduleExpression(); schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); TimerConfig config = new TimerConfig(); config.setPersistent(false);//from w w w. j a v a2s. c om Timer timer = timerService.createCalendarTimer(schedule, config); LOGGER.config(() -> timer.getSchedule().toString()); }
From source file:be.fedict.eid.dss.model.bean.DocumentServiceBean.java
private ScheduleExpression getScheduleExpression(String cronSchedule) { ScheduleExpression schedule = new ScheduleExpression(); String[] fields = cronSchedule.split(" "); if (fields.length > 8) { throw new IllegalArgumentException("Too many fields in cronexpression: " + cronSchedule); }/* ww w. j a v a 2s. co m*/ if (fields.length > 1) { schedule.second(fields[0]); } if (fields.length > 2) { schedule.minute(fields[1]); } if (fields.length > 3) { schedule.hour(fields[2]); } if (fields.length > 4) { schedule.dayOfMonth(fields[3]); } if (fields.length > 5) { schedule.month(fields[4]); } if (fields.length > 6) { schedule.dayOfWeek(fields[5]); } if (fields.length > 7) { schedule.year(fields[6]); } return schedule; }
From source file:h2backup.BackupTimerService.java
@PostConstruct public void init() { if (!enabled) { log.info("H2 database backup is disabled"); return;//from w w w. j a v a 2 s . c om } if (StringUtils.isEmpty(methodName)) { log.warn("No H2 database backup methods were specified"); return; } method = BackupMethod.valueOf(methodName); if (StringUtils.isEmpty(directory)) { directory = System.getProperty("user.dir"); } toList = asList(to.split(LIST_DELIMITER)); if (text == null) { text = StringUtils.EMPTY; } String timerInfoName = getTimerInfoName(); for (Timer timer : timerService.getAllTimers()) { if (timer.getInfo() instanceof BackupTimerInfo) { BackupTimerInfo timerInfo = (BackupTimerInfo) timer.getInfo(); if (StringUtils.equals(timerInfoName, timerInfo.getName())) { log.info("H2 database backup is already scheduled: {}", timerInfo); return; } } } ScheduleExpression scheduleExpression = new ScheduleExpression(); if (StringUtils.isNoneEmpty(year)) { scheduleExpression.year(year); } if (StringUtils.isNoneEmpty(month)) { scheduleExpression.month(month); } if (StringUtils.isNoneEmpty(dayOfMonth)) { scheduleExpression.dayOfMonth(dayOfMonth); } if (StringUtils.isNoneEmpty(dayOfWeek)) { scheduleExpression.dayOfWeek(dayOfWeek); } if (StringUtils.isNoneEmpty(hour)) { scheduleExpression.hour(hour); } if (StringUtils.isNoneEmpty(minute)) { scheduleExpression.minute(minute); } if (StringUtils.isNoneEmpty(second)) { scheduleExpression.second(second); } if (StringUtils.isNoneEmpty(timezone)) { scheduleExpression.timezone(timezone); } BackupTimerInfo timerInfo = new BackupTimerInfo(timerInfoName, scheduleExpression, Instant.now()); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(timerInfo); timerConfig.setPersistent(true); timerService.createCalendarTimer(scheduleExpression, timerConfig); log.info("Scheduled H2 database backup: {}", timerInfo); }