org.jgroups.protocols

Class TCP

Implemented Interfaces:
ConnectionTable.Receiver
Known Direct Subclasses:
TCP_NIO

public class TCP
extends TP
implements ConnectionTable.Receiver

TCP based protocol. Creates a server socket, which gives us the local address of this group member. For each accept() on the server socket, a new thread is created that listens on the socket. For each outgoing message m, if m.dest is in the ougoing hashtable, the associated socket will be reused to send message, otherwise a new socket is created and put in the hashtable. When a socket connection breaks or a member is removed from the group, the corresponding items in the incoming and outgoing hashtables will be removed as well.
This functionality is in ConnectionTable, which isT used by TCP. TCP sends messages using ct.send() and registers with the connection table to receive all incoming messages.
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

TCP()

Method Summary

InetAddress
getBindAddr()
long
getConnExpireTime()
protected ConnectionTable
getConnectionTable(long reaperInterval, long connExpireTime, InetAddress bindAddress, InetAddress externalAddress, int startPort, int endPort)
int
getEndPort()
String
getInfo()
String
getName()
int
getOpenConnections()
long
getReaperInterval()
int
getStartPort()
protected void
handleDownEvent(Event evt)
boolean
isLoopback()
void
postUnmarshalling(Message msg, Address dest, Address src, boolean multicast)
void
postUnmarshallingList(Message msg, Address dest, boolean multicast)
String
printConnections()
void
receive(Address sender, byte[] data, int offset, int length)
ConnectionTable.Receiver interface
void
sendToAllMembers(byte[] data, int offset, int length)
void
sendToSingleMember(Address dest, byte[] data, int offset, int length)
void
setBindAddr(InetAddress bind_addr)
void
setConnExpireTime(long conn_expire_time)
void
setEndPort(int end_port)
void
setLoopback(boolean loopback)
boolean
setProperties(Properties props)
Setup the Protocol instance acording to the configuration string
void
setReaperInterval(long reaper_interval)
void
setStartPort(int start_port)
void
start()
void
stop()

Methods inherited from class org.jgroups.protocols.TP

down, dumpStats, getBindAddress, getBindToAllInterfaces, getChannelName, getIncomingQueueSize, getInfo, getLocalAddress, getMaxBundleSize, getMaxBundleTimeout, getNumBytesReceived, getNumBytesSent, getNumMessagesReceived, getNumMessagesSent, getOutgoingQueueMaxSize, getOutgoingQueueSize, getReceiveInterfaces, getSendInterfaces, handleConfigEvent, handleDownEvent, isDiscardIncompatiblePackets, isEnableBundling, isLoopback, isReceiveOnAllInterfaces, isSendOnAllInterfaces, isUseIncomingPacketHandler, isUseOutgoingPacketHandler, postUnmarshalling, postUnmarshallingList, receive, resetStats, sendToAllMembers, sendToSingleMember, setBindAddress, setBindToAllInterfaces, setDiscardIncompatiblePackets, setEnableBundling, setLoopback, setMaxBundleSize, setMaxBundleTimeout, setOutgoingQueueMaxSize, setProperties, start, startUpHandler, stop, toString, up

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

TCP

public TCP()

Method Details

getBindAddr

public InetAddress getBindAddr()

getConnExpireTime

public long getConnExpireTime()

getConnectionTable

protected ConnectionTable getConnectionTable(long reaperInterval,
                                             long connExpireTime,
                                             InetAddress bindAddress,
                                             InetAddress externalAddress,
                                             int startPort,
                                             int endPort)
            throws Exception
Parameters:
reaperInterval -
connExpireTime -
bindAddress -
startPort -
Returns:
ConnectionTable Sub classes overrides this method to initialize a different version of ConnectionTable.

getEndPort

public int getEndPort()

getInfo

public String getInfo()
Overrides:
getInfo in interface TP

getName

public String getName()
Overrides:
getName in interface Protocol

getOpenConnections

public int getOpenConnections()

getReaperInterval

public long getReaperInterval()

getStartPort

public int getStartPort()

handleDownEvent

protected void handleDownEvent(Event evt)
Overrides:
handleDownEvent in interface TP

isLoopback

public boolean isLoopback()
Overrides:
isLoopback in interface TP

postUnmarshalling

public void postUnmarshalling(Message msg,
                              Address dest,
                              Address src,
                              boolean multicast)
Overrides:
postUnmarshalling in interface TP

postUnmarshallingList

public void postUnmarshallingList(Message msg,
                                  Address dest,
                                  boolean multicast)
Overrides:
postUnmarshallingList in interface TP

printConnections

public String printConnections()

receive

public void receive(Address sender,
                    byte[] data,
                    int offset,
                    int length)
ConnectionTable.Receiver interface
Specified by:
receive in interface ConnectionTable.Receiver

sendToAllMembers

public void sendToAllMembers(byte[] data,
                             int offset,
                             int length)
            throws Exception
Overrides:
sendToAllMembers in interface TP

sendToSingleMember

public void sendToSingleMember(Address dest,
                               byte[] data,
                               int offset,
                               int length)
            throws Exception
Overrides:
sendToSingleMember in interface TP

setBindAddr

public void setBindAddr(InetAddress bind_addr)

setConnExpireTime

public void setConnExpireTime(long conn_expire_time)

setEndPort

public void setEndPort(int end_port)

setLoopback

public void setLoopback(boolean loopback)
Overrides:
setLoopback in interface TP

setProperties

public boolean setProperties(Properties props)
Setup the Protocol instance acording to the configuration string
Overrides:
setProperties in interface TP

setReaperInterval

public void setReaperInterval(long reaper_interval)

setStartPort

public void setStartPort(int start_port)

start

public void start()
            throws Exception
Overrides:
start in interface TP

stop

public void stop()
Overrides:
stop in interface TP

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