org.jgroups.protocols

Class TP

Known Direct Subclasses:
TCP, UDP

public abstract class TP
extends Protocol

Generic transport - specific implementations should extend this abstract class. Features which are provided to the subclasses include 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.
Version:
$Id: TP.java,v 1.53.2.1 2006/05/16 04:20:38 belaban Exp $
Author:
Bela Ban

Field Summary

Fields inherited from class org.jgroups.stack.Protocol

down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, stats, trace, up_handler, up_prot, up_queue, up_thread, up_thread_prio, warn

Constructor Summary

TP()
Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads.

Method Summary

void
down(Event evt)
Caller by the layer above this layer.
Map
dumpStats()
String
getBindAddress()
boolean
getBindToAllInterfaces()
Deprecated. Use isReceiveOnAllInterfaces() instead
String
getChannelName()
int
getIncomingQueueSize()
abstract String
getInfo()
Address
getLocalAddress()
int
getMaxBundleSize()
long
getMaxBundleTimeout()
long
getNumBytesReceived()
long
getNumBytesSent()
long
getNumMessagesReceived()
long
getNumMessagesSent()
int
getOutgoingQueueMaxSize()
int
getOutgoingQueueSize()
java.util.List
getReceiveInterfaces()
java.util.List
getSendInterfaces()
protected void
handleConfigEvent(HashMap map)
protected void
handleDownEvent(Event evt)
boolean
isDiscardIncompatiblePackets()
boolean
isEnableBundling()
boolean
isLoopback()
boolean
isReceiveOnAllInterfaces()
boolean
isSendOnAllInterfaces()
boolean
isUseIncomingPacketHandler()
boolean
isUseOutgoingPacketHandler()
abstract void
postUnmarshalling(Message msg, Address dest, Address src, boolean multicast)
abstract void
postUnmarshallingList(Message msg, Address dest, boolean multicast)
protected 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.
void
resetStats()
abstract void
sendToAllMembers(byte[] data, int offset, int length)
Send to all members in the group.
abstract void
sendToSingleMember(Address dest, byte[] data, int offset, int length)
Send to all members in the group.
void
setBindAddress(String bind_addr)
void
setBindToAllInterfaces(boolean flag)
void
setDiscardIncompatiblePackets(boolean flag)
void
setEnableBundling(boolean flag)
void
setLoopback(boolean b)
void
setMaxBundleSize(int size)
void
setMaxBundleTimeout(long timeout)
void
setOutgoingQueueMaxSize(int new_size)
boolean
setProperties(Properties props)
Setup the Protocol instance according to the configuration string
void
start()
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
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.
void
stop()
This method is called on a Channel.disconnect().
String
toString()
debug only
void
up(Event evt)
handle the UP event.

Methods inherited from class org.jgroups.stack.Protocol

destroy, down, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, isTrace, isWarn, passDown, passUp, printStats, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, resetStats, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setTrace, setUpProtocol, setWarn, start, startDownHandler, startUpHandler, statsEnabled, stop, stopInternal, up, upThreadEnabled

Constructor Details

TP

protected TP()
Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads.

Method Details

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()).
Overrides:
down in interface Protocol

dumpStats

public Map dumpStats()
Overrides:
dumpStats in interface Protocol

getBindAddress

public String getBindAddress()

getBindToAllInterfaces

public boolean getBindToAllInterfaces()

Deprecated. Use isReceiveOnAllInterfaces() instead


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.
Parameters:
dest -
sender -
data -
offset -
length -

resetStats

public void resetStats()
Overrides:
resetStats in interface Protocol

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
Parameters:
data - The data to be sent. This is not a copy, so don't modify it
offset -
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
Parameters:
dest - Must be a non-null unicast address
data - The data to be sent. This is not a copy, so don't modify it
offset -
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
Overrides:
setProperties in interface Protocol
Returns:
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
Overrides:
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 !
Overrides:
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
Overrides:
stop in interface Protocol

toString

public String toString()
debug only

up

public void up(Event evt)
handle the UP event.
Overrides:
up in interface Protocol
Parameters:
evt - - the event being send from the stack

Copyright B) 1998-2005 Bela Ban. All Rights Reserved.