Package gaiasky.event

Class EventManager

java.lang.Object
gaiasky.event.EventManager
All Implemented Interfaces:
IObserver

public class EventManager
extends java.lang.Object
implements IObserver
Event manager that allows for subscription of observers to events (identified by strings), and also for the creation of event objects by anyone.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  EventManager.TimeFrame
    Time frame options
  • Field Summary

    Fields
    Modifier and Type Field Description
    static EventManager instance
    Singleton pattern
  • Constructor Summary

    Constructors
    Constructor Description
    EventManager()  
  • Method Summary

    Modifier and Type Method Description
    void clearAllSubscriptions()  
    void clearSubscriptions​(Events msg)
    Unregisters all the listeners for the specified message code.
    void dispatchDelayedMessages()
    Dispatches any telegrams with a timestamp that has expired.
    static long getCurrentTime()
    Returns the current time in milliseconds.
    boolean hasSubscriptors​(Events event)  
    boolean isSubscribedToAny​(IObserver o)  
    void notify​(Events event, java.lang.Object... data)  
    void post​(Events event, java.lang.Object... data)
    Posts or registers a new event type with the given data.
    void postDelayed​(Events event, long delayMs, EventManager.TimeFrame frame, java.lang.Object... data)
    Posts or registers a new event type with the given data.
    void postDelayed​(Events event, long delayMs, java.lang.Object... data)
    Posts or registers a new event type with the given data and the default time frame.
    void removeAllSubscriptions​(IObserver... listeners)
    Unregisters all the subscriptions of the given listeners.
    void subscribe​(IObserver listener, Events msg)
    Registers a listener for the specified message code.
    void subscribe​(IObserver observer, Events... events)
    Subscribes the given observer to the given event types.
    void unsubscribe​(IObserver listener, Events events)
    Unregister the specified listener for the specified message code.
    void unsubscribe​(IObserver listener, Events... events)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • instance

      public static final EventManager instance
      Singleton pattern
  • Constructor Details

    • EventManager

      public EventManager()
  • Method Details

    • subscribe

      public void subscribe​(IObserver observer, Events... events)
      Subscribes the given observer to the given event types.
      Parameters:
      observer - The observer to subscribe.
      events - The event types to subscribe to.
    • subscribe

      public void subscribe​(IObserver listener, Events msg)
      Registers a listener for the specified message code. Messages without an explicit receiver are broadcasted to all its registered listeners.
      Parameters:
      msg - the message code
      listener - the listener to add
    • unsubscribe

      public void unsubscribe​(IObserver listener, Events... events)
    • unsubscribe

      public void unsubscribe​(IObserver listener, Events events)
      Unregister the specified listener for the specified message code.
      Parameters:
      events - The message code.
      listener - The listener to remove.
    • removeAllSubscriptions

      public void removeAllSubscriptions​(IObserver... listeners)
      Unregisters all the subscriptions of the given listeners.
      Parameters:
      listeners - The listeners to remove.
    • clearSubscriptions

      public void clearSubscriptions​(Events msg)
      Unregisters all the listeners for the specified message code.
      Parameters:
      msg - the message code
    • clearAllSubscriptions

      public void clearAllSubscriptions()
    • post

      public void post​(Events event, java.lang.Object... data)
      Posts or registers a new event type with the given data.
      Parameters:
      event - The event type.
      data - The event data.
    • postDelayed

      public void postDelayed​(Events event, long delayMs, java.lang.Object... data)
      Posts or registers a new event type with the given data and the default time frame. The default time frame can be changed using the event Events.EVENT_TIME_FRAME_CMD. The event will be passed along after the specified delay time [ms] in the given time frame has passed.
      Parameters:
      event - The event type.
      delayMs - Milliseconds of delay in the given time frame.
      data - The event data.
    • postDelayed

      public void postDelayed​(Events event, long delayMs, EventManager.TimeFrame frame, java.lang.Object... data)
      Posts or registers a new event type with the given data. The event will be passed along after the specified delay time [ms] in the given time frame has passed.
      Parameters:
      event - The event type.
      delayMs - Milliseconds of delay in the given time frame.
      frame - The time frame, either real time (user) or simulation time (simulation clock time).
      data - The event data.
    • getCurrentTime

      public static long getCurrentTime()
      Returns the current time in milliseconds.
    • dispatchDelayedMessages

      public void dispatchDelayedMessages()
      Dispatches any telegrams with a timestamp that has expired. Any dispatched telegrams are removed from the queue.

      This method must be called each time through the main loop.

    • hasSubscriptors

      public boolean hasSubscriptors​(Events event)
    • isSubscribedToAny

      public boolean isSubscribedToAny​(IObserver o)
    • notify

      public void notify​(Events event, java.lang.Object... data)
      Specified by:
      notify in interface IObserver