Package gaiasky.event

Class EventManager

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

public class EventManager extends Object implements IObserver

This is the main manager of events within Gaia Sky. It enables the subscription of IObserver objects to specific events, and also the submission of events (optionally delayed).

See Event for information on the events.

  • Field Details

    • instance

      public static final EventManager instance
      Singleton pattern
  • Constructor Details

    • EventManager

      public EventManager()
  • Method Details

    • publish

      public static void publish(Event event, Object source, Object... data)
      Register a new event to the default event manager instance with the given source and data.
      Parameters:
      event - The event.
      source - The source object, if any.
      data - The event data.
    • publishDelayed

      public static void publishDelayed(Event event, Object source, long delayMs, Object... data)
      Register a new delayed event in the default manager with the given type, data, delay and the default time frame. The default time frame can be changed using the event Event.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.
      source - The source object, if any.
      delayMs - Milliseconds of delay in the given time frame.
      data - The event data.
    • publishWaitUntilConsumer

      public static void publishWaitUntilConsumer(Event event, Object source, Object... data)
      Register a new event with the given source and with the given data. The message is automatically dispatched if at least one consumer is present. Otherwise, it waits until a consumer is available.
      Parameters:
      event - The event.
      source - The source object, if any.
      data - The event data.
    • subscribe

      public void subscribe(IObserver observer, Event... events)
      Subscribe 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, Event msg)
      Register a listener for the specified message code. Messages without an explicit receiver are broadcast to all its registered listeners.
      Parameters:
      msg - the message code
      listener - the listener to add
    • unsubscribe

      public void unsubscribe(IObserver listener, Event... events)
    • unsubscribe

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

      public void removeAllSubscriptions(IObserver listener)
      Unregister all the subscriptions of the given listener.
      Parameters:
      listener - The listener to remove.
    • removeAllSubscriptions

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

      public void removeRadioSubscriptions(com.badlogic.ashley.core.Entity entity)
      Remove all subscriptions of EntityRadio for the given entity.
      Parameters:
      entity - The entity.
    • clearAllSubscriptions

      public void clearAllSubscriptions()
    • post

      public void post(Event event, Object source)
      Register a new data-less event with the given source.
      Parameters:
      event - The event.
      source - The source object, if any.
    • post

      public void post(Event event, Object source, Object... data)
      Register a new event with the given source and with the given data.
      Parameters:
      event - The event.
      source - The source object, if any.
      data - The event data.
    • postWaitUntilConsumer

      public void postWaitUntilConsumer(Event event, Object source, Object... data)
      Register a new event with the given source and with the given data. The message is automatically dispatched if at least one consumer is present. Otherwise, it waits until a consumer is available.
      Parameters:
      event - The event.
      source - The source object, if any.
      data - The event data.
    • postDelayed

      public void postDelayed(Event event, Object source, long delayMs, Object... data)
      Register a new delayed event with the given type, data, delay and the default time frame. The default time frame can be changed using the event Event.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.
      source - The source object, if any.
      delayMs - Milliseconds of delay in the given time frame.
      data - The event data.
    • postDelayed

      public void postDelayed(Event event, Object source, long delayMs, EventManager.TimeFrame frame, Object... data)
      Register a new event with the given type, data, delay and time frame. The event will be passed along after the specified delay time [ms] in the given time frame has passed.
      Parameters:
      event - The event.
      source - The source object, if any.
      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.
    • 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(Event event)
    • isSubscribedTo

      public boolean isSubscribedTo(IObserver o, Event event)
    • notify

      public void notify(Event event, Object source, Object... data)
      Description copied from interface: IObserver
      Event notification call.
      Specified by:
      notify in interface IObserver
      Parameters:
      event - The event type.
      source - The source object, if any.
      data - The data associated with this event.