com.realtime.crossfire.jxclient.timeouts
Class Timeouts

java.lang.Object
  extended by com.realtime.crossfire.jxclient.timeouts.Timeouts

public class Timeouts
extends java.lang.Object

Manages a list of timeouts. Client code can register timeouts with add(int, TimeoutEvent) or reset(int, TimeoutEvent). These timeout events are called after the given timeout has expired.


Field Summary
private static java.lang.Runnable DELIVER_PENDING_TIMEOUTS
          The thread that delivers timeout events.
private static java.util.PriorityQueue<Event> EVENTS
          Contains all pending timeout events.
private static java.util.Map<TimeoutEvent,Event> TIMEOUT_EVENTS
          Maps TimeoutEvent instance to Event instance.
 
Constructor Summary
private Timeouts()
          Private constructor to prevent instantiation.
 
Method Summary
private static void add(int timeout, TimeoutEvent timeoutEvent)
          Add a timeout event.
static void remove(TimeoutEvent timeoutEvent)
          Remove a timeout event.
static void reset(int timeout, TimeoutEvent timeoutEvent)
          Set the timeout value for a given event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELIVER_PENDING_TIMEOUTS

@NotNull
private static final java.lang.Runnable DELIVER_PENDING_TIMEOUTS
The thread that delivers timeout events.


EVENTS

@NotNull
private static final java.util.PriorityQueue<Event> EVENTS
Contains all pending timeout events. The head element is the next event to deliver.


TIMEOUT_EVENTS

@NotNull
private static final java.util.Map<TimeoutEvent,Event> TIMEOUT_EVENTS
Maps TimeoutEvent instance to Event instance. This information is necessary for removing active timeouts.

Constructor Detail

Timeouts

private Timeouts()
Private constructor to prevent instantiation.

Method Detail

add

private static void add(int timeout,
                        @NotNull
                        TimeoutEvent timeoutEvent)
Add a timeout event.

Parameters:
timeout - The timeout in milliseconds.
timeoutEvent - The timeout event to execute.

remove

public static void remove(@NotNull
                          TimeoutEvent timeoutEvent)
Remove a timeout event. If the timeout event is not active, nothing happens.

Parameters:
timeoutEvent - The timeout event to remove.

reset

public static void reset(int timeout,
                         @NotNull
                         TimeoutEvent timeoutEvent)
Set the timeout value for a given event. If the event is not yet pending, it is added.

Parameters:
timeout - The new timeout in milliseconds.
timeoutEvent - The timeout event to execute.