Package org.sonatype.scheduling.schedules

Examples of org.sonatype.scheduling.schedules.Schedule


  }

  public Schedule getModelSchedule(ScheduledServiceBaseResource model)
      throws ParseException, InvalidConfigurationException
  {
    Schedule schedule = null;

    if (ScheduledServiceAdvancedResource.class.isAssignableFrom(model.getClass())) {
      schedule = new CronSchedule(((ScheduledServiceAdvancedResource) model).getCronCommand());
    }
    else if (ScheduledServiceMonthlyResource.class.isAssignableFrom(model.getClass())) {
View Full Code Here


    ScheduledServiceResourceStatusResponse result = null;

    if (serviceRequest != null) {
      ScheduledServiceBaseResource serviceResource = serviceRequest.getData();
      try {
        Schedule schedule = getModelSchedule(serviceRequest.getData());
        ScheduledTask<?> task = null;

        final NexusTask<?> nexusTask = getModelNexusTask(serviceResource, request);

        if (getLogger().isDebugEnabled()) {
View Full Code Here

      return null;
    }
  }

  private Schedule translateFrom(CScheduleConfig modelSchedule, Date nextRun) {
    Schedule schedule = null;

    Date startDate = null;
    Date endDate = null;

    if (modelSchedule.getStartDate() > 0) {
      startDate = new Date(modelSchedule.getStartDate());
    }

    if (modelSchedule.getEndDate() > 0) {
      endDate = new Date(modelSchedule.getEndDate());
    }

    if (CScheduleConfig.TYPE_ADVANCED.equals(modelSchedule.getType())) {
      try {
        schedule = new CronSchedule(modelSchedule.getCronCommand());
      }
      catch (ParseException e) {
        // this will not happen, since it was persisted, hence already submitted
      }
    }
    else if (CScheduleConfig.TYPE_MONTHLY.equals(modelSchedule.getType())) {
      Set<Integer> daysToRun = new HashSet<Integer>();

      for (Iterator iter = modelSchedule.getDaysOfMonth().iterator(); iter.hasNext(); ) {
        String day = (String) iter.next();

        try {
          daysToRun.add(Integer.valueOf(day));
        }
        catch (NumberFormatException nfe) {
          log.error("Invalid day being added to monthly schedule - " + day + " - skipping.");
        }
      }

      schedule = new MonthlySchedule(startDate, endDate, daysToRun);
    }
    else if (CScheduleConfig.TYPE_WEEKLY.equals(modelSchedule.getType())) {
      Set<Integer> daysToRun = new HashSet<Integer>();

      for (Iterator iter = modelSchedule.getDaysOfWeek().iterator(); iter.hasNext(); ) {
        String day = (String) iter.next();

        try {
          daysToRun.add(Integer.valueOf(day));
        }
        catch (NumberFormatException nfe) {
          log.error("Invalid day being added to weekly schedule - " + day + " - skipping.");
        }
      }

      schedule = new WeeklySchedule(startDate, endDate, daysToRun);
    }
    else if (CScheduleConfig.TYPE_DAILY.equals(modelSchedule.getType())) {
      schedule = new DailySchedule(startDate, endDate);
    }
    else if (CScheduleConfig.TYPE_HOURLY.equals(modelSchedule.getType())) {
      schedule = new HourlySchedule(startDate, endDate);
    }
    else if (CScheduleConfig.TYPE_ONCE.equals(modelSchedule.getType())) {
      schedule = new OnceSchedule(startDate);
    }
    else if (CScheduleConfig.TYPE_RUN_NOW.equals(modelSchedule.getType())) {
      schedule = new RunNowSchedule();
    }
    else if (CScheduleConfig.TYPE_MANUAL.equals(modelSchedule.getType())) {
      schedule = new ManualRunSchedule();
    }
    else {
      throw new IllegalArgumentException("Unknown Schedule type: " + modelSchedule.getClass().getName());
    }

    if (nextRun != null) {
      Date resetFrom = nextRun;
      // NEXUS-4465: Cron schedule will add 1 second to given time to calculate next scheduled time
      // so we subtract it in case that next schedule is actually a valid time to run
      if (schedule instanceof CronSchedule) {
        resetFrom = new Date(resetFrom.getTime() - 1000);
      }
      schedule.getIterator().resetFrom(resetFrom);
    }

    return schedule;
  }
View Full Code Here

      props.setValue(task.getTaskParams().get(key));

      storeableTask.addProperty(props);
    }

    Schedule schedule = task.getSchedule();
    CScheduleConfig storeableSchedule = new CScheduleConfig();

    if (schedule != null) {
      if (CronSchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_ADVANCED);

        storeableSchedule.setCronCommand(((CronSchedule) schedule).getCronString());
      }
      else if (MonthlySchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_MONTHLY);

        storeableSchedule.setStartDate(((MonthlySchedule) schedule).getStartDate().getTime());

        Date endDate = ((MonthlySchedule) schedule).getEndDate();

        if (endDate != null) {
          storeableSchedule.setEndDate(endDate.getTime());
        }

        for (Iterator iter = ((MonthlySchedule) schedule).getDaysToRun().iterator(); iter.hasNext(); ) {
          // TODO: String.valueOf is used because currently the days to run are integers in the monthly
          // schedule
          // needs to be string
          storeableSchedule.addDaysOfMonth(String.valueOf(iter.next()));
        }
      }
      else if (WeeklySchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_WEEKLY);

        storeableSchedule.setStartDate(((WeeklySchedule) schedule).getStartDate().getTime());

        Date endDate = ((WeeklySchedule) schedule).getEndDate();

        if (endDate != null) {
          storeableSchedule.setEndDate(endDate.getTime());
        }

        for (Iterator iter = ((WeeklySchedule) schedule).getDaysToRun().iterator(); iter.hasNext(); ) {
          // TODO: String.valueOf is used because currently the days to run are integers in the weekly
          // schedule
          // needs to be string
          storeableSchedule.addDaysOfWeek(String.valueOf(iter.next()));
        }
      }
      else if (DailySchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_DAILY);

        storeableSchedule.setStartDate(((DailySchedule) schedule).getStartDate().getTime());

        Date endDate = ((DailySchedule) schedule).getEndDate();

        if (endDate != null) {
          storeableSchedule.setEndDate(endDate.getTime());
        }
      }
      else if (HourlySchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_HOURLY);

        storeableSchedule.setStartDate(((HourlySchedule) schedule).getStartDate().getTime());

        Date endDate = ((HourlySchedule) schedule).getEndDate();

        if (endDate != null) {
          storeableSchedule.setEndDate(endDate.getTime());
        }
      }
      else if (OnceSchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_ONCE);

        storeableSchedule.setStartDate(((OnceSchedule) schedule).getStartDate().getTime());
      }
      else if (RunNowSchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_RUN_NOW);
      }
      else if (ManualRunSchedule.class.isAssignableFrom(schedule.getClass())) {
        storeableSchedule.setType(CScheduleConfig.TYPE_MANUAL);
      }
      else {
        throw new IllegalArgumentException("Unknown Schedule type: " + schedule.getClass().getName());
      }
    }

    storeableTask.setSchedule(storeableSchedule);
View Full Code Here

    tr = new TestRunnable();

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), new Date(nearFuture + 4900));

    ScheduledTask<Object> st = defaultScheduler.schedule("default", tr, schedule);

    assertEquals(1, defaultScheduler.getActiveTasks().size());
View Full Code Here

    tr = new TestCallable();

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), new Date(nearFuture + 4900));

    ScheduledTask<Integer> st = defaultScheduler.schedule("default", tr, schedule);

    assertEquals(1, defaultScheduler.getActiveTasks().size());
View Full Code Here

    tr = new TestRunnable();

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), new Date(nearFuture + 4900));

    ScheduledTask<Object> st = defaultScheduler.schedule("default", tr, schedule);

    assertEquals(1, defaultScheduler.getActiveTasks().size());
View Full Code Here

    tr = new TestCallable();

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), new Date(nearFuture + 4900));

    ScheduledTask<Integer> st = defaultScheduler.schedule("default", tr, schedule);

    assertEquals(1, defaultScheduler.getActiveTasks().size());
View Full Code Here

  {
    BrokenTestCallable callable = new BrokenTestCallable();

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), new Date(nearFuture + 1200));

    ScheduledTask<Integer> task = defaultScheduler.schedule("default", callable, schedule);

    Thread.sleep(700);
View Full Code Here

    TestChangeScheduleDuringRunCallable callable = new TestChangeScheduleDuringRunCallable(200000);

    long nearFuture = System.currentTimeMillis() + 500;

    Schedule schedule = getEverySecondSchedule(new Date(nearFuture), null);

    ScheduledTask<Integer> task = defaultScheduler.schedule("default", callable, schedule);

    callable.setTask(task);
View Full Code Here

TOP

Related Classes of org.sonatype.scheduling.schedules.Schedule

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.