com.elephantdrummer.trigger.base.DrumTrigger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of drummer Show documentation
Show all versions of drummer Show documentation
Elephant Drummer Java Job Scheduler
package com.elephantdrummer.trigger.base;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import com.elephantdrummer.annotation.trigger.After;
import com.elephantdrummer.annotation.trigger.At;
import com.elephantdrummer.annotation.trigger.Before;
import com.elephantdrummer.annotation.trigger.Every;
import com.elephantdrummer.annotation.trigger.Range;
import com.elephantdrummer.container.ContainerElement;
import com.elephantdrummer.parser.ParserDateMaskToStep;
import com.elephantdrummer.trigger.Trigger;
/**
* Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public abstract class DrumTrigger implements Trigger,ContainerElement{
protected Logger log=Logger.getLogger(this.getClass().getSimpleName());
private Long step=new Long(0);
private Long shift=new Long(0);
private After after;
private Before before;
private At at;
private String cron;
private Every period;
public abstract TriggerType getTriggerType();
public abstract String getDescription();
// private ParserPeriodToMiliseconds parserPeriodToMiliseconds=Container.getElement(ParserPeriodToMiliseconds.class);
// public final static long PERIOD_MILISECOND=1;
// public final static long PERIOD_SECOND=1000*PERIOD_MILISECOND;
// public final static long PERIOD_MINUTE=60*PERIOD_SECOND;
// public final static long PERIOD_HOUR=60*PERIOD_MINUTE;
// public final static long PERIOD_DAY=24*PERIOD_HOUR;
// public final static long PERIOD_WEEK=7*PERIOD_DAY;
public final Long getStep() {
return step;
}
public void setStep(Long step) {
this.step = step;
}
//TODO: co z ta data
public Date getAfterNextRunTime(Date taskScheduledTime){
return getNextRunTime(new Date());
}
public static long getDifferenceDays(Date d1, Date d2) {
long diff = d2.getTime() - d1.getTime();
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
}
public void setShift(Range period) {
setShift(ParserDateMaskToStep.toMiliseconds(period));
}
public void setStep(Every period) {
setStep(ParserDateMaskToStep.toMiliseconds(period));
}
public final Long getShift() {
if (shift==null==false&&shift>0){
Random rnd=new Random();
shift=new Long (rnd.nextInt( new Long( (getStep()>shift)?shift:getStep()).intValue())*-1 ) ;
}
return shift;
}
public void setShift(Long shift) {
this.shift = shift;
}
public Every getPeriod() {
return period;
}
public void setPeriod(Every intervalPeriod) {
this.period = intervalPeriod;
}
public After getAfter() {
return after;
}
public void setAfter(After start) {
this.after = start;
}
public Before getBefore() {
return before;
}
public void setBefore(Before stop) {
this.before = stop;
}
public At getAt() {
return at;
}
public void setAt(At at) {
this.at = at;
}
public String getCron() {
return cron;
}
public void setCron(String cron) {
this.cron = cron;
}
}