org.sapia.ubik.mcast
Class EventConsumer

java.lang.Object
  extended by org.sapia.ubik.mcast.EventConsumer

public class EventConsumer
extends java.lang.Object

Helper class that encasulates AsyncEventListeners and SyncEventListeners, grouping them by "event type". This class implements the dispatching of remote events to the encapsulated listeners.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
See Also:
AsyncEventListener, SyncEventListener, DomainName

Constructor Summary
EventConsumer(java.lang.String domain)
          Creates an instance of this class with the given domain.
EventConsumer(java.lang.String node, java.lang.String domain)
          Creates an instance of this class, with the given node identifier, and the given domain.
 
Method Summary
protected  boolean contains(java.util.List listeners, AsyncEventListener listener)
           
 boolean containsAsyncListener(AsyncEventListener listener)
          Returns true if the passed in listener is held within this instance.
 boolean containsSyncListener(SyncEventListener listener)
          Returns true if the given listener is contained by this instance.
 int getCount()
          Returns the number of listeners within this instance.
 DomainName getDomainName()
          Returns the object that represents this instance's domain name.
 java.lang.String getNode()
          Returns the node identifier of this instance.
 boolean hasSyncListener(java.lang.String evtType)
          Checks if a SyncEventListener exists for the given event type
protected  boolean matchesAll(DomainName dn, java.lang.String node)
           
protected  boolean matchesThis(DomainName dn, java.lang.String node)
           
protected  void onAsyncEvent(RemoteEvent evt)
           
protected  java.lang.Object onSyncEvent(RemoteEvent evt)
           
 void registerAsyncListener(java.lang.String evtType, AsyncEventListener listener)
          Registers the given listener with the given "logical" event type.
 void registerSyncListener(java.lang.String evtType, SyncEventListener listener)
          Registers the given listener with the given "logical" event type.
 void unregisterListener(AsyncEventListener listener)
          Removes the given listener from this instance.
 void unregisterListener(SyncEventListener listener)
          Removes the given listener from this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventConsumer

public EventConsumer(java.lang.String node,
                     java.lang.String domain)
Creates an instance of this class, with the given node identifier, and the given domain.


EventConsumer

public EventConsumer(java.lang.String domain)
              throws java.net.UnknownHostException
Creates an instance of this class with the given domain. Internally creates a globally unique node identifier.

Throws:
java.net.UnknownHostException
Method Detail

getNode

public java.lang.String getNode()
Returns the node identifier of this instance.

Returns:
this instance's node idenfier.

getDomainName

public DomainName getDomainName()
Returns the object that represents this instance's domain name.

Returns:
this instance's DomainName

registerAsyncListener

public void registerAsyncListener(java.lang.String evtType,
                                  AsyncEventListener listener)
Registers the given listener with the given "logical" event type.

Parameters:
evtType - a logical event type.
listener - an AsyncEventListener.

registerSyncListener

public void registerSyncListener(java.lang.String evtType,
                                 SyncEventListener listener)
                          throws ListenerAlreadyRegisteredException
Registers the given listener with the given "logical" event type.

Parameters:
evtType - a logical event type.
listener - a SyncEventListener.
Throws:
ListenerAlreadyRegisteredException

unregisterListener

public void unregisterListener(SyncEventListener listener)
Removes the given listener from this instance.

Parameters:
listener - the SyncEventListener to remove.

unregisterListener

public void unregisterListener(AsyncEventListener listener)
Removes the given listener from this instance.

Parameters:
listener - the AsyncEventListener to remove.

containsAsyncListener

public boolean containsAsyncListener(AsyncEventListener listener)
Returns true if the passed in listener is held within this instance.

Parameters:
listener - an AsyncEventListener
Returns:
true if the passed in listener is held within this instance.

hasSyncListener

public boolean hasSyncListener(java.lang.String evtType)
Checks if a SyncEventListener exists for the given event type

Parameters:
evtType - the type of event for which to perform the check.
Returns:
true if a SyncEventListener exists for the given event type.

containsSyncListener

public boolean containsSyncListener(SyncEventListener listener)
Returns true if the given listener is contained by this instance.

Parameters:
listener - a SyncEventListener.
Returns:
true if the given listener is contained by this instance.

getCount

public int getCount()
Returns the number of listeners within this instance.

Returns:
the number of listeners within this instance.

onAsyncEvent

protected void onAsyncEvent(RemoteEvent evt)

matchesAll

protected boolean matchesAll(DomainName dn,
                             java.lang.String node)

matchesThis

protected boolean matchesThis(DomainName dn,
                              java.lang.String node)

onSyncEvent

protected java.lang.Object onSyncEvent(RemoteEvent evt)

contains

protected boolean contains(java.util.List listeners,
                           AsyncEventListener listener)


Copyright © 2010 Sapia OSS. All Rights Reserved.