Package gaiasky.event
Class EventManager
java.lang.Object
gaiasky.event.EventManager
- All Implemented Interfaces:
IObserver
Event manager that allows for subscription of observers to events (identified
by strings), and also for the creation of event objects by anyone. Events can also
be added to be processed with a delay.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclearSubscriptions(Events msg)Unregisters all the listeners for the specified message code.voidDispatches any telegrams with a timestamp that has expired.static longReturns the current time in milliseconds.booleanhasSubscriptors(Events event)booleanisSubscribedTo(IObserver o, Events event)booleanvoidEvent notification call.voidPosts or registers a new event type with the given data.voidpostDelayed(Events event, long delayMs, EventManager.TimeFrame frame, Object... data)Posts or registers a new event type with the given data.voidpostDelayed(Events event, long delayMs, Object... data)Posts or registers a new event type with the given data and the default time frame.voidremoveAllSubscriptions(IObserver... listeners)Unregisters all the subscriptions of the given listeners.voidRegisters a listener for the specified message code.voidSubscribes the given observer to the given event types.voidunsubscribe(IObserver listener, Events events)Unregister the specified listener for the specified message code.voidunsubscribe(IObserver listener, Events... events)
-
Field Details
-
instance
Singleton pattern
-
-
Constructor Details
-
EventManager
public EventManager()
-
-
Method Details
-
subscribe
Subscribes the given observer to the given event types.- Parameters:
observer- The observer to subscribe.events- The event types to subscribe to.
-
subscribe
Registers a listener for the specified message code. Messages without an explicit receiver are broadcast to all its registered listeners.- Parameters:
msg- the message codelistener- the listener to add
-
unsubscribe
-
unsubscribe
Unregister the specified listener for the specified message code.- Parameters:
events- The message code.listener- The listener to remove.
-
removeAllSubscriptions
Unregisters all the subscriptions of the given listeners.- Parameters:
listeners- The listeners to remove.
-
clearSubscriptions
Unregisters all the listeners for the specified message code.- Parameters:
msg- the message code
-
clearAllSubscriptions
public void clearAllSubscriptions() -
post
Posts or registers a new event type with the given data.- Parameters:
event- The event type.data- The event data.
-
postDelayed
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 eventEvents.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
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
-
isSubscribedToAny
-
isSubscribedTo
-
notify
Description copied from interface:IObserverEvent notification call.
-