/** * Creates cron expression which schedule task execution * every given day of the month at the given time * * @param hour of schedule * @param minute of schedule * @param dayOfMonth of schedule * @return object */ public static CronSchedule monthlyOnDayAndHourAndMinute(int dayOfMonth, int hour, int minute) { String expression = String.format("0 %d %d %d * ?", minute, hour, dayOfMonth); return of(expression); }
/** * Creates cron expression object with defined expression string * * @param expression of cron * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule of(String expression) { return new CronSchedule(new CronExpression(expression)); }
public static void main(String[] args) { Config config = new Config(); config.useClusterServers() .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"); RedissonClient redisson = Redisson.create(config); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 5)); RedissonNode node = RedissonNode.create(nodeConfig); node.start(); RScheduledExecutorService e = redisson.getExecutorService("myExecutor"); e.schedule(new RunnableTask(), 10, TimeUnit.SECONDS); e.schedule(new CallableTask(), 4, TimeUnit.MINUTES); e.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?")); e.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5)); e.schedule(new RunnableTask(), CronSchedule.weeklyOnDayAndHourAndMinute(12, 4, Calendar.MONDAY, Calendar.FRIDAY)); e.shutdown(); node.shutdown(); }
ClassBody classBody = getClassBody(task); byte[] state = encode(task); final Date startDate = cronSchedule.getExpression().getNextValidTimeAfter(new Date()); if (startDate == null) { throw new IllegalArgumentException("Wrong cron expression! Unable to calculate start date"); params.setState(state); params.setStartTime(startTime); params.setCronExpression(cronSchedule.getExpression().getCronExpression()); params.setTimezone(cronSchedule.getExpression().getTimeZone().getID()); params.setExecutorId(executorId); RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.schedule(params);
ClassBody classBody = getClassBody(task); byte[] state = encode(task); final Date startDate = cronSchedule.getExpression().getNextValidTimeAfter(new Date()); if (startDate == null) { throw new IllegalArgumentException("Wrong cron expression! Unable to calculate start date"); params.setState(state); params.setStartTime(startTime); params.setCronExpression(cronSchedule.getExpression().getCronExpression()); params.setTimezone(cronSchedule.getExpression().getTimeZone().getID()); params.setExecutorId(executorId); RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.schedule(params);
/** * Creates cron expression which schedule task execution * every given day of the month at the given time * * @param hour of schedule * @param minute of schedule * @param dayOfMonth of schedule * @return object */ public static CronSchedule monthlyOnDayAndHourAndMinute(int dayOfMonth, int hour, int minute) { String expression = String.format("0 %d %d %d * ?", minute, hour, dayOfMonth); return of(expression); }
/** * Creates cron expression object with defined expression string * * @param expression of cron * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule of(String expression) { return new CronSchedule(new CronExpression(expression)); }
ClassBody classBody = getClassBody(task); byte[] state = encode(task); final Date startDate = cronSchedule.getExpression().getNextValidTimeAfter(new Date()); if (startDate == null) { throw new IllegalArgumentException("Wrong cron expression! Unable to calculate start date"); params.setState(state); params.setStartTime(startTime); params.setCronExpression(cronSchedule.getExpression().getCronExpression()); params.setTimezone(cronSchedule.getExpression().getTimeZone().getID()); params.setExecutorId(executorId); RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.schedule(params);
/** * Creates cron expression which schedule task execution * every day at the given time * * @param hour of schedule * @param minute of schedule * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule dailyAtHourAndMinute(int hour, int minute) { String expression = String.format("0 %d %d ? * *", minute, hour); return of(expression); }
/** * Creates cron expression object with defined expression string * * @param expression of cron * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule of(String expression) { return new CronSchedule(new CronExpression(expression)); }
/** * Creates cron expression which schedule task execution * every day at the given time * * @param hour of schedule * @param minute of schedule * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule dailyAtHourAndMinute(int hour, int minute) { String expression = String.format("0 %d %d ? * *", minute, hour); return of(expression); }
/** * Creates cron expression which schedule task execution * every given days of the week at the given time. * Use Calendar object constants to define day. * * @param hour of schedule * @param minute of schedule * @param daysOfWeek - Calendar object constants * @return object */ public static CronSchedule weeklyOnDayAndHourAndMinute(int hour, int minute, Integer... daysOfWeek) { if (daysOfWeek == null || daysOfWeek.length == 0) { throw new IllegalArgumentException("You must specify at least one day of week."); } String expression = String.format("0 %d %d ? * %d", minute, hour, daysOfWeek[0]); for (int i = 1; i < daysOfWeek.length; i++) { expression = expression + "," + daysOfWeek[i]; } return of(expression); }
/** * Creates cron expression which schedule task execution * every given days of the week at the given time. * Use Calendar object constants to define day. * * @param hour of schedule * @param minute of schedule * @param daysOfWeek - Calendar object constants * @return object */ public static CronSchedule weeklyOnDayAndHourAndMinute(int hour, int minute, Integer... daysOfWeek) { if (daysOfWeek == null || daysOfWeek.length == 0) { throw new IllegalArgumentException("You must specify at least one day of week."); } String expression = String.format("0 %d %d ? * %d", minute, hour, daysOfWeek[0]); for (int i = 1; i < daysOfWeek.length; i++) { expression = expression + "," + daysOfWeek[i]; } return of(expression); }
/** * Creates cron expression which schedule task execution * every given day of the month at the given time * * @param hour of schedule * @param minute of schedule * @param dayOfMonth of schedule * @return object */ public static CronSchedule monthlyOnDayAndHourAndMinute(int dayOfMonth, int hour, int minute) { String expression = String.format("0 %d %d %d * ?", minute, hour, dayOfMonth); return of(expression); }
/** * Creates cron expression which schedule task execution * every day at the given time * * @param hour of schedule * @param minute of schedule * @return object * @throws IllegalArgumentException * wrapping a ParseException if the expression is invalid */ public static CronSchedule dailyAtHourAndMinute(int hour, int minute) { String expression = String.format("0 %d %d ? * *", minute, hour); return of(expression); }
/** * Creates cron expression which schedule task execution * every given days of the week at the given time. * Use Calendar object constants to define day. * * @param hour of schedule * @param minute of schedule * @param daysOfWeek - Calendar object constants * @return object */ public static CronSchedule weeklyOnDayAndHourAndMinute(int hour, int minute, Integer... daysOfWeek) { if (daysOfWeek == null || daysOfWeek.length == 0) { throw new IllegalArgumentException("You must specify at least one day of week."); } String expression = String.format("0 %d %d ? * %d", minute, hour, daysOfWeek[0]); for (int i = 1; i < daysOfWeek.length; i++) { expression = expression + "," + daysOfWeek[i]; } return of(expression); }
@Override public String addCronJob(String jobId, String cron) { String taskId = getRedissonClient().getExecutorService(JobConfig.WORKER) .scheduleAsync(new JobDispatchWrapper(jobId), CronSchedule.of(cron)).getTaskId(); getRedissonClient().<String, String>getListMultimap( JobConfig.TASK_ID).put(jobId, taskId); return taskId; }