Package org.jgroups.protocols
Class TP
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.TP
- Direct Known Subclasses:
BasicTCP
,LOOPBACK
,SHARED_LOOPBACK
,TUNNEL
,UDP
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
sendToAllMembers(byte[], int, int)
sendToSingleMember(org.jgroups.Address, byte[], int, int)
init()
start()
: subclasses must call super.start() after they initialize themselves (e.g., created their sockets).stop()
: subclasses must call super.stop() after they deinitialized themselvesdestroy()
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.160.2.38 2008/12/12 08:09:27 belaban Exp $
- Author:
- Bela Ban
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetAddress
The interface (NIC) which should be used by this transportprotected String
The name of the group to which this member is connectedprotected boolean
Discard packets with a different version.protected ThreadFactory
Used by all threads created by JGroups outside of the thread poolsprotected Address
The address (host and port) of this memberThe members of this group (updated when a member joins or leaves)protected boolean
protected String
protected PortsManager
protected long
protected String
Names the current thread.protected TimeScheduler
================================== Timer thread pool =================================protected ThreadFactory
protected View
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TP()
Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads. -
Method Summary
Modifier and TypeMethodDescriptionprotected static ExecutorService
createThreadPool
(int min_threads, int max_threads, long keep_alive_time, String rejection_policy, BlockingQueue<Runnable> queue, ThreadFactory factory) void
destroy()
This method is called on aChannel.close()
.Caller by the layer above this layer.int
boolean
Deprecated.long
int
int
long
int
int
int
abstract String
getInfo()
int
long
long
long
long
long
long
int
int
long
int
int
int
Supposed to be overwritten by subclasses.getTimer()
protected void
handleConfigEvent
(Map<String, Object> map) protected void
protected void
protected Object
handleDownEvent
(Event evt) void
init()
Called after instance has been created (null constructor) and before protocol is started.boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
protected void
abstract void
postUnmarshalling
(Message msg, Address dest, Address src, boolean multicast) abstract void
postUnmarshallingList
(Message msg, Address dest, boolean multicast) protected final void
Subclasses must call this method when a unicast or multicast message has been received.void
registerProbeHandler
(TP.ProbeHandler handler) void
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
void
setBindAddress
(String bind_addr) void
setBindPort
(int port) void
setBindToAllInterfaces
(boolean flag) void
setDefaultThreadPool
(Executor thread_pool) void
void
setDiscardIncompatiblePackets
(boolean flag) void
setEnable_unicast_bundling
(boolean enable_unicast_bundling) void
setEnableBundling
(boolean flag) void
setIncomingKeepAliveTime
(long time) void
setIncomingMaxPoolSize
(int size) void
setIncomingMinPoolSize
(int size) void
setLoopback
(boolean b) void
setMaxBundleSize
(int size) void
setMaxBundleTimeout
(long timeout) void
setOOBKeepAliveTime
(long time) void
setOOBMaxPoolSize
(int size) void
setOOBMinPoolSize
(int size) void
setOOBThreadPool
(Executor oob_thread_pool) void
boolean
setProperties
(Properties props) Setup the Protocol instance according to the configuration stringvoid
setThreadFactory
(ThreadFactory factory) protected void
void
setTimerThreadFactory
(ThreadFactory factory) void
start()
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsvoid
stop()
This method is called on aChannel.disconnect()
.toString()
debug onlyvoid
unregisterProbeHandler
(TP.ProbeHandler handler) protected void
handle the UP event.Methods inherited from class org.jgroups.stack.Protocol
downThreadEnabled, enableStats, getDownProtocol, getName, getProperties, getProtocolStack, getTransport, getUpProtocol, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, setDownProtocol, setPropertiesInternal, setProtocolStack, setUpProtocol, statsEnabled, upThreadEnabled
-
Field Details
-
local_addr
The address (host and port) of this member -
channel_name
The name of the group to which this member is connected -
bind_addr
The interface (NIC) which should be used by this transport -
members
The members of this group (updated when a member joins or leaves) -
view
-
discard_incompatible_packets
protected boolean discard_incompatible_packetsDiscard packets with a different version. Usually minor version differences are okay. Setting this property to true means that we expect the exact same version on all incoming packets -
thread_naming_pattern
Names the current thread. Valid values are "pcl": p: include the previous (original) name, e.g. "Incoming thread-1", "UDP ucast receiver" c: include the cluster name, e.g. "MyCluster" l: include the local address of the current member, e.g. "192.168.5.1:5678" -
timer
================================== Timer thread pool ================================= -
timer_thread_factory
-
global_thread_factory
Used by all threads created by JGroups outside of the thread pools -
pm
-
persistent_ports_file
-
pm_expiry_time
protected long pm_expiry_time -
persistent_ports
protected boolean persistent_ports
-
-
Constructor Details
-
TP
protected TP()Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads.
-
-
Method Details
-
getThreadNamingPattern
-
getOOBThreadPool
-
setOOBThreadPool
-
getOOBThreadPoolThreadFactory
-
setOOBThreadPoolThreadFactory
-
getDefaultThreadPool
-
setDefaultThreadPool
-
getDefaultThreadPoolThreadFactory
-
setDefaultThreadPoolThreadFactory
-
getTimerThreadFactory
-
setTimerThreadFactory
-
getTimer
-
getThreadFactory
Description copied from class:Protocol
Supposed to be overwritten by subclasses. Usually the transport returns a valid non-null thread factory, but thread factories can also be created by individual protocols- Overrides:
getThreadFactory
in classProtocol
- Returns:
-
setThreadFactory
-
toString
debug only -
resetStats
public void resetStats()- Overrides:
resetStats
in classProtocol
-
registerProbeHandler
-
unregisterProbeHandler
-
getNumMessagesSent
public long getNumMessagesSent() -
getNumMessagesReceived
public long getNumMessagesReceived() -
getNumBytesSent
public long getNumBytesSent() -
getNumBytesReceived
public long getNumBytesReceived() -
getBindAddress
-
setBindAddress
- Throws:
UnknownHostException
-
getBindPort
public int getBindPort() -
setBindPort
public void setBindPort(int port) -
getBindToAllInterfaces
public boolean getBindToAllInterfaces()Deprecated.UseisReceiveOnAllInterfaces()
instead -
setBindToAllInterfaces
public void setBindToAllInterfaces(boolean flag) -
isReceiveOnAllInterfaces
public boolean isReceiveOnAllInterfaces() -
getReceiveInterfaces
-
isSendOnAllInterfaces
public boolean isSendOnAllInterfaces() -
getSendInterfaces
-
isDiscardIncompatiblePackets
public boolean isDiscardIncompatiblePackets() -
setDiscardIncompatiblePackets
public void setDiscardIncompatiblePackets(boolean flag) -
isEnableBundling
public boolean isEnableBundling() -
setEnableBundling
public void setEnableBundling(boolean flag) -
isEnable_unicast_bundling
public boolean isEnable_unicast_bundling() -
setEnable_unicast_bundling
public void setEnable_unicast_bundling(boolean enable_unicast_bundling) -
getMaxBundleSize
public int getMaxBundleSize() -
setMaxBundleSize
public void setMaxBundleSize(int size) -
getMaxBundleTimeout
public long getMaxBundleTimeout() -
setMaxBundleTimeout
public void setMaxBundleTimeout(long timeout) -
getLocalAddress
-
getChannelName
-
isLoopback
public boolean isLoopback() -
setLoopback
public void setLoopback(boolean b) -
isUseIncomingPacketHandler
public boolean isUseIncomingPacketHandler() -
isDefaulThreadPoolEnabled
public boolean isDefaulThreadPoolEnabled() -
isOOBThreadPoolEnabled
public boolean isOOBThreadPoolEnabled() -
getUpProtocols
-
getOOBMinPoolSize
public int getOOBMinPoolSize() -
setOOBMinPoolSize
public void setOOBMinPoolSize(int size) -
getOOBMaxPoolSize
public int getOOBMaxPoolSize() -
setOOBMaxPoolSize
public void setOOBMaxPoolSize(int size) -
getOOBPoolSize
public int getOOBPoolSize() -
getOOBKeepAliveTime
public long getOOBKeepAliveTime() -
setOOBKeepAliveTime
public void setOOBKeepAliveTime(long time) -
getOOBMessages
public long getOOBMessages() -
getOOBQueueSize
public int getOOBQueueSize() -
getOOBMaxQueueSize
public int getOOBMaxQueueSize() -
getIncomingMinPoolSize
public int getIncomingMinPoolSize() -
setIncomingMinPoolSize
public void setIncomingMinPoolSize(int size) -
getIncomingMaxPoolSize
public int getIncomingMaxPoolSize() -
setIncomingMaxPoolSize
public void setIncomingMaxPoolSize(int size) -
getIncomingPoolSize
public int getIncomingPoolSize() -
getIncomingKeepAliveTime
public long getIncomingKeepAliveTime() -
setIncomingKeepAliveTime
public void setIncomingKeepAliveTime(long time) -
getIncomingMessages
public long getIncomingMessages() -
getIncomingQueueSize
public int getIncomingQueueSize() -
getIncomingMaxQueueSize
public int getIncomingMaxQueueSize() -
dumpStats
-
sendToAllMembers
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 itoffset
-length
-- Throws:
Exception
-
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 addressdata
- The data to be sent. This is not a copy, so don't modify itoffset
-length
-- Throws:
Exception
-
getInfo
-
postUnmarshalling
-
postUnmarshallingList
-
init
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. -
destroy
public void destroy()Description copied from class:Protocol
This method is called on aChannel.close()
. Does some cleanup; after the call the VM will terminate -
start
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Overrides:
start
in classProtocol
- Throws:
Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soChannel.connect(String)
will throw an exception
-
stop
public void stop()Description copied from class:Protocol
This method is called on aChannel.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 -
handleConnect
- Throws:
Exception
-
handleDisconnect
protected void handleDisconnect() -
getSingletonName
-
setProperties
Setup the Protocol instance according to the configuration string- Overrides:
setProperties
in classProtocol
- 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
-
up
handle the UP event. -
down
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()). -
receive
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
-
setThreadNames
protected void setThreadNames() -
unsetThreadNames
protected void unsetThreadNames() -
handleConfigEvent
-
createThreadPool
protected static ExecutorService createThreadPool(int min_threads, int max_threads, long keep_alive_time, String rejection_policy, BlockingQueue<Runnable> queue, ThreadFactory factory) -
passToAllUpProtocols
-
sendUpLocalAddressEvent
public void sendUpLocalAddressEvent()
-
isReceiveOnAllInterfaces()
instead