org.jgroups.protocols
Class TP

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.TP
Direct Known Subclasses:
BasicTCP, 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.77.2.5 2007/06/19 10:50:59 belaban Exp $
Author:
Bela Ban

Field Summary
protected  java.net.InetAddress bind_addr
          The interface (NIC) which should be used by this transport
protected  java.lang.String channel_name
          The name of the group to which this member is connected
protected  Address local_addr
          The address (host and port) of this member
protected  java.util.Vector members
          The members of this group (updated when a member joins or leaves)
protected  TimeScheduler timer
           
protected  View view
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, stats, up_handler, up_prot, up_queue, up_thread, up_thread_prio
 
Constructor Summary
protected 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.
 java.util.Map dumpStats()
           
 java.lang.String getBindAddress()
           
 boolean getBindToAllInterfaces()
          Deprecated. Use isReceiveOnAllInterfaces() instead
 java.lang.String getChannelName()
           
 int getIncomingQueueSize()
           
abstract  java.lang.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(java.util.HashMap map)
           
protected  void handleDownEvent(Event evt)
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 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(java.lang.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(java.util.Properties props)
          Setup the Protocol instance according to the configuration string
protected  void setThreadNames()
           
 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().
 java.lang.String toString()
          debug only
protected  void unsetThreadNames()
           
 void up(Event evt)
          handle the UP event.
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, enableStats, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, passDown, passUp, printStats, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setPropertiesInternal, setProtocolStack, setUpProtocol, startDownHandler, statsEnabled, stopInternal, upThreadEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

local_addr

protected Address local_addr
The address (host and port) of this member


channel_name

protected java.lang.String channel_name
The name of the group to which this member is connected


bind_addr

protected java.net.InetAddress bind_addr
The interface (NIC) which should be used by this transport


members

protected final java.util.Vector members
The members of this group (updated when a member joins or leaves)


view

protected View view

timer

protected TimeScheduler timer
Constructor Detail

TP

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

Method Detail

toString

public java.lang.String toString()
debug only

Overrides:
toString in class java.lang.Object

resetStats

public void resetStats()
Overrides:
resetStats in class Protocol

getNumMessagesSent

public long getNumMessagesSent()

getNumMessagesReceived

public long getNumMessagesReceived()

getNumBytesSent

public long getNumBytesSent()

getNumBytesReceived

public long getNumBytesReceived()

getBindAddress

public java.lang.String getBindAddress()

setBindAddress

public void setBindAddress(java.lang.String bind_addr)
                    throws java.net.UnknownHostException
Throws:
java.net.UnknownHostException

getBindToAllInterfaces

public boolean getBindToAllInterfaces()
Deprecated. Use isReceiveOnAllInterfaces() instead


setBindToAllInterfaces

public void setBindToAllInterfaces(boolean flag)

isReceiveOnAllInterfaces

public boolean isReceiveOnAllInterfaces()

getReceiveInterfaces

public java.util.List getReceiveInterfaces()

isSendOnAllInterfaces

public boolean isSendOnAllInterfaces()

getSendInterfaces

public java.util.List getSendInterfaces()

isDiscardIncompatiblePackets

public boolean isDiscardIncompatiblePackets()

setDiscardIncompatiblePackets

public void setDiscardIncompatiblePackets(boolean flag)

isEnableBundling

public boolean isEnableBundling()

setEnableBundling

public void setEnableBundling(boolean flag)

getMaxBundleSize

public int getMaxBundleSize()

setMaxBundleSize

public void setMaxBundleSize(int size)

getMaxBundleTimeout

public long getMaxBundleTimeout()

setMaxBundleTimeout

public void setMaxBundleTimeout(long timeout)

getOutgoingQueueSize

public int getOutgoingQueueSize()

getIncomingQueueSize

public int getIncomingQueueSize()

getLocalAddress

public Address getLocalAddress()

getChannelName

public java.lang.String getChannelName()

isLoopback

public boolean isLoopback()

setLoopback

public void setLoopback(boolean b)

isUseIncomingPacketHandler

public boolean isUseIncomingPacketHandler()

isUseOutgoingPacketHandler

public boolean isUseOutgoingPacketHandler()

getOutgoingQueueMaxSize

public int getOutgoingQueueMaxSize()

setOutgoingQueueMaxSize

public void setOutgoingQueueMaxSize(int new_size)

dumpStats

public java.util.Map dumpStats()
Overrides:
dumpStats in class Protocol

sendToAllMembers

public abstract void sendToAllMembers(byte[] data,
                                      int offset,
                                      int length)
                               throws java.lang.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 -
Throws:
java.lang.Exception

sendToSingleMember

public abstract void sendToSingleMember(Address dest,
                                        byte[] data,
                                        int offset,
                                        int length)
                                 throws java.lang.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 -
Throws:
java.lang.Exception

getInfo

public abstract java.lang.String getInfo()

postUnmarshalling

public abstract void postUnmarshalling(Message msg,
                                       Address dest,
                                       Address src,
                                       boolean multicast)

postUnmarshallingList

public abstract void postUnmarshallingList(Message msg,
                                           Address dest,
                                           boolean multicast)

init

public void init()
          throws java.lang.Exception
Description copied from class: Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.

Overrides:
init in class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception

start

public void start()
           throws java.lang.Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads

Overrides:
start in class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception

stop

public void stop()
Description copied from class: Protocol
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 class Protocol

setProperties

public boolean setProperties(java.util.Properties props)
Setup the Protocol instance according to the configuration string

Overrides:
setProperties in class 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

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 class Protocol

up

public void up(Event evt)
handle the UP event.

Overrides:
up in class Protocol
Parameters:
evt - - the event being send from the stack

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 class Protocol

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 -

handleDownEvent

protected void handleDownEvent(Event evt)

setThreadNames

protected void setThreadNames()

unsetThreadNames

protected void unsetThreadNames()

handleConfigEvent

protected void handleConfigEvent(java.util.HashMap map)


Copyright ? 1998-2006 Bela Ban. All Rights Reserved.