public List<JobLocation> readPayload(DataInput dataIn) throws IOException { List<JobLocation> result = new ArrayList<JobLocation>(); int size = dataIn.readInt(); for (int i = 0; i < size; i++) { JobLocation jobLocation = new JobLocation(); jobLocation.readExternal(dataIn); result.add(jobLocation); } return result; }
long calculateNextExecutionTime(final JobLocation job, long currentTime, int repeat) throws MessageFormatException { long result = currentTime; String cron = job.getCronEntry(); if (cron != null && cron.length() > 0) { result = CronParser.getNextScheduledTime(cron, result); } else if (job.getRepeat() != 0) { result += job.getPeriod(); } return result; }
public long getDelay() { return this.jobLocation.getDelay(); }
JobLocation jobLocation = new JobLocation(location); this.store.incrementJournalCount(tx, location); jobLocation.setJobId(jobId); jobLocation.setStartTime(startTime); jobLocation.setCronEntry(cronEntry); jobLocation.setDelay(delay); jobLocation.setPeriod(period); jobLocation.setRepeat(repeat); if (LOG.isDebugEnabled()) { LOG.debug("Scheduling " + jobLocation);
if (executionTime <= currentTime) { for (final JobLocation job : list) { int repeat = job.getRepeat(); nextExecutionTime = calculateNextExecutionTime(job, currentTime, repeat); long waitTime = nextExecutionTime - currentTime; this.scheduleTime.setWaitTime(waitTime); if (job.isCron() == false) { fireJob(job); if (repeat != 0) { repeat--; job.setRepeat(repeat); removeFromIndex(executionTime, job.getJobId()); removeFromIndex(executionTime, job.getJobId()); ByteSequence payload = getPayload(job.getLocation()); schedule(jobId, payload, "", job.getDelay(), job.getPeriod(), job.getRepeat()); waitTime = job.getDelay() != 0 ? job.getDelay() : job.getPeriod(); this.scheduleTime.setWaitTime(waitTime);
void fireJob(JobLocation job) throws IllegalStateException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("Firing " + job); } ByteSequence bs = this.store.getPayload(job.getLocation()); for (JobListener l : jobListeners) { l.scheduledJob(job.getJobId(), bs); } }
synchronized void destroy(Transaction tx) throws IOException { List<Long> keys = new ArrayList<Long>(); for (Iterator<Map.Entry<Long, List<JobLocation>>> i = this.index.iterator(tx); i.hasNext();) { Map.Entry<Long, List<JobLocation>> entry = i.next(); keys.add(entry.getKey()); List<JobLocation> values = entry.getValue(); if (values != null) { for (JobLocation jl : values) { this.store.decrementJournalCount(tx, jl.getLocation()); } } } for (Long l : keys) { this.index.remove(tx, l); } }
public String getJobId() { return this.jobLocation.getJobId(); }
public String getCronEntry() { return this.jobLocation.getCronEntry(); }
public long getStart() { return this.jobLocation.getStartTime(); }
public int getRepeat() { return this.jobLocation.getRepeat(); }
public long getPeriod() { return this.jobLocation.getPeriod(); }
public String getNextExecutionTime() { return JobImpl.getDateTime(this.jobLocation.getNextTime()); }
void remove(Transaction tx, long time) throws IOException { List<JobLocation> values = this.index.remove(tx, time); if (values != null) { for (JobLocation jl : values) { this.store.decrementJournalCount(tx, jl.getLocation()); } } }
void remove(Transaction tx, String id) throws IOException { for (Iterator<Map.Entry<Long, List<JobLocation>>> i = this.index.iterator(tx); i.hasNext();) { Map.Entry<Long, List<JobLocation>> entry = i.next(); List<JobLocation> values = entry.getValue(); if (values != null) { for (JobLocation jl : values) { if (jl.getJobId().equals(id)) { remove(tx, entry.getKey(), id); return; } } } } }
public boolean isCron() { return getCronEntry() != null && getCronEntry().length() > 0; }
public List<JobLocation> readPayload(DataInput dataIn) throws IOException { List<JobLocation> result = new ArrayList<JobLocation>(); int size = dataIn.readInt(); for (int i = 0; i < size; i++) { JobLocation jobLocation = new JobLocation(); jobLocation.readExternal(dataIn); result.add(jobLocation); } return result; }
void remove(Transaction tx, long time, String jobId) throws IOException { JobLocation result = removeFromIndex(tx, time, jobId); if (result != null) { this.store.decrementJournalCount(tx, result.getLocation()); } }
JobLocation removeFromIndex(Transaction tx, long time, String jobId) throws IOException { JobLocation result = null; List<JobLocation> values = this.index.remove(tx, time); if (values != null) { for (int i = 0; i < values.size(); i++) { JobLocation jl = values.get(i); if (jl.getJobId().equals(jobId)) { values.remove(i); if (!values.isEmpty()) { this.index.put(tx, time, values); } result = jl; break; } } } return result; }
public List<JobLocation> readPayload(DataInput dataIn) throws IOException { List<JobLocation> result = new ArrayList<JobLocation>(); int size = dataIn.readInt(); for (int i = 0; i < size; i++) { JobLocation jobLocation = new JobLocation(); jobLocation.readExternal(dataIn); result.add(jobLocation); } return result; }