Search in sources :

Example 1 with DefaultScheduleMaster

use of jp.ossc.nimbus.service.scheduler2.DefaultScheduleMaster in project nimbus by nimbus-org.

the class ScheduleMakeActionService method execute.

/**
 * リソースの内容を読み込んで、指定されたスケジュールマスタから、現在時刻で開始するスケジュールを作成する。<p>
 * リソースのフォーマットは、以下。<br>
 * <pre>
 * masterId
 * </pre>
 * masterIdは、作成するスケジュールのマスタIDを指定する。<br>
 *
 * @param context コンテキスト
 * @param actionId アクションID
 * @param resource リソース
 * @return 生成されたスケジュールのリスト
 */
public Object execute(TestContext context, String actionId, Reader resource) throws Exception {
    BufferedReader br = new BufferedReader(resource);
    String masterId = null;
    try {
        masterId = br.readLine();
        if (masterId == null) {
            throw new Exception("Unexpected EOF on masterId");
        }
    } finally {
        br.close();
        br = null;
    }
    Date now = new Date();
    final DefaultScheduleMaster master = (DefaultScheduleMaster) scheduleManager.findScheduleMaster(masterId);
    if (master == null) {
        throw new Exception("ScheduleMaster not found. masterId=" + masterId);
    }
    final Calendar cal = Calendar.getInstance();
    Date startTime = master.getStartTime();
    long offset = 0;
    if (startTime != null) {
        cal.setTime(now);
        final int year = cal.get(Calendar.YEAR);
        final int day = cal.get(Calendar.DAY_OF_YEAR);
        cal.clear();
        cal.setTime(startTime);
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.DAY_OF_YEAR, day + (cal.get(Calendar.DAY_OF_YEAR) - 1));
        offset = now.getTime() - cal.getTimeInMillis();
        cal.clear();
        cal.setTime(now);
        cal.set(Calendar.DAY_OF_YEAR, 1);
        startTime = cal.getTime();
    }
    master.setStartTime(startTime);
    final Date endTime = master.getEndTime();
    if (endTime != null) {
        master.setEndTime(new Date(endTime.getTime() + offset));
    }
    final Date retryEndTime = master.getRetryEndTime();
    if (retryEndTime != null) {
        master.setRetryEndTime(new Date(retryEndTime.getTime() + offset));
    }
    return scheduleManager.makeSchedule(now, master);
}
Also used : Calendar(java.util.Calendar) BufferedReader(java.io.BufferedReader) DefaultScheduleMaster(jp.ossc.nimbus.service.scheduler2.DefaultScheduleMaster) Date(java.util.Date)

Aggregations

BufferedReader (java.io.BufferedReader)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 DefaultScheduleMaster (jp.ossc.nimbus.service.scheduler2.DefaultScheduleMaster)1