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 interfaceTP.ProbeHandlerstatic classTP.ProtocolAdapter
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetAddressbind_addrThe interface (NIC) which should be used by this transportprotected java.lang.Stringchannel_nameThe name of the group to which this member is connectedprotected booleandiscard_incompatible_packetsDiscard packets with a different version.protected ThreadFactoryglobal_thread_factoryUsed by all threads created by JGroups outside of the thread poolsprotected Addresslocal_addrThe address (host and port) of this memberprotected java.util.HashSet<Address>membersThe members of this group (updated when a member joins or leaves)protected booleanpersistent_portsprotected java.lang.Stringpersistent_ports_fileprotected PortsManagerpmprotected longpm_expiry_timeprotected java.lang.Stringthread_naming_patternNames the current thread.protected TimeSchedulertimer================================== Timer thread pool =================================protected ThreadFactorytimer_thread_factoryprotected Viewview
-
Constructor Summary
Constructors Modifier Constructor Description protectedTP()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.ExecutorServicecreateThreadPool(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)voiddestroy()This method is called on aChannel.close().java.lang.Objectdown(Event evt)Caller by the layer above this layer.java.util.Map<java.lang.String,java.lang.Object>dumpStats()java.lang.StringgetBindAddress()intgetBindPort()booleangetBindToAllInterfaces()Deprecated.UseisReceiveOnAllInterfaces()insteadjava.lang.StringgetChannelName()java.util.concurrent.ExecutorgetDefaultThreadPool()ThreadFactorygetDefaultThreadPoolThreadFactory()longgetIncomingKeepAliveTime()intgetIncomingMaxPoolSize()intgetIncomingMaxQueueSize()longgetIncomingMessages()intgetIncomingMinPoolSize()intgetIncomingPoolSize()intgetIncomingQueueSize()abstract java.lang.StringgetInfo()AddressgetLocalAddress()intgetMaxBundleSize()longgetMaxBundleTimeout()longgetNumBytesReceived()longgetNumBytesSent()longgetNumMessagesReceived()longgetNumMessagesSent()longgetOOBKeepAliveTime()intgetOOBMaxPoolSize()intgetOOBMaxQueueSize()longgetOOBMessages()intgetOOBMinPoolSize()intgetOOBPoolSize()intgetOOBQueueSize()java.util.concurrent.ExecutorgetOOBThreadPool()ThreadFactorygetOOBThreadPoolThreadFactory()java.util.ListgetReceiveInterfaces()java.util.ListgetSendInterfaces()java.lang.StringgetSingletonName()ThreadFactorygetThreadFactory()Supposed to be overwritten by subclasses.java.lang.StringgetThreadNamingPattern()TimeSchedulergetTimer()ThreadFactorygetTimerThreadFactory()java.util.concurrent.ConcurrentMap<java.lang.String,Protocol>getUpProtocols()protected voidhandleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> map)protected voidhandleConnect()protected voidhandleDisconnect()protected java.lang.ObjecthandleDownEvent(Event evt)voidinit()Called after instance has been created (null constructor) and before protocol is started.booleanisDefaulThreadPoolEnabled()booleanisDiscardIncompatiblePackets()booleanisEnable_unicast_bundling()booleanisEnableBundling()booleanisLoopback()booleanisOOBThreadPoolEnabled()booleanisReceiveOnAllInterfaces()booleanisSendOnAllInterfaces()booleanisUseIncomingPacketHandler()protected voidpassToAllUpProtocols(Event evt)abstract voidpostUnmarshalling(Message msg, Address dest, Address src, boolean multicast)abstract voidpostUnmarshallingList(Message msg, Address dest, boolean multicast)protected voidreceive(Address dest, Address sender, byte[] data, int offset, int length)Subclasses must call this method when a unicast or multicast message has been received.voidregisterProbeHandler(TP.ProbeHandler handler)voidresetStats()abstract voidsendToAllMembers(byte[] data, int offset, int length)Send to all members in the group.abstract voidsendToSingleMember(Address dest, byte[] data, int offset, int length)Send to all members in the group.voidsendUpLocalAddressEvent()voidsetBindAddress(java.lang.String bind_addr)voidsetBindPort(int port)voidsetBindToAllInterfaces(boolean flag)voidsetDefaultThreadPool(java.util.concurrent.Executor thread_pool)voidsetDefaultThreadPoolThreadFactory(ThreadFactory factory)voidsetDiscardIncompatiblePackets(boolean flag)voidsetEnable_unicast_bundling(boolean enable_unicast_bundling)voidsetEnableBundling(boolean flag)voidsetIncomingKeepAliveTime(long time)voidsetIncomingMaxPoolSize(int size)voidsetIncomingMinPoolSize(int size)voidsetLoopback(boolean b)voidsetMaxBundleSize(int size)voidsetMaxBundleTimeout(long timeout)voidsetOOBKeepAliveTime(long time)voidsetOOBMaxPoolSize(int size)voidsetOOBMinPoolSize(int size)voidsetOOBThreadPool(java.util.concurrent.Executor oob_thread_pool)voidsetOOBThreadPoolThreadFactory(ThreadFactory factory)booleansetProperties(java.util.Properties props)Setup the Protocol instance according to the configuration stringvoidsetThreadFactory(ThreadFactory factory)protected voidsetThreadNames()voidsetTimerThreadFactory(ThreadFactory factory)voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsvoidstop()This method is called on aChannel.disconnect().java.lang.StringtoString()debug onlyvoidunregisterProbeHandler(TP.ProbeHandler handler)protected voidunsetThreadNames()java.lang.Objectup(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:ProtocolSupposed 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:
getThreadFactoryin classProtocol- Returns:
-
setThreadFactory
public void setThreadFactory(ThreadFactory factory)
-
toString
public java.lang.String toString()
debug only- Overrides:
toStringin classjava.lang.Object
-
resetStats
public void resetStats()
- Overrides:
resetStatsin 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.ExceptionSend 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.ExceptionDescription copied from class:ProtocolCalled 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:ProtocolThis method is called on aChannel.close(). Does some cleanup; after the call the VM will terminate
-
start
public void start() throws java.lang.ExceptionCreates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Overrides:
startin 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:ProtocolThis 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:
setPropertiesin 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()
-
-