fulmine.event.subscription
Class Subscription

java.lang.Object
  extended by fulmine.event.subscription.Subscription
All Implemented Interfaces:
ISubscription, ISubscriptionParameters, IAddressable, IDestroyable
Direct Known Subclasses:
ContainerSubscription

public class Subscription
extends Object
implements ISubscription

The base implementation of a subscription.

Thread safe.

Author:
Ramon Servadei

Field Summary
 
Fields inherited from interface fulmine.event.subscription.ISubscription
WILDCARD_DOMAIN, WILDCARD_ID_REGEX, WILDCARD_TYPE
 
Constructor Summary
protected Subscription(ISubscriptionParameters parameters)
          Construct the subscription to match the subscription passed in.
 
Method Summary
 boolean addListener(IEventListener listener)
          Add the listener to the IEventListener instances associated with this ISubscription.
 boolean addMatch(IEventSource source)
          Add the event source as a matched reference.
 void destroy()
          This is called when the object is being removed from application use.
protected  boolean doAddOperation(IEventSource source)
          Template method for the operation to perform when a source match is added.
protected  boolean doRemoveOperation(IEventSource source)
          Template method for the operation to perform when a source match is removed.
 boolean equals(Object obj)
           
 String getAddress()
          Get the unique address for this.
 IDomain getDomain()
          Get the domain attribute of this object.
 String getIdentity()
          Get the identification string for this entity.
 List<IEventListener> getListeners()
          Get a copy of the internal List of all the IEventListener instances used by the subscription to register against the subscribed IEventSource instances.
protected  org.apache.commons.logging.Log getLog()
           
 Collection<IEventSource> getMatches()
          Get a copy of the internal Collection of all the IEventSource instances referenced by this subscription.
 IType getType()
          Get the type attribute of this object.
 int hashCode()
           
 boolean includes(IAddressable parameters)
          Determine if the IAddressable attributes of this parameters instance would include those of another.
 boolean removeListener(IEventListener listener)
          Remove the listener from the IEventListener instances associated with this ISubscription.
 boolean removeMatch(ISubscriptionParameters parameters)
          Remove the event source(s) identified by the parameters from this subscription's matched references.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Subscription

protected Subscription(ISubscriptionParameters parameters)
Construct the subscription to match the subscription passed in.

Parameters:
subscription - the subscription subscription for this
Method Detail

addMatch

public final boolean addMatch(IEventSource source)
Description copied from interface: ISubscription
Add the event source as a matched reference.

The source is only added if the subscription does not already contain the source as a match.

This is an idempotent operation.

Specified by:
addMatch in interface ISubscription
Parameters:
source - the event source
Returns:
true if the event source was added, false if the subscription already has the source as a matched reference

removeMatch

public final boolean removeMatch(ISubscriptionParameters parameters)
Description copied from interface: ISubscription
Remove the event source(s) identified by the parameters from this subscription's matched references.

Note: if the parameters include wildcards, multiple event sources may be removed.

Specified by:
removeMatch in interface ISubscription
Parameters:
parameters - the subscription parameters identifying any matching event sources to remove
Returns:
true if at least one event source was found and removed, false if no event source was found to remove

getMatches

public final Collection<IEventSource> getMatches()
Description copied from interface: ISubscription
Get a copy of the internal Collection of all the IEventSource instances referenced by this subscription. The order of the collection elements is arbitrary.

Specified by:
getMatches in interface ISubscription
Returns:
a copy of the collection of all IEventSource instances referenced by this subscription

getListeners

public final List<IEventListener> getListeners()
Description copied from interface: ISubscription
Get a copy of the internal List of all the IEventListener instances used by the subscription to register against the subscribed IEventSource instances.

Specified by:
getListeners in interface ISubscription
Returns:
a copy of the internal List of all the listeners that are registered against all subscribed IEventSource instances. The order of the listeners is the order of calling ISubscription.addListener(IEventListener).

addListener

public final boolean addListener(IEventListener listener)
Description copied from interface: ISubscription
Add the listener to the IEventListener instances associated with this ISubscription. The subscription will register the listener with any currently matched IEventSource instances.

This is an idempotent operation.

Specified by:
addListener in interface ISubscription
Parameters:
listener - the listener to add to the subscription's list of listeners
Returns:
true if the listener was added, false if it already existed

removeListener

public final boolean removeListener(IEventListener listener)
Description copied from interface: ISubscription
Remove the listener from the IEventListener instances associated with this ISubscription. The subscription will remove the listener from any currently matched IEventSource instances.

This is an idempotent operation.

Specified by:
removeListener in interface ISubscription
Parameters:
listener - the listener to remove from the subscription's list of listeners
Returns:
true if the listener was removed, false if it was not found

getDomain

public final IDomain getDomain()
Description copied from interface: IAddressable
Get the domain attribute of this object. The domain is orthogonal to the type.

Specified by:
getDomain in interface IAddressable
Returns:
the domain of this object
See Also:
IAddressable.getType()

getIdentity

public final String getIdentity()
Description copied from interface: IAddressable
Get the identification string for this entity. This is unique within the type and domain.

Specified by:
getIdentity in interface IAddressable
Returns:
a String identity providing an identification for this entity within its type and domain.
See Also:
IAddressable.getType(), IAddressable.getDomain()

getType

public final IType getType()
Description copied from interface: IAddressable
Get the type attribute of this object. The type is orthogonal to the domain.

Specified by:
getType in interface IAddressable
Returns:
the type of this object
See Also:
IAddressable.getDomain()

getAddress

public final String getAddress()
Description copied from interface: IAddressable
Get the unique address for this. The address is composed of the identity, domain and type.

Specified by:
getAddress in interface IAddressable
Returns:
the unique address for this

includes

public final boolean includes(IAddressable parameters)
Description copied from interface: ISubscriptionParameters
Determine if the IAddressable attributes of this parameters instance would include those of another. For this instance to include the other, each attribute of this instance must be an exact match or a more generalised match of corresponding attribute in the other.

For example, assuming the type and domain are equal, if this instance has the identity regular expression "foo.*" and the other instance has the identity "foo bar", then this instance effectively includes the other (it is more generalised). However, it would not include the other if the other instance has an identity regular expression ".*" as this is now more generalised than this instance.

Specified by:
includes in interface ISubscriptionParameters
Parameters:
parameters - the other IAddressable instance to compare with this
Returns:
true if the attributes of this instance include those of the other

destroy

public void destroy()
Description copied from interface: IDestroyable
This is called when the object is being removed from application use. This releases all system resources and performs clean up prior to the object becoming redundant. This operation is idempotent.

This method must not throw a RuntimeException.

Specified by:
destroy in interface IDestroyable

doAddOperation

protected boolean doAddOperation(IEventSource source)
Template method for the operation to perform when a source match is added.

Parameters:
source - the source the operation applies to
Returns:
true if the operation did something

doRemoveOperation

protected boolean doRemoveOperation(IEventSource source)
Template method for the operation to perform when a source match is removed.

Parameters:
source - the source the operation applies to
Returns:
true if the operation did something

getLog

protected org.apache.commons.logging.Log getLog()

toString

public final String toString()
Overrides:
toString in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

equals

public final boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2007-2009. All Rights Reserved.