de.novanic.eventservice.service.registry
Class DefaultEventRegistry

java.lang.Object
  extended by de.novanic.eventservice.service.registry.DefaultEventRegistry
All Implemented Interfaces:
ListenDomainAccessor, EventRegistry

public class DefaultEventRegistry
extends java.lang.Object
implements EventRegistry, ListenDomainAccessor

The EventRegistry handles the users/clients and the events per domain. Users can be registered for a domain/context to receive events for the according domain. User specific events can be handled domain-less, when the user is registered. The EventRegistry is used by EventServiceImpl.
The client id is required, because the connection to every client must be kept open.

Author:
sstrohschein
Date: 05.06.2008
Time: 19:12:35
See Also:
EventServiceImpl

Constructor Summary
protected DefaultEventRegistry(EventServiceConfiguration aConfiguration)
          Creates a new EventRegistry with a configuration (EventServiceConfiguration).
 
Method Summary
 void addEvent(Domain aDomain, Event anEvent)
          Adds an event to a domain.
 void addEventUserSpecific(java.lang.String aUserId, Event anEvent)
          Adds an event directly to a user.
 EventServiceConfiguration getConfiguration()
          Returns the initialized EventServiceConfiguration
 EventFilter getEventFilter(Domain aDomain, java.lang.String aUserId)
          Returns the EventFilter for the user domain combination.
 java.util.Set<Domain> getListenDomains()
          Returns all registered/activated domains.
 java.util.Set<Domain> getListenDomains(java.lang.String aUserId)
          Returns all domains where the user is registered to.
 java.util.Set<java.lang.String> getRegisteredUserIds()
          Returns all registered users/clients.
 java.util.Set<java.lang.String> getRegisteredUserIds(Domain aDomain)
          Returns all registered users/client of a specific Domain.
 boolean isUserRegistered(Domain aDomain, java.lang.String aUserId)
          Checks if the user is registered for the corresponding domain.
 boolean isUserRegistered(java.lang.String aUserId)
          Checks if the user is registered for any domain.
 java.util.List<DomainEvent> listen(java.lang.String aUserId)
          The listen method returns all events for the user (events for all domains where the user is registered and user specific events).
 void registerUnlistenEvent(java.lang.String aUserId, UnlistenEventListener.Scope anUnlistenScope, UnlistenEvent anUnlistenEvent)
          Registers an UnlistenEvent which is triggered on a timeout or when a user/client leaves a Domain.
 void registerUser(Domain aDomain, java.lang.String aUserId, EventFilter anEventFilter)
          Registers a user for listening for the corresponding domain.
 void removeEventFilter(Domain aDomain, java.lang.String aUserId)
          EventFilters can be removed for a user domain combination with that method.
 void setEventFilter(Domain aDomain, java.lang.String aUserId, EventFilter anEventFilter)
          The EventFilter for a user domain combination can be set or changed with that method.
 void unlisten(Domain aDomain, java.lang.String aUserId)
          This method causes a stop of listening for a domain (listen(String)).
 void unlisten(java.lang.String aUserId)
          This method causes a stop of listening for all domains (listen(String)).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultEventRegistry

protected DefaultEventRegistry(EventServiceConfiguration aConfiguration)
Creates a new EventRegistry with a configuration (EventServiceConfiguration). The EventRegistryFactory should be used instead of calling that constructor directly.

Parameters:
aConfiguration - configuration
See Also:
EventRegistryFactory.getEventRegistry()
Method Detail

isUserRegistered

public boolean isUserRegistered(java.lang.String aUserId)
Checks if the user is registered for any domain.

Specified by:
isUserRegistered in interface EventRegistry
Parameters:
aUserId - the user to check
Returns:
true if registered, false if not registered

isUserRegistered

public boolean isUserRegistered(Domain aDomain,
                                java.lang.String aUserId)
Checks if the user is registered for the corresponding domain.

Specified by:
isUserRegistered in interface EventRegistry
Parameters:
aDomain - the domain to check
aUserId - the user to check
Returns:
true if registered, false if not registered

registerUser

public void registerUser(Domain aDomain,
                         java.lang.String aUserId,
                         EventFilter anEventFilter)
Registers a user for listening for the corresponding domain. From now all events for the domain are recognized and will be returned when listen (listen(String)) is called. The EventFilter is optional and can be NULL.

Specified by:
registerUser in interface EventRegistry
Parameters:
aDomain - the domain to listen
aUserId - the user to register
anEventFilter - EventFilter to filter the domain events (optional, can be NULL)

setEventFilter

public void setEventFilter(Domain aDomain,
                           java.lang.String aUserId,
                           EventFilter anEventFilter)
The EventFilter for a user domain combination can be set or changed with that method. The EventFilter can be removed with the method EventRegistry.removeEventFilter(de.novanic.eventservice.client.event.domain.Domain, String) or when that method is called with NULL as the EventFilter parameter value.

Specified by:
setEventFilter in interface EventRegistry
Parameters:
aDomain - domain
aUserId - user
anEventFilter - new EventFilter

getEventFilter

public EventFilter getEventFilter(Domain aDomain,
                                  java.lang.String aUserId)
Returns the EventFilter for the user domain combination.

Specified by:
getEventFilter in interface EventRegistry
Parameters:
aDomain - domain
aUserId - user
Returns:
EventFilter for the domain

removeEventFilter

public void removeEventFilter(Domain aDomain,
                              java.lang.String aUserId)
EventFilters can be removed for a user domain combination with that method.

Specified by:
removeEventFilter in interface EventRegistry
Parameters:
aDomain - domain
aUserId - user

listen

public java.util.List<DomainEvent> listen(java.lang.String aUserId)
The listen method returns all events for the user (events for all domains where the user is registered and user specific events). If no events are available, the method waits a defined time before the events are returned. The listen method is designed for the EventService functionality. The client side calls the method with a defined interval to receive all events. If the client don't call the method in the interval, the user will be removed from the EventRegistry. The timeout time and the min. and max. waiting time can be configured by EventServiceConfiguration.

Specified by:
listen in interface EventRegistry
Parameters:
aUserId - user
Returns:
list of events

unlisten

public void unlisten(Domain aDomain,
                     java.lang.String aUserId)
This method causes a stop of listening for a domain (listen(String)).

Specified by:
unlisten in interface EventRegistry
Parameters:
aDomain - domain to stop listening
aUserId - user

unlisten

public void unlisten(java.lang.String aUserId)
This method causes a stop of listening for all domains (listen(String)).

Specified by:
unlisten in interface EventRegistry
Parameters:
aUserId - user

getListenDomains

public java.util.Set<Domain> getListenDomains(java.lang.String aUserId)
Returns all domains where the user is registered to.

Specified by:
getListenDomains in interface ListenDomainAccessor
Specified by:
getListenDomains in interface EventRegistry
Parameters:
aUserId - user id
Returns:
domains where the user is registered to

getListenDomains

public java.util.Set<Domain> getListenDomains()
Returns all registered/activated domains.

Specified by:
getListenDomains in interface ListenDomainAccessor
Specified by:
getListenDomains in interface EventRegistry
Returns:
all registered/activated domains

getRegisteredUserIds

public java.util.Set<java.lang.String> getRegisteredUserIds()
Returns all registered users/clients. To get only the registered users/client of a specific Domain, the method EventRegistry.getRegisteredUserIds(de.novanic.eventservice.client.event.domain.Domain) can be used instead.

Specified by:
getRegisteredUserIds in interface EventRegistry
Returns:
registered users/clients

getRegisteredUserIds

public java.util.Set<java.lang.String> getRegisteredUserIds(Domain aDomain)
Returns all registered users/client of a specific Domain. To get all the registered users/client (of all domains), the method EventRegistry.getRegisteredUserIds() can be used instead.

Specified by:
getRegisteredUserIds in interface EventRegistry
Parameters:
aDomain - domain
Returns:
registered users/client of the specific domain

addEvent

public void addEvent(Domain aDomain,
                     Event anEvent)
Adds an event to a domain.

Specified by:
addEvent in interface EventRegistry
Parameters:
aDomain - domain for the event
anEvent - event to add

addEventUserSpecific

public void addEventUserSpecific(java.lang.String aUserId,
                                 Event anEvent)
Adds an event directly to a user. The user must be registered to any domain.

Specified by:
addEventUserSpecific in interface EventRegistry
Parameters:
aUserId - user
anEvent - event

registerUnlistenEvent

public void registerUnlistenEvent(java.lang.String aUserId,
                                  UnlistenEventListener.Scope anUnlistenScope,
                                  UnlistenEvent anUnlistenEvent)
Registers an UnlistenEvent which is triggered on a timeout or when a user/client leaves a Domain. An UnlistenEvent is hold at the server side and can contain custom data. Other users/clients can use the custom data when the event is for example triggered by a timeout.

Specified by:
registerUnlistenEvent in interface EventRegistry
Parameters:
aUserId - user to register the UnlistenEvent to
anUnlistenScope - scope of the unlisten events to receive
anUnlistenEvent - UnlistenEvent which should be transferred to other users/clients when a timeout occurs or a domain is leaved.

getConfiguration

public EventServiceConfiguration getConfiguration()
Returns the initialized EventServiceConfiguration

Specified by:
getConfiguration in interface EventRegistry
Returns:
configuration EventServiceConfiguration