hu.mta.sztaki.lpds.cloud.simulator.notifications
Class StateDependentEventHandler<T,P>

java.lang.Object
  extended by hu.mta.sztaki.lpds.cloud.simulator.notifications.StateDependentEventHandler<T,P>
Type Parameters:
T - the kind of state change for which this handler is prepared to notify about.

public class StateDependentEventHandler<T,P>
extends Object

The main non-time dependent event handling mechanism in DISSECT-CF. This class is kept generic, and every user could either derive from it or use this as an embedded object. It is expected that the user of this class will want to deliver notifications about its internal state changes. The kind of state changes possible are not known by this generic mechanism, but the user of this class is expected to express this via the generic parameter of the class. The individual notifications can be customized via the class's constructor.

Author:
"Gabor Kecskemeti, Laboratory of Parallel and Distributed Systems, MTA SZTAKI (c) 2015"

Field Summary
private  ArrayList<T> cancelledListeners
           
private  ArrayList<T> listeners
           
private  SingleNotificationHandler<T,P> myHandler
           
private  ArrayList<T> newListeners
           
private  boolean noEventDispatchingInProcess
           
 
Constructor Summary
StateDependentEventHandler(SingleNotificationHandler<T,P> handler)
          Initialization of the event handling mechanism.
 
Method Summary
private  void mainNotificationLoop(P payload)
          The main event dispatching loop.
 void notifyListeners(P payload)
          Sends out the notifications via the user defined event handler for all currently listed listeners.
 void subscribeToEvents(T listener)
          To get state dependent events one must subscribe to them via this function.
 void unsubscribeFromEvents(T listener)
          If there are no events needed for a particular listener then they can be cancelled here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

private ArrayList<T> listeners

newListeners

private ArrayList<T> newListeners

cancelledListeners

private ArrayList<T> cancelledListeners

noEventDispatchingInProcess

private boolean noEventDispatchingInProcess

myHandler

private final SingleNotificationHandler<T,P> myHandler
Constructor Detail

StateDependentEventHandler

public StateDependentEventHandler(SingleNotificationHandler<T,P> handler)
Initialization of the event handling mechanism.

Parameters:
handler - via this interface's implementation will the actual observed object be capable of dispatching custom events abouts its state change
Method Detail

subscribeToEvents

public void subscribeToEvents(T listener)
To get state dependent events one must subscribe to them via this function. The listener will be called every time when the observed object changes its particular state and uses the notifylisteners function below.

Parameters:
listener - who should receive notifications upon state changes in the observed object

unsubscribeFromEvents

public void unsubscribeFromEvents(T listener)
If there are no events needed for a particular listener then they can be cancelled here.

Parameters:
listener - the listener which does not need the state related events anymore

mainNotificationLoop

private void mainNotificationLoop(P payload)
The main event dispatching loop. It is not intended for external use as it is not prepared to handle cases when the number of subscribers change while the dispatching is in process.


notifyListeners

public void notifyListeners(P payload)
Sends out the notifications via the user defined event handler for all currently listed listeners. If there are new/cancelled subscriptions then they are added/removed to/from the list of listeners at the end of the event dispatching loop.



Copyright © 2012–2015 University of Innsbruck & MTA SZTAKI. All rights reserved.