Generic transport - specific implementations should extend this abstract class.
Features which are provided to the subclasses include
- version checking
- marshalling and unmarshalling
- message bundling (handling single messages, and message lists)
- incoming packet handler
- loopback
A subclass has to override
The create() or start() method has to create a local address.
The
receive(Address,Address,byte[],int,int)
method must
be called by subclasses when a unicast or multicast message has been received.
down
public void down(Event evt)
Caller by the layer above this layer. Usually we just put this Message
into the send queue and let one or more worker threads handle it. A worker thread
then removes the Message from the send queue, performs a conversion and adds the
modified Message to the send queue of the layer below it, by calling down()).
- down in interface Protocol
getBindAddress
public String getBindAddress()
getChannelName
public String getChannelName()
getIncomingQueueSize
public int getIncomingQueueSize()
getInfo
public abstract String getInfo()
getLocalAddress
public Address getLocalAddress()
getMaxBundleSize
public int getMaxBundleSize()
getMaxBundleTimeout
public long getMaxBundleTimeout()
getNumBytesReceived
public long getNumBytesReceived()
getNumBytesSent
public long getNumBytesSent()
getNumMessagesReceived
public long getNumMessagesReceived()
getNumMessagesSent
public long getNumMessagesSent()
getOutgoingQueueMaxSize
public int getOutgoingQueueMaxSize()
getOutgoingQueueSize
public int getOutgoingQueueSize()
getReceiveInterfaces
public java.util.List getReceiveInterfaces()
getSendInterfaces
public java.util.List getSendInterfaces()
handleConfigEvent
protected void handleConfigEvent(HashMap map)
handleDownEvent
protected void handleDownEvent(Event evt)
isDiscardIncompatiblePackets
public boolean isDiscardIncompatiblePackets()
isEnableBundling
public boolean isEnableBundling()
isLoopback
public boolean isLoopback()
isReceiveOnAllInterfaces
public boolean isReceiveOnAllInterfaces()
isSendOnAllInterfaces
public boolean isSendOnAllInterfaces()
isUseIncomingPacketHandler
public boolean isUseIncomingPacketHandler()
isUseOutgoingPacketHandler
public boolean isUseOutgoingPacketHandler()
postUnmarshalling
public abstract void postUnmarshalling(Message msg,
Address dest,
Address src,
boolean multicast)
postUnmarshallingList
public abstract void postUnmarshallingList(Message msg,
Address dest,
boolean multicast)
receive
protected final void receive(Address dest,
Address sender,
byte[] data,
int offset,
int length)
Subclasses must call this method when a unicast or multicast message has been received.
Declared final so subclasses cannot override this method.
dest
- sender
- data
- offset
- length
-
sendToAllMembers
public abstract void sendToAllMembers(byte[] data,
int offset,
int length)
throws Exception
Send to all members in the group. UDP would use an IP multicast message, whereas TCP would send N
messages, one for each member
data
- The data to be sent. This is not a copy, so don't modify itoffset
- length
-
sendToSingleMember
public abstract void sendToSingleMember(Address dest,
byte[] data,
int offset,
int length)
throws Exception
Send to all members in the group. UDP would use an IP multicast message, whereas TCP would send N
messages, one for each member
dest
- Must be a non-null unicast addressdata
- The data to be sent. This is not a copy, so don't modify itoffset
- length
-
setBindAddress
public void setBindAddress(String bind_addr)
throws UnknownHostException
setBindToAllInterfaces
public void setBindToAllInterfaces(boolean flag)
setDiscardIncompatiblePackets
public void setDiscardIncompatiblePackets(boolean flag)
setEnableBundling
public void setEnableBundling(boolean flag)
setLoopback
public void setLoopback(boolean b)
setMaxBundleSize
public void setMaxBundleSize(int size)
setMaxBundleTimeout
public void setMaxBundleTimeout(long timeout)
setOutgoingQueueMaxSize
public void setOutgoingQueueMaxSize(int new_size)
setProperties
public boolean setProperties(Properties props)
Setup the Protocol instance according to the configuration string
- setProperties in interface Protocol
- true if no other properties are left.
false if the properties still have data in them, ie ,
properties are left over and not handled by the protocol stack
start
public void start()
throws Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
- start in interface Protocol
startUpHandler
public void startUpHandler()
This prevents the up-handler thread to be created, which essentially is superfluous:
messages are received from the network rather than from a layer below.
DON'T REMOVE !
- startUpHandler in interface Protocol
stop
public void stop()
This method is called on a
Channel.disconnect()
. Stops work (e.g. by closing multicast socket).
Will be called
from top to bottom. This means that at the time of the method invocation the
neighbor protocol below is still working. This method will replace the
STOP,
STOP_OK,
CLEANUP and
CLEANUP_OK events. The ProtocolStack guarantees that
when this method is called all messages in the down queue will have been flushed
- stop in interface Protocol
toString
public String toString()
debug only
up
public void up(Event evt)
handle the UP event.
- up in interface Protocol
evt
- - the event being send from the stack