org.softamis.net.registry.impl
Class AbstractProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.registry.impl.AbstractProvidingRegistry<K,V>
Type Parameters:
K - type of keys used to identify registry items
V - type of values stored in the registry
All Implemented Interfaces:
DiscoverableProvidingRegistry<K,V>, ProvidingRegistry<K,V>
Direct Known Subclasses:
DefaultProvidingRegistry

public abstract class AbstractProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>
extends java.lang.Object
implements DiscoverableProvidingRegistry<K,V>

Base abstract implementation of ProvidingRegistry.

Author:
Andrew Sazonov
See Also:
ProvidingRegistry

Nested Class Summary
protected static interface AbstractProvidingRegistry.ItemsStorage<K extends java.io.Serializable,V extends java.io.Serializable>
          Interface with represents storage used by registry to store registered values internally
protected  class AbstractProvidingRegistry.MultiValueItemsStorage
           
protected  class AbstractProvidingRegistry.SingleValueItemsStorage
          Implementation of storage wich allows only one value be registered under the given key.
 
Field Summary
protected  AbstractProvidingRegistry.ItemsStorage<K,V> fItemsStorage
          Storage where registered items are stored internally
protected static org.apache.commons.logging.Log fLog
           
 
Constructor Summary
protected AbstractProvidingRegistry(boolean aMultivalue)
          Constructor which creates providing registry and initializes internal storage of registered items.
 
Method Summary
protected abstract  void doAfterItemRegistered(K aItemKey, V aItem)
          Performs post-processing of item registration.
protected abstract  void doAfterItemUnregistered(K aItemKey, V aItem)
          Performs post-processing of item unregistration.
 java.util.List<java.util.Map.Entry<K,V>> getOwnItems()
          Returns items that were published by this provider registry
 boolean isMultivalued()
          Allows to determine whether storage allows to register several values under the same key
 void notifyAllRegistrations()
          Forces registry to issue notification for all registered items.
 void registerItem(K aItemKey, V aItem)
          Registers item stored under given key.
protected  void removeOwnItems()
          Method that issues notification about unregistration of all items which were previously registred via this particular ProviderReqistry
 void unregisterAllItems()
           
 void unRegisterItem(K aItemKey)
          Performs un-registration of the item under given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fLog

protected static final org.apache.commons.logging.Log fLog

fItemsStorage

protected AbstractProvidingRegistry.ItemsStorage<K extends java.io.Serializable,V extends java.io.Serializable> fItemsStorage
Storage where registered items are stored internally

Constructor Detail

AbstractProvidingRegistry

protected AbstractProvidingRegistry(boolean aMultivalue)
Constructor which creates providing registry and initializes internal storage of registered items.

Parameters:
aMultivalue - indicates whether only one value could be registered per key or several ones. If value is true, it's possible to register several items on the same key
Method Detail

isMultivalued

public boolean isMultivalued()
Allows to determine whether storage allows to register several values under the same key

Returns:
true if registry allows to register several values under the same key

registerItem

public void registerItem(K aItemKey,
                         V aItem)
Registers item stored under given key. If given item was not already registered under given key, this implementation will preform additional pos-processing of registration (such as as issuing appropriate network notification about registration). If the item was already registered, it will be silently ignored.

Specified by:
registerItem in interface ProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - key of the item to be registered
aItem - the item to be registered

notifyAllRegistrations

public void notifyAllRegistrations()
Forces registry to issue notification for all registered items. Potentially, this method could be called on some scheduled basis to provider "heart-beat" of registry (so client registries will be re-notified about content published via registry).

Method simply performs the same post-processing of registration as one performed during normal item registration.

Specified by:
notifyAllRegistrations in interface ProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>

unRegisterItem

public void unRegisterItem(K aItemKey)
Performs un-registration of the item under given key. Item will be removed from the distributed registry. If given item was actually registered under given key, this method also invokes additional post-processing of un-registration, letting inherited classes to implement, for example, issuing of network notifications about item un-registration

Specified by:
unRegisterItem in interface ProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - item to unregister

doAfterItemUnregistered

protected abstract void doAfterItemUnregistered(K aItemKey,
                                                V aItem)
Performs post-processing of item unregistration. Method will be overriden by inherited classes and may be used, for example, for issuing network notifications about item un-registration

Parameters:
aItemKey - key of the item unregistered
aItem - the item which is unregistered

doAfterItemRegistered

protected abstract void doAfterItemRegistered(K aItemKey,
                                              V aItem)
Performs post-processing of item registration. Method will be overriden by inherited classes and may be used, for example, for issuing network notifications about item registration.

Parameters:
aItemKey - key of the item registered
aItem - the item which is registered

getOwnItems

public java.util.List<java.util.Map.Entry<K,V>> getOwnItems()
Returns items that were published by this provider registry

Specified by:
getOwnItems in interface DiscoverableProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>
Returns:
items

removeOwnItems

protected void removeOwnItems()
Method that issues notification about unregistration of all items which were previously registred via this particular ProviderReqistry


unregisterAllItems

public void unregisterAllItems()
Specified by:
unregisterAllItems in interface ProvidingRegistry<K extends java.io.Serializable,V extends java.io.Serializable>