Created
January 18, 2017 06:00
-
-
Save mnadeem/162082f6c338bdd15d73a4dbe39e284e to your computer and use it in GitHub Desktop.
Fixed Delay job data used by FixedDelayJobListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import java.util.Date; | |
import java.util.concurrent.TimeUnit; | |
public final class FixdedDelayJobData implements Serializable { | |
private static final long serialVersionUID = 1L; | |
private long delay; | |
private TimeUnit delayUnit; | |
public FixdedDelayJobData(long delay) { | |
this(delay, TimeUnit.SECONDS); | |
} | |
public FixdedDelayJobData(long delay, final TimeUnit delayUnit) { | |
if (delay == 0) { | |
throw new IllegalArgumentException("Delay cannot be zero"); | |
} | |
if (delayUnit == null) { | |
throw new IllegalArgumentException("Delay Unit should be provided"); | |
} | |
this.delay = delay; | |
this.delayUnit = delayUnit; | |
} | |
public Date getNextScheduleDate() { | |
return new Date(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, delayUnit)); | |
} | |
@Override | |
public String toString() { | |
return "FixdedDelayJobData [delay=" + delay + ", delayUnit=" + delayUnit + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment