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 interfacestatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetAddressThe interface (NIC) which should be used by this transportprotected StringThe name of the group to which this member is connectedprotected booleanDiscard packets with a different version.protected ThreadFactoryUsed by all threads created by JGroups outside of the thread poolsprotected AddressThe address (host and port) of this memberThe members of this group (updated when a member joins or leaves)protected booleanprotected Stringprotected PortsManagerprotected longprotected StringNames the current thread.protected TimeScheduler================================== Timer thread pool =================================protected ThreadFactoryprotected View -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTP()Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads. -
Method Summary
Modifier and TypeMethodDescriptionprotected static ExecutorServicecreateThreadPool(int min_threads, int max_threads, long keep_alive_time, String rejection_policy, BlockingQueue<Runnable> queue, ThreadFactory factory) voiddestroy()This method is called on aChannel.close().Caller by the layer above this layer.intbooleanDeprecated.longintintlongintintintabstract StringgetInfo()intlonglonglonglonglonglongintintlongintintintSupposed to be overwritten by subclasses.getTimer()protected voidhandleConfigEvent(Map<String, Object> map) protected voidprotected voidprotected ObjecthandleDownEvent(Event evt) voidinit()Called after instance has been created (null constructor) and before protocol is started.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanprotected voidabstract voidpostUnmarshalling(Message msg, Address dest, Address src, boolean multicast) abstract voidpostUnmarshallingList(Message msg, Address dest, boolean multicast) protected final voidSubclasses must call this method when a unicast or multicast message has been received.voidregisterProbeHandler(TP.ProbeHandler handler) voidabstract 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.voidvoidsetBindAddress(String bind_addr) voidsetBindPort(int port) voidsetBindToAllInterfaces(boolean flag) voidsetDefaultThreadPool(Executor thread_pool) voidvoidsetDiscardIncompatiblePackets(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(Executor oob_thread_pool) voidbooleansetProperties(Properties props) Setup the Protocol instance according to the configuration stringvoidsetThreadFactory(ThreadFactory factory) protected voidvoidsetTimerThreadFactory(ThreadFactory factory) voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsvoidstop()This method is called on aChannel.disconnect().toString()debug onlyvoidunregisterProbeHandler(TP.ProbeHandler handler) protected voidhandle 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: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
-
toString
debug only -
resetStats
public void resetStats()- Overrides:
resetStatsin 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: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
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads- Overrides:
startin 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: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
- Throws:
Exception
-
handleDisconnect
protected void handleDisconnect() -
getSingletonName
-
setProperties
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
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