com.realtime.crossfire.jxclient.items
Class EventScheduler

java.lang.Object
  extended by com.realtime.crossfire.jxclient.items.EventScheduler

public class EventScheduler
extends java.lang.Object

A scheduler for synchronous event notifications. Notifications are triggered by calling trigger(). Notifications are delivered by calling the event scheduler callback of eventSchedulerCallback. This callback is called delay after the last call to trigger() but not faster than once per eventSchedulerCallback.


Field Summary
private  int afterEventDelay
          The minimum delay between two eventSchedulerCallback notifications.
private  int delay
          The delay between a call to trigger() until the eventSchedulerCallback is notified.
private  java.lang.Runnable eventSchedulerCallback
          The Runnable to notify.
private  long nextAction
          The timestamp for the next notification.
private  long nextActionNotBefore
          The minimum timestamp for the next notification.
private  java.lang.Runnable runnable
          The Runnable delivering notifications through eventSchedulerCallback.
private  java.lang.Object sync
          The object used to synchronize access to nextAction and nextActionNotBefore.
private  java.lang.Thread thread
          The thread running runnable.
 
Constructor Summary
EventScheduler(int delay, int afterEventDelay, java.lang.Runnable eventSchedulerCallback)
          Creates a new instance.
 
Method Summary
 void start()
          Activates this instance.
 void trigger()
          Notifies the callback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

afterEventDelay

private final int afterEventDelay
The minimum delay between two eventSchedulerCallback notifications.


delay

private final int delay
The delay between a call to trigger() until the eventSchedulerCallback is notified.


eventSchedulerCallback

@NotNull
private final java.lang.Runnable eventSchedulerCallback
The Runnable to notify.


nextAction

private long nextAction
The timestamp for the next notification. Set to 0 when not active.


nextActionNotBefore

private long nextActionNotBefore
The minimum timestamp for the next notification.


runnable

@NotNull
private final java.lang.Runnable runnable
The Runnable delivering notifications through eventSchedulerCallback.


sync

@NotNull
private final java.lang.Object sync
The object used to synchronize access to nextAction and nextActionNotBefore.


thread

@NotNull
private final java.lang.Thread thread
The thread running runnable.

Constructor Detail

EventScheduler

public EventScheduler(int delay,
                      int afterEventDelay,
                      @NotNull
                      java.lang.Runnable eventSchedulerCallback)
Creates a new instance.

Parameters:
delay - the initial delay
afterEventDelay - the "after-event" delay
eventSchedulerCallback - the callback to notify
Method Detail

start

public void start()
Activates this instance.


trigger

public void trigger()
Notifies the callback.