org.softamis.net.exchange.support
Class AbstractCommunicationHelper<D extends java.io.Serializable,K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.exchange.support.AbstractCommunicationHelper<D,K,V>
Type Parameters:
D - type of low level data that are sent via network
K - type of keys used to identify registry items
V - type of values stored in the registry
All Implemented Interfaces:
CommunicationHelper<K,V>
Direct Known Subclasses:
JGCommunicationHelper, UDPCommunicationHelper

public abstract class AbstractCommunicationHelper<D extends java.io.Serializable,K extends java.io.Serializable,V extends java.io.Serializable>
extends java.lang.Object
implements CommunicationHelper<K,V>

Class represents base implementation of CommunicationHelper used to isolate details of networking communications from registry logic.

Author:
Andrew Sazonov

Field Summary
protected  CommunicationProtocol<D,K,V> fCommunicationProtocol
          Communication proctocol used to transfer data
protected  java.lang.String fDefaultGroupName
          Name of group used to form "virtual" group.
protected  java.lang.String fDefaultMessageSignature
          Signature that will be set to CommunicationProtocol if one is created (and not specified explicitely)
protected static org.apache.commons.logging.Log fLog
           
protected  boolean fOwnCommunicationProtocol
           
protected  RegistryEventsMulticaster<K,V> fRegistryEventsMulticaster
          Processors that are responsible for processing of obtaining external notifications
 
Fields inherited from interface org.softamis.net.exchange.CommunicationHelper
COMMAND_ITEM_INVALID, COMMAND_ITEM_REGISTERED, COMMAND_ITEM_REQUEST, COMMAND_ITEM_UNREGISTERED
 
Constructor Summary
protected AbstractCommunicationHelper()
           
 
Method Summary
 void addRegistryEventProcessor(RegistryEventProcessor<K,V> aListener)
          Adds listener to list of registered RegistryEventProcessors which performs further processing of obtained external notifications
protected  ItemEntry<K,V> createEntryToReceiveData()
           
protected  void dispatchCommunicationMessage(byte aMessageType, ItemEntry<K,V> aEntry)
          Performs dispatching of the incoming external notification by call of appropriate method of processors.
protected  void doSendItemInvalidNotification(ItemEntry<K,V> aEntry)
          Creates lowlevel network data packet that corresponds to notification and sends it
protected  void doSendItemRegisteredNotification(ItemEntry<K,V> aEntry)
          Creates lowlevel network data packet that corresponds to notification and sends it
protected  void doSendItemsRequestNotification(ItemEntry<K,V> aEntry, long aTimeout)
          Creates lowlevel network data packet that corresponds to notification and sends it.
protected  void doSendItemUnRegisteredNotification(ItemEntry<K,V> aEntry)
          Creates lowlevel network data packet that corresponds to notification and sends it
 CommunicationProtocol<D,K,V> getCommunicationProtocol()
          Returns communication proctocol used to transfer data
 java.lang.String getDefaultGroupName()
          Returns name of group used to form "virtual" group.
 java.lang.String getDefaultMessageSignature()
           
protected  void processReceivedData(D aReceivedData, ItemEntry<K,V> aEntry)
          Performs processing of received data
protected  void processServiceInvalid(ItemEntry<K,V> aEntry)
          Initiates processing or "service invalid" notification by transferring notification data to registered processors.
protected  void processServiceRegistered(ItemEntry<K,V> aEntry)
          Initiates processing or "service registered" notification by transferring notification data to registered processors.
protected  void processServiceRequest(ItemEntry<K,V> aEntry)
          Initiating processing of service request by transferring notification to registered processors.
protected  void processServiceUnRegistered(ItemEntry<K,V> aEntry)
          Initiates processing or "service unregistered" notification by transferring notification data to registered processors.
protected abstract  void processUnexpectedMessage(byte aMessageType, ItemEntry<K,V> aEntry)
          Method that is used to handle messages with unexpected type.
protected  void receiveData(D aReceivedData)
          Performs processing of received data.
 void removeRegistryEventProcessor(RegistryEventProcessor<K,V> aListener)
          Removes listener from list of registered RegistryEventProcessors which performs further processing of obtained external notifications
protected abstract  void sendData(D aDataToSend)
          Sends newtorking notification with provided data
 void sendItemInvalidNotification(K aItemKey, V aItemInfo)
          Sends network notification about invalid item.
 void sendItemRegisteredNotification(K aItemKey, V aItemInfo)
          Sends network notification about item registered.
 void sendItemsRequestNotification(K aItemKey, long aTimeout)
          Sends network notification about requesting items for given key.
 void sendItemUnRegisteredNotification(K aItemKey, V aItemInfo)
          Sends network notification about item unregistration.
 void setCommunicationProtocol(CommunicationProtocol<D,K,V> aCommunicationProtocol)
          Sets communication proctocol used to transfer data
 void setDefaultGroupName(java.lang.String aDefaultGroupName)
          Sets name of group used to form "virtual" group.
 void setDefaultMessageSignature(java.lang.String aDefaultMessageSignature)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.softamis.net.exchange.CommunicationHelper
close, init
 

Field Detail

fLog

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

fRegistryEventsMulticaster

protected RegistryEventsMulticaster<K extends java.io.Serializable,V extends java.io.Serializable> fRegistryEventsMulticaster
Processors that are responsible for processing of obtaining external notifications


fCommunicationProtocol

protected CommunicationProtocol<D extends java.io.Serializable,K extends java.io.Serializable,V extends java.io.Serializable> fCommunicationProtocol
Communication proctocol used to transfer data


fDefaultGroupName

protected java.lang.String fDefaultGroupName
Name of group used to form "virtual" group.


fDefaultMessageSignature

protected java.lang.String fDefaultMessageSignature
Signature that will be set to CommunicationProtocol if one is created (and not specified explicitely)


fOwnCommunicationProtocol

protected boolean fOwnCommunicationProtocol
Constructor Detail

AbstractCommunicationHelper

protected AbstractCommunicationHelper()
Method Detail

processReceivedData

protected void processReceivedData(D aReceivedData,
                                   ItemEntry<K,V> aEntry)
Performs processing of received data

Parameters:
aReceivedData - raw data received from network notification
aEntry - entry to be filled by parsed data from network

receiveData

protected void receiveData(D aReceivedData)
Performs processing of received data. This method will be called by inherited classes as result of incoming networking communication.

Parameters:
aReceivedData - data received from the network.

createEntryToReceiveData

protected ItemEntry<K,V> createEntryToReceiveData()

dispatchCommunicationMessage

protected void dispatchCommunicationMessage(byte aMessageType,
                                            ItemEntry<K,V> aEntry)
Performs dispatching of the incoming external notification by call of appropriate method of processors.

Parameters:
aMessageType - type of incoming message
aEntry - item entry obtained with message

processUnexpectedMessage

protected abstract void processUnexpectedMessage(byte aMessageType,
                                                 ItemEntry<K,V> aEntry)
Method that is used to handle messages with unexpected type. Inherited classes may implement it to add processing of additional commands.

Parameters:
aMessageType - type of message
aEntry - entry obtained with message

sendData

protected abstract void sendData(D aDataToSend)
Sends newtorking notification with provided data

Parameters:
aDataToSend - data which should be sent

sendItemsRequestNotification

public void sendItemsRequestNotification(K aItemKey,
                                         long aTimeout)
Sends network notification about requesting items for given key. Typically this method will be called by ConsumingRegistry to obtain information about available items.

This method may block execution of calling thread after issuing notification for specified amount of time to let responses be collected.

Specified by:
sendItemsRequestNotification in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - key of item
aTimeout - timeout(in ms) used for discovering items

sendItemInvalidNotification

public void sendItemInvalidNotification(K aItemKey,
                                        V aItemInfo)
Sends network notification about invalid item. Typically is sent by ConsumingRegistry.

Specified by:
sendItemInvalidNotification in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - key of the item
aItemInfo - item invalidated

sendItemRegisteredNotification

public void sendItemRegisteredNotification(K aItemKey,
                                           V aItemInfo)
Sends network notification about item registered. Typically is sent by ProvidingRegistry.

Specified by:
sendItemRegisteredNotification in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - key of registered item
aItemInfo - the item registered

sendItemUnRegisteredNotification

public void sendItemUnRegisteredNotification(K aItemKey,
                                             V aItemInfo)
Sends network notification about item unregistration. Typically is sent by ProvidingRegistry.

Specified by:
sendItemUnRegisteredNotification in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aItemKey - key of unregistered item
aItemInfo - the item unregistered

doSendItemInvalidNotification

protected void doSendItemInvalidNotification(ItemEntry<K,V> aEntry)
Creates lowlevel network data packet that corresponds to notification and sends it

Parameters:
aEntry - item entry to be set in notification

doSendItemRegisteredNotification

protected void doSendItemRegisteredNotification(ItemEntry<K,V> aEntry)
Creates lowlevel network data packet that corresponds to notification and sends it

Parameters:
aEntry - item entry to be set in notification

doSendItemUnRegisteredNotification

protected void doSendItemUnRegisteredNotification(ItemEntry<K,V> aEntry)
Creates lowlevel network data packet that corresponds to notification and sends it

Parameters:
aEntry - item entry to be set in notification

doSendItemsRequestNotification

protected void doSendItemsRequestNotification(ItemEntry<K,V> aEntry,
                                              long aTimeout)
Creates lowlevel network data packet that corresponds to notification and sends it. After this, current thread is blocked for given period of time allowing registries that obtained this request to respond. Responding notifications from these reqistries will be processed by this CommunicationHelper in receiveData(D) and will be further processed by registered processors.

Parameters:
aEntry - item entry to be set in notification

removeRegistryEventProcessor

public void removeRegistryEventProcessor(RegistryEventProcessor<K,V> aListener)
Removes listener from list of registered RegistryEventProcessors which performs further processing of obtained external notifications

Specified by:
removeRegistryEventProcessor in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aListener - processor to be removed

addRegistryEventProcessor

public void addRegistryEventProcessor(RegistryEventProcessor<K,V> aListener)
Adds listener to list of registered RegistryEventProcessors which performs further processing of obtained external notifications

Specified by:
addRegistryEventProcessor in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aListener - processor to be added

processServiceRequest

protected void processServiceRequest(ItemEntry<K,V> aEntry)
Initiating processing of service request by transferring notification to registered processors.

Parameters:
aEntry - entry contained in request.

processServiceRegistered

protected void processServiceRegistered(ItemEntry<K,V> aEntry)
Initiates processing or "service registered" notification by transferring notification data to registered processors.

Parameters:
aEntry - entry contained in request.

processServiceUnRegistered

protected void processServiceUnRegistered(ItemEntry<K,V> aEntry)
Initiates processing or "service unregistered" notification by transferring notification data to registered processors.

Parameters:
aEntry - entry contained in request.

processServiceInvalid

protected void processServiceInvalid(ItemEntry<K,V> aEntry)
Initiates processing or "service invalid" notification by transferring notification data to registered processors.

Parameters:
aEntry - entry contained in request.

getCommunicationProtocol

public CommunicationProtocol<D,K,V> getCommunicationProtocol()
Returns communication proctocol used to transfer data

Returns:
communication proctocol

setCommunicationProtocol

public void setCommunicationProtocol(CommunicationProtocol<D,K,V> aCommunicationProtocol)
Sets communication proctocol used to transfer data

Parameters:
aCommunicationProtocol - communication proctocol

getDefaultGroupName

public java.lang.String getDefaultGroupName()
Returns name of group used to form "virtual" group.

Returns:
name of group

setDefaultGroupName

public void setDefaultGroupName(java.lang.String aDefaultGroupName)
Sets name of group used to form "virtual" group.

Parameters:
aDefaultGroupName - name of group

getDefaultMessageSignature

public java.lang.String getDefaultMessageSignature()
Specified by:
getDefaultMessageSignature in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>

setDefaultMessageSignature

public void setDefaultMessageSignature(java.lang.String aDefaultMessageSignature)
Specified by:
setDefaultMessageSignature in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>