org.softamis.net.exchange.udp
Class UDPCommunicationProtocol<K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.exchange.support.AbstractCommunicationProtocol<byte[],K,V,java.lang.String>
      extended by org.softamis.net.exchange.udp.UDPCommunicationProtocol<K,V>
Type Parameters:
K - type of keys used to identify registry items
V - type of values stored in the registry
All Implemented Interfaces:
CommunicationProtocol<byte[],K,V>

public class UDPCommunicationProtocol<K extends java.io.Serializable,V extends java.io.Serializable>
extends AbstractCommunicationProtocol<byte[],K,V,java.lang.String>

Default implementation of CommunicationProtocol if multicasting UDP is used as underlying network transport protocol.

Author:
Andrew Sazonov
See Also:
RegistryEventProcessor

Field Summary
static java.lang.String DEFAULT_DATAGRAM_SIGNATURE
          Default signature for notifications that are sent as part of network protocol.
protected static org.apache.commons.logging.Log fLog
           
protected  java.lang.String fOwnID
          ID used to identify source of datagaram packets that are sent.
 
Fields inherited from class org.softamis.net.exchange.support.AbstractCommunicationProtocol
DEFAULT_COMPRESSION_MODE, fDatagramSignature, fUseCompression, MSG_EXCEPTION_CLOSING_STREAM
 
Constructor Summary
UDPCommunicationProtocol()
           
 
Method Summary
protected  MessageContent<K,V,java.lang.String> createMessageContent(byte aType, java.lang.String aTo, ItemEntry<K,V> aEntry)
          Creates MessageContent which will be converted into form used by underlying network communication based on provided parameters.
protected  byte[] doCreateDataToSend(MessageContent<K,V,java.lang.String> aContent)
          Converts given MessageContent to form used by underlying network communication
static boolean equals(java.lang.String aFirst, java.lang.String aSecond)
           
protected  java.lang.String generateOwnID()
          Generates ID that is used to determine destination of the message.
protected  MessageContent<K,V,java.lang.String> getDatagramFromReceivedData(byte[] aReceivedData)
          Constructs MessageContent from underlying network data.
protected  byte[] getLocalAddress()
          Utility method that allows to obtain local address.
protected  boolean isNotOwnDatagaram(MessageContent<K,V,java.lang.String> aDatagram)
          Determines whether notification was obtained from external source and is not result of own notification
 
Methods inherited from class org.softamis.net.exchange.support.AbstractCommunicationProtocol
closeStream, closeStream, createDataToSend, createMessageContentToRead, fillEntryByMessageContent, fillItemEntry, getDatagram, getDatagramSignature, getDataToSend, isUseCompression, setDatagramSignature, setUseCompression
 
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

fOwnID

protected java.lang.String fOwnID
ID used to identify source of datagaram packets that are sent. This ID is used to determine wither message is obtained from the sender.

See Also:
isNotOwnDatagaram(org.softamis.net.exchange.support.MessageContent)

DEFAULT_DATAGRAM_SIGNATURE

public static final java.lang.String DEFAULT_DATAGRAM_SIGNATURE
Default signature for notifications that are sent as part of network protocol.

See Also:
Constant Field Values
Constructor Detail

UDPCommunicationProtocol

public UDPCommunicationProtocol()
Method Detail

isNotOwnDatagaram

protected boolean isNotOwnDatagaram(MessageContent<K,V,java.lang.String> aDatagram)
Determines whether notification was obtained from external source and is not result of own notification

Specified by:
isNotOwnDatagaram in class AbstractCommunicationProtocol<byte[],K extends java.io.Serializable,V extends java.io.Serializable,java.lang.String>
Parameters:
aDatagram - data to receive
Returns:
true if data was obtained from external source

equals

public static boolean equals(java.lang.String aFirst,
                             java.lang.String aSecond)

getDatagramFromReceivedData

protected MessageContent<K,V,java.lang.String> getDatagramFromReceivedData(byte[] aReceivedData)
Constructs MessageContent from underlying network data.

Specified by:
getDatagramFromReceivedData in class AbstractCommunicationProtocol<byte[],K extends java.io.Serializable,V extends java.io.Serializable,java.lang.String>
Parameters:
aReceivedData - raw data obtained in network notification
Returns:
constructed content

createMessageContent

protected MessageContent<K,V,java.lang.String> createMessageContent(byte aType,
                                                                    java.lang.String aTo,
                                                                    ItemEntry<K,V> aEntry)
Creates MessageContent which will be converted into form used by underlying network communication based on provided parameters.

Specified by:
createMessageContent in class AbstractCommunicationProtocol<byte[],K extends java.io.Serializable,V extends java.io.Serializable,java.lang.String>
Parameters:
aType - type of notification
aTo - destination of notification
aEntry - Item data
Returns:
created message content

doCreateDataToSend

protected byte[] doCreateDataToSend(MessageContent<K,V,java.lang.String> aContent)
Converts given MessageContent to form used by underlying network communication

Specified by:
doCreateDataToSend in class AbstractCommunicationProtocol<byte[],K extends java.io.Serializable,V extends java.io.Serializable,java.lang.String>
Parameters:
aContent - given message content
Returns:
data in form ready to send via network by CommunicationHelper

getLocalAddress

protected byte[] getLocalAddress()
Utility method that allows to obtain local address.

Returns:
local address of machine
See Also:
generateOwnID()

generateOwnID

protected java.lang.String generateOwnID()
Generates ID that is used to determine destination of the message. ID is genearated by composing local address of machine, hashCode() of current thread and current system time.

Returns:
id for datagrams.
See Also:
getLocalAddress(), fOwnID, isNotOwnDatagaram(org.softamis.net.exchange.support.MessageContent)