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
public abstract class TP extends Protocol
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 Classes Modifier and Type Class Description static interface
TP.ProbeHandler
static class
TP.ProtocolAdapter
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetAddress
bind_addr
The interface (NIC) which should be used by this transportprotected java.lang.String
channel_name
The name of the group to which this member is connectedprotected boolean
discard_incompatible_packets
Discard packets with a different version.protected ThreadFactory
global_thread_factory
Used by all threads created by JGroups outside of the thread poolsprotected Address
local_addr
The address (host and port) of this memberprotected java.util.HashSet<Address>
members
The members of this group (updated when a member joins or leaves)protected boolean
persistent_ports
protected java.lang.String
persistent_ports_file
protected PortsManager
pm
protected long
pm_expiry_time
protected java.lang.String
thread_naming_pattern
Names the current thread.protected TimeScheduler
timer
================================== Timer thread pool =================================protected ThreadFactory
timer_thread_factory
protected View
view
-
Constructor Summary
Constructors Modifier Constructor Description protected
TP()
Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static java.util.concurrent.ExecutorService
createThreadPool(int min_threads, int max_threads, long keep_alive_time, java.lang.String rejection_policy, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, ThreadFactory factory)
void
destroy()
This method is called on aChannel.close()
.java.lang.Object
down(Event evt)
Caller by the layer above this layer.java.util.Map<java.lang.String,java.lang.Object>
dumpStats()
java.lang.String
getBindAddress()
int
getBindPort()
boolean
getBindToAllInterfaces()
Deprecated.UseisReceiveOnAllInterfaces()
insteadjava.lang.String
getChannelName()
java.util.concurrent.Executor
getDefaultThreadPool()
ThreadFactory
getDefaultThreadPoolThreadFactory()
long
getIncomingKeepAliveTime()
int
getIncomingMaxPoolSize()
int
getIncomingMaxQueueSize()
long
getIncomingMessages()
int
getIncomingMinPoolSize()
int
getIncomingPoolSize()
int
getIncomingQueueSize()
abstract java.lang.String
getInfo()
Address
getLocalAddress()
int
getMaxBundleSize()
long
getMaxBundleTimeout()
long
getNumBytesReceived()
long
getNumBytesSent()
long
getNumMessagesReceived()
long
getNumMessagesSent()
long
getOOBKeepAliveTime()
int
getOOBMaxPoolSize()
int
getOOBMaxQueueSize()
long
getOOBMessages()
int
getOOBMinPoolSize()
int
getOOBPoolSize()
int
getOOBQueueSize()
java.util.concurrent.Executor
getOOBThreadPool()
ThreadFactory
getOOBThreadPoolThreadFactory()
java.util.List
getReceiveInterfaces()
java.util.List
getSendInterfaces()
java.lang.String
getSingletonName()
ThreadFactory
getThreadFactory()
Supposed to be overwritten by subclasses.java.lang.String
getThreadNamingPattern()
TimeScheduler
getTimer()
ThreadFactory
getTimerThreadFactory()
java.util.concurrent.ConcurrentMap<java.lang.String,Protocol>
getUpProtocols()
protected void
handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)
protected void
handleConnect()
protected void
handleDisconnect()
protected java.lang.Object
handleDownEvent(Event evt)
void
init()
Called after instance has been created (null constructor) and before protocol is started.boolean
isDefaulThreadPoolEnabled()
boolean
isDiscardIncompatiblePackets()
boolean
isEnable_unicast_bundling()
boolean
isEnableBundling()
boolean
isLoopback()
boolean
isOOBThreadPoolEnabled()
boolean
isReceiveOnAllInterfaces()
boolean
isSendOnAllInterfaces()
boolean
isUseIncomingPacketHandler()
protected void
passToAllUpProtocols(Event evt)
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
registerProbeHandler(TP.ProbeHandler handler)
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
sendUpLocalAddressEvent()
void
setBindAddress(java.lang.String bind_addr)
void
setBindPort(int port)
void
setBindToAllInterfaces(boolean flag)
void
setDefaultThreadPool(java.util.concurrent.Executor thread_pool)
void
setDefaultThreadPoolThreadFactory(ThreadFactory factory)
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(java.util.concurrent.Executor oob_thread_pool)
void
setOOBThreadPoolThreadFactory(ThreadFactory factory)
boolean
setProperties(java.util.Properties props)
Setup the Protocol instance according to the configuration stringvoid
setThreadFactory(ThreadFactory factory)
protected void
setThreadNames()
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()
.java.lang.String
toString()
debug onlyvoid
unregisterProbeHandler(TP.ProbeHandler handler)
protected void
unsetThreadNames()
java.lang.Object
up(Event evt)
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 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.HashSet<Address> members
The members of this group (updated when a member joins or leaves)
-
view
protected View view
-
discard_incompatible_packets
protected boolean discard_incompatible_packets
Discard 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
protected java.lang.String 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
protected TimeScheduler timer
================================== Timer thread pool =================================
-
timer_thread_factory
protected ThreadFactory timer_thread_factory
-
global_thread_factory
protected ThreadFactory global_thread_factory
Used by all threads created by JGroups outside of the thread pools
-
pm
protected PortsManager pm
-
persistent_ports_file
protected java.lang.String persistent_ports_file
-
pm_expiry_time
protected long pm_expiry_time
-
persistent_ports
protected boolean persistent_ports
-
-
Method Detail
-
getThreadNamingPattern
public java.lang.String getThreadNamingPattern()
-
getOOBThreadPool
public java.util.concurrent.Executor getOOBThreadPool()
-
setOOBThreadPool
public void setOOBThreadPool(java.util.concurrent.Executor oob_thread_pool)
-
getOOBThreadPoolThreadFactory
public ThreadFactory getOOBThreadPoolThreadFactory()
-
setOOBThreadPoolThreadFactory
public void setOOBThreadPoolThreadFactory(ThreadFactory factory)
-
getDefaultThreadPool
public java.util.concurrent.Executor getDefaultThreadPool()
-
setDefaultThreadPool
public void setDefaultThreadPool(java.util.concurrent.Executor thread_pool)
-
getDefaultThreadPoolThreadFactory
public ThreadFactory getDefaultThreadPoolThreadFactory()
-
setDefaultThreadPoolThreadFactory
public void setDefaultThreadPoolThreadFactory(ThreadFactory factory)
-
getTimerThreadFactory
public ThreadFactory getTimerThreadFactory()
-
setTimerThreadFactory
public void setTimerThreadFactory(ThreadFactory factory)
-
getTimer
public TimeScheduler getTimer()
-
getThreadFactory
public ThreadFactory 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
public void setThreadFactory(ThreadFactory factory)
-
toString
public java.lang.String toString()
debug only- Overrides:
toString
in classjava.lang.Object
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
registerProbeHandler
public void registerProbeHandler(TP.ProbeHandler handler)
-
unregisterProbeHandler
public void unregisterProbeHandler(TP.ProbeHandler handler)
-
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
-
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
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)
-
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
public Address getLocalAddress()
-
getChannelName
public java.lang.String getChannelName()
-
isLoopback
public boolean isLoopback()
-
setLoopback
public void setLoopback(boolean b)
-
isUseIncomingPacketHandler
public boolean isUseIncomingPacketHandler()
-
isDefaulThreadPoolEnabled
public boolean isDefaulThreadPoolEnabled()
-
isOOBThreadPoolEnabled
public boolean isOOBThreadPoolEnabled()
-
getUpProtocols
public java.util.concurrent.ConcurrentMap<java.lang.String,Protocol> 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
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
-
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 itoffset
-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 addressdata
- The data to be sent. This is not a copy, so don't modify itoffset
-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.
-
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
public void start() throws java.lang.Exception
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Overrides:
start
in classProtocol
- Throws:
java.lang.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
protected void handleConnect() throws java.lang.Exception
- Throws:
java.lang.Exception
-
handleDisconnect
protected void handleDisconnect()
-
getSingletonName
public java.lang.String getSingletonName()
-
setProperties
public boolean setProperties(java.util.Properties props)
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
public java.lang.Object up(Event evt)
handle the UP event.
-
down
public java.lang.Object 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()).
-
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 java.lang.Object handleDownEvent(Event evt)
-
setThreadNames
protected void setThreadNames()
-
unsetThreadNames
protected void unsetThreadNames()
-
handleConfigEvent
protected void handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)
-
createThreadPool
protected static java.util.concurrent.ExecutorService createThreadPool(int min_threads, int max_threads, long keep_alive_time, java.lang.String rejection_policy, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, ThreadFactory factory)
-
passToAllUpProtocols
protected void passToAllUpProtocols(Event evt)
-
sendUpLocalAddressEvent
public void sendUpLocalAddressEvent()
-
-