22 package com.realtime.crossfire.jxclient.items;
24 import org.jetbrains.annotations.NotNull;
59 private final Object
sync =
new Object();
83 @SuppressWarnings(
"FieldCanBeLocal")
84 private final Runnable
runnable = new Runnable() {
90 final long now = System.currentTimeMillis();
91 final boolean fireEvent;
93 if (nextAction == 0) {
97 final long thisDelay = Math.max(nextAction, nextActionNotBefore)-now;
108 eventSchedulerCallback.run();
112 }
catch (
final InterruptedException ignored) {
127 public EventScheduler(
final int delay,
final int afterEventDelay, @NotNull
final Runnable eventSchedulerCallback) {
131 thread =
new Thread(
runnable,
"JXClient:EventScheduler");
145 final long now = System.currentTimeMillis();
146 synchronized (
sync) {
147 nextAction = now+
delay;
long nextActionNotBefore
The minimum timestamp for the next notification.
void start()
Activates this instance.
final int delay
The delay between a call to trigger() until the eventSchedulerCallback is notified.
final Runnable runnable
The Runnable delivering notifications through eventSchedulerCallback.
A scheduler for synchronous event notifications.
final int afterEventDelay
The minimum delay between two eventSchedulerCallback notifications.
long nextAction
The timestamp for the next notification.
final Runnable eventSchedulerCallback
The Runnable to notify.
final Thread thread
The thread running runnable.
void trigger()
Notifies the callback.
final Object sync
The object used to synchronize access to nextAction and nextActionNotBefore.
EventScheduler(final int delay, final int afterEventDelay, @NotNull final Runnable eventSchedulerCallback)
Creates a new instance.