org.softamis.net.exchange.jgroups
Class JGCommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.exchange.support.AbstractCommunicationHelper<org.jgroups.Message,K,V>
      extended by org.softamis.net.exchange.jgroups.JGCommunicationHelper<K,V>
Type Parameters:
K - type of keys used to identify registry items
V - type of values stored in the registry
All Implemented Interfaces:
org.jgroups.MessageListener, CommunicationHelper<K,V>

public class JGCommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
extends AbstractCommunicationHelper<org.jgroups.Message,K,V>
implements org.jgroups.MessageListener

Implementation of CommunicationHelper that uses JGroups reliable multicast as underlying trasport mechanizm of network communications. This implementation of communication helper listens messages from contained JGroups PullPushAdapter which could be specified outside during instance initialization (or created internally).

Author:
Andrew Sazonov
See Also:
RegistryEventProcessor

Field Summary
static java.lang.String DEFAULT_GROUP_NAME
           
static java.lang.String DEFAULT_PROPERTIES
           
static java.lang.String DEFAULT_SIGNATURE
           
protected  org.jgroups.blocks.PullPushAdapter fAdapter
          Adapter used to perform communication
protected  org.jgroups.JChannel fDefaultChannel
          JGroups channel that is created if adapter is not specified from outside
protected  java.lang.String fDefaultProperties
          Properties that are used for creation of JGroups JChannel if adapter should be created
protected static org.apache.commons.logging.Log fLog
           
protected  boolean fOwnAdapter
          Flag that indicates whether adapter was not set from outside and therefore was created
protected  java.io.Serializable fSignature
          Signature used to select JGroups messages
 
Fields inherited from class org.softamis.net.exchange.support.AbstractCommunicationHelper
fCommunicationProtocol, fDefaultGroupName, fDefaultMessageSignature, fOwnCommunicationProtocol, fRegistryEventsMulticaster
 
Fields inherited from interface org.softamis.net.exchange.CommunicationHelper
COMMAND_ITEM_INVALID, COMMAND_ITEM_REGISTERED, COMMAND_ITEM_REQUEST, COMMAND_ITEM_UNREGISTERED
 
Constructor Summary
JGCommunicationHelper()
           
 
Method Summary
 void close()
          Used to close helper after usage at the end of lifecycle.
 org.jgroups.blocks.PullPushAdapter getAdapter()
          Returns adapter used to perform communication
 java.lang.String getDefaultProperties()
          Returns properties that are used for creation of JGroups JChannel if adapter should be created
 java.io.Serializable getSignature()
          Returns signature used to select JGroups messages
 byte[] getState()
           
 void init()
          Method used for initialization of communication helper.
protected  void initAdapter()
           
protected  void insureCommunicationProtocolSet()
           
protected  void processUnexpectedMessage(byte aMessageType, ItemEntry<K,V> aEntry)
          Method that is used to handle messages with unexpected type.
 void receive(org.jgroups.Message aMessage)
           
protected  void sendData(org.jgroups.Message aDataToSend)
          Sends newtorking notification with provided data
 void setAdapter(org.jgroups.blocks.PullPushAdapter aAdapter)
          Sets adapter used to perform communication
 void setDefaultProperties(java.lang.String aDefaultProperties)
          Sets properties that are used for creation of JGroups JChannel if adapter should be created
 void setSignature(java.io.Serializable aSignature)
          Sets signature used to select JGroups messages
 void setState(byte[] aState)
           
protected  java.lang.String stripWhiteSpaces(java.lang.String aOriginalString)
           
 
Methods inherited from class org.softamis.net.exchange.support.AbstractCommunicationHelper
addRegistryEventProcessor, createEntryToReceiveData, dispatchCommunicationMessage, doSendItemInvalidNotification, doSendItemRegisteredNotification, doSendItemsRequestNotification, doSendItemUnRegisteredNotification, getCommunicationProtocol, getDefaultGroupName, getDefaultMessageSignature, processReceivedData, processServiceInvalid, processServiceRegistered, processServiceRequest, processServiceUnRegistered, receiveData, removeRegistryEventProcessor, sendItemInvalidNotification, sendItemRegisteredNotification, sendItemsRequestNotification, sendItemUnRegisteredNotification, setCommunicationProtocol, setDefaultGroupName, setDefaultMessageSignature
 
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

fAdapter

protected org.jgroups.blocks.PullPushAdapter fAdapter
Adapter used to perform communication


fOwnAdapter

protected boolean fOwnAdapter
Flag that indicates whether adapter was not set from outside and therefore was created


fDefaultProperties

protected java.lang.String fDefaultProperties
Properties that are used for creation of JGroups JChannel if adapter should be created


fDefaultChannel

protected org.jgroups.JChannel fDefaultChannel
JGroups channel that is created if adapter is not specified from outside


DEFAULT_GROUP_NAME

public static final java.lang.String DEFAULT_GROUP_NAME
See Also:
Constant Field Values

fSignature

protected java.io.Serializable fSignature
Signature used to select JGroups messages


DEFAULT_SIGNATURE

public static final java.lang.String DEFAULT_SIGNATURE
See Also:
Constant Field Values

DEFAULT_PROPERTIES

public static final java.lang.String DEFAULT_PROPERTIES
See Also:
Constant Field Values
Constructor Detail

JGCommunicationHelper

public JGCommunicationHelper()
Method Detail

insureCommunicationProtocolSet

protected void insureCommunicationProtocolSet()

processUnexpectedMessage

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

Specified by:
processUnexpectedMessage in class AbstractCommunicationHelper<org.jgroups.Message,K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aMessageType - type of message
aEntry - entry obtained with message

receive

public void receive(org.jgroups.Message aMessage)
Specified by:
receive in interface org.jgroups.MessageListener

getState

public byte[] getState()
Specified by:
getState in interface org.jgroups.MessageListener

setState

public void setState(byte[] aState)
Specified by:
setState in interface org.jgroups.MessageListener

sendData

protected void sendData(org.jgroups.Message aDataToSend)
Description copied from class: AbstractCommunicationHelper
Sends newtorking notification with provided data

Specified by:
sendData in class AbstractCommunicationHelper<org.jgroups.Message,K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aDataToSend - data which should be sent

init

public void init()
          throws java.io.IOException
Description copied from interface: CommunicationHelper
Method used for initialization of communication helper.

Specified by:
init in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>
Throws:
java.io.IOException

initAdapter

protected void initAdapter()

close

public void close()
Description copied from interface: CommunicationHelper
Used to close helper after usage at the end of lifecycle.

Specified by:
close in interface CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable>

getSignature

public java.io.Serializable getSignature()
Returns signature used to select JGroups messages

Returns:
signature used to select JGroups messages

setSignature

public void setSignature(java.io.Serializable aSignature)
Sets signature used to select JGroups messages

Parameters:
aSignature - signature used to select JGroups messages

getAdapter

public org.jgroups.blocks.PullPushAdapter getAdapter()
Returns adapter used to perform communication

Returns:
adapter used to perform communication

setAdapter

public void setAdapter(org.jgroups.blocks.PullPushAdapter aAdapter)
Sets adapter used to perform communication

Parameters:
aAdapter - adapter used to perform communication

getDefaultProperties

public java.lang.String getDefaultProperties()
Returns properties that are used for creation of JGroups JChannel if adapter should be created

Returns:
properties

setDefaultProperties

public void setDefaultProperties(java.lang.String aDefaultProperties)
Sets properties that are used for creation of JGroups JChannel if adapter should be created

Parameters:
aDefaultProperties - properties string

stripWhiteSpaces

protected java.lang.String stripWhiteSpaces(java.lang.String aOriginalString)