at.spardat.xma.event.global
Class GlobalEventManager

java.lang.Object
  extended byat.spardat.xma.event.global.GlobalEventManager

public class GlobalEventManager
extends java.lang.Object

This singleton class serves for creating, sending and polling GlobalEvents. To send an event means to store it for this server in an GlobalEventmanager internal Map, for the accesss of other servers the events are also stored in an JNDI tree. Polling means to ask the map and the JNDI tree for undelivered events and to return a collection with them. GlobalEventListener for the server side GlobalEvents have to be registerd at this class (addGlobalEventListener()). GlobalEventListener for the client side GlobalEvents have to be registerd at the XMASessionClient (addGlobalEventListener()).

Since:
version_number

Method Summary
 void addGlobalEventListener(GlobalEventListener listener)
          The added GlobalEventListener will be notifyed by server events (recipient = RECIPIENT_ALL_SERVERS).
 GlobalEvent createGlobalEvent(java.lang.String name)
          creates a GlobalEvent with the given name, the default recipient type (RECIPIENT_ALL_CLIENTS_ALL_SERVERS) and the default expiration date (now + 1 day).
 GlobalEvent createGlobalEvent(java.lang.String name, int recipient)
          creates a GlobalEvent with the given name, recipient type and the default expiration date (now + 1 day).
 GlobalEvent createGlobalEvent(java.lang.String name, int recipient, long expiresMilliSec)
          creates a GlobalEvent with the given name, recipient type and the given expiration date.
 GlobalEvent createGlobalEvent(java.lang.String name, int recipient, long expiresMilliSec, java.lang.String sessionId)
          creates a GlobalEvent with the given name, recipient type, the given expiration date and the given session id.
 GlobalEvent createGlobalEventTTL(java.lang.String name, int recipient, long timeToLiveMilliSec)
          creates a GlobalEvent with the given name, the given recipient type and the time from now how long this event is valid.
 GlobalEvent createGlobalEventTTL(java.lang.String name, int recipient, long timeToLiveMilliSec, java.lang.String sessionId)
          creates a GlobalEvent with the given name, the given recipient type and the time from now how long this event is valid.
 GlobalEvent createGlobalEventTTL(java.lang.String name, long timeToLiveMilliSec)
          creates a GlobalEvent with the given name, the default recipient type (RECIPIENT_ALL_CLIENTS_ALL_SERVERS) and the time from now how long this event is valid.
static GlobalEventManager getInstance()
          Returns a singleton GlobalEventManager object.
static boolean isGlobalEventActivated()
          Queries for the property: at.spardat.xma.activateGlobalEvents=true Is called after every RPC before GlobalEventManager.getInstance().pollEvents() to ommit unneccesary JNDI queries.
 java.util.Collection pollEvents()
          Returns a Collection of GlobalEvents for the client.
 void pollServerSideEvents()
          Polls for new GlobalEvents with myServerHighCounts and iterates over the registered sever side GlobalEventsListers.
 boolean removeGlobalEventListener(GlobalEventListener listener)
          removes the GlobalEventListener.
 void send(GlobalEvent event)
          Sends this given event to the global data structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static GlobalEventManager getInstance()
Returns a singleton GlobalEventManager object. Can only be called if xma.runtime.activateGlobalEvents!="false" ("false" is default).

Returns:
@since version_number
Throws:
at.spardat.enterprise.exc.SysException - - if xma.runtime.activateGlobalEvents is set to "false"

addGlobalEventListener

public void addGlobalEventListener(GlobalEventListener listener)
The added GlobalEventListener will be notifyed by server events (recipient = RECIPIENT_ALL_SERVERS).

Parameters:
listener -
Since:
version_number

removeGlobalEventListener

public boolean removeGlobalEventListener(GlobalEventListener listener)
removes the GlobalEventListener.

Parameters:
listener -
Returns:
true: if a listener was removed, false otherwise.
Since:
version_number

createGlobalEvent

public GlobalEvent createGlobalEvent(java.lang.String name)
creates a GlobalEvent with the given name, the default recipient type (RECIPIENT_ALL_CLIENTS_ALL_SERVERS) and the default expiration date (now + 1 day).

Parameters:
name - type of GlobalEvent
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEvent

public GlobalEvent createGlobalEvent(java.lang.String name,
                                     int recipient)
creates a GlobalEvent with the given name, recipient type and the default expiration date (now + 1 day).

Parameters:
name - type of GlobalEvent
recipient - type of recipient: RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS, RECIPIENT_ALL_CLIENTS_ALL_SERVERS
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEvent

public GlobalEvent createGlobalEvent(java.lang.String name,
                                     int recipient,
                                     long expiresMilliSec)
creates a GlobalEvent with the given name, recipient type and the given expiration date.

Parameters:
name - type of GlobalEvent
recipient - type of recipient: RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS, RECIPIENT_ALL_CLIENTS_ALL_SERVERS
expiresMilliSec - milli seconds after 1970
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEvent

public GlobalEvent createGlobalEvent(java.lang.String name,
                                     int recipient,
                                     long expiresMilliSec,
                                     java.lang.String sessionId)
creates a GlobalEvent with the given name, recipient type, the given expiration date and the given session id. The session ID should be given if the creator of the event is the only recipient. So when the session ID is stated then as recipients only GlobalEvent.RECIPIENT_BY_ID (only the listeners of the client with this session ID are called) or RECIPIENT_ALL_SERVERS (only the listeners of all servers and the listeners of the client with this ID are called) make sense. (The session ID it will be evaluated by the GlobalEvent.isEventForClient(String idSession) method.)

Parameters:
name - type of GlobalEvent
recipient - type of recipient: RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS, RECIPIENT_ALL_CLIENTS_ALL_SERVERS
expiresMilliSec - milli seconds after 1970
sessionId - - usually session id of creator.
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEventTTL

public GlobalEvent createGlobalEventTTL(java.lang.String name,
                                        long timeToLiveMilliSec)
creates a GlobalEvent with the given name, the default recipient type (RECIPIENT_ALL_CLIENTS_ALL_SERVERS) and the time from now how long this event is valid.

Parameters:
name - type of GlobalEvent
timeToLiveMilliSec - - milli seconds (from now) in which this event expires.
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEventTTL

public GlobalEvent createGlobalEventTTL(java.lang.String name,
                                        int recipient,
                                        long timeToLiveMilliSec)
creates a GlobalEvent with the given name, the given recipient type and the time from now how long this event is valid.

Parameters:
name - type of GlobalEvent
recipient - type of recipient: RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS, RECIPIENT_ALL_CLIENTS_ALL_SERVERS
timeToLiveMilliSec - milli seconds (from now) in which this event expires.
Returns:
a new created GlobalEvent
Since:
version_number

createGlobalEventTTL

public GlobalEvent createGlobalEventTTL(java.lang.String name,
                                        int recipient,
                                        long timeToLiveMilliSec,
                                        java.lang.String sessionId)
creates a GlobalEvent with the given name, the given recipient type and the time from now how long this event is valid. The session ID should be given if the creator of the event is the only recipient. So when the session ID is stated then as recipients only GlobalEvent.RECIPIENT_BY_ID (only the listeners of the client with this session ID are called) or RECIPIENT_ALL_SERVERS (only the listeners of all servers and the listeners of the client with this ID are called) make sense. (The session ID it will be evaluated by the GlobalEvent.isEventForClient(String idSession) method.)

Parameters:
name - type of GlobalEvent
recipient - type of recipient: RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS, RECIPIENT_ALL_CLIENTS_ALL_SERVERS
timeToLiveMilliSec - milli seconds (from now) in which this event expires.
sessionId - - usually session id of creator.
Returns:
a new created GlobalEvent
Since:
version_number

send

public void send(GlobalEvent event)
Sends this given event to the global data structure. The event is then stored an can be retrieved by pollEvents().

Parameters:
event -
Throws:
java.lang.RuntimeException - if XProperty 'at.spardat.xma.activateGlobalEvents=true' is not set.
Since:
version_number

pollEvents

public java.util.Collection pollEvents()
Returns a Collection of GlobalEvents for the client. Server side events are transmitted to the registered server side GlobalEventListener. Only events are returned which were not already transmitted to the client or the server.

Returns:
a Collection of GlobalEvents.
Since:
version_number

pollServerSideEvents

public void pollServerSideEvents()
Polls for new GlobalEvents with myServerHighCounts and iterates over the registered sever side GlobalEventsListers. Usually this method is implicitly called in pollEvents(). But pollEvents() itself is only called if an XMA remote call is answered by the server. To poll for server side events independently from XMA remote calls this method can be used.

Since:
version_number

isGlobalEventActivated

public static boolean isGlobalEventActivated()
Queries for the property: at.spardat.xma.activateGlobalEvents=true Is called after every RPC before GlobalEventManager.getInstance().pollEvents() to ommit unneccesary JNDI queries. Should also be called before every GlobalEventManager.getInstance().pollServerSideEvents().

Returns:
true if at.spardat.xma.activateGlobalEvents != "false" is set.
Since:
version_number