Package org.jgroups.protocols
Class TP
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.TP
- All Implemented Interfaces:
Lifecycle,DiagnosticsHandler.ProbeHandler
- Direct Known Subclasses:
BasicTCP,SHARED_LOOPBACK,SimpleTCP,TUNNEL,UDP
Generic transport - specific implementations should extend this abstract class.
Features which are provided to the subclasses include
The
- version checking
- marshalling and unmarshalling
- message bundling (handling single messages, and message lists)
- incoming packet handler
sendUnicast(org.jgroups.PhysicalAddress, 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()
The
receive(Address, byte[], int, int) method must
be called by subclasses when a unicast or multicast message has been received.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AsyncExecutor<Object> protected InetAddressprotected intThe port to which the transport binds.protected Bundlerprotected Stringprotected AsciiStringThe name of the group to which this member is connected.protected final ReentrantLockprotected DiagnosticsHandlerprotected InetAddressprotected intprotected TpHeaderThe header including the cluster name, sent with each messageprotected booleanprotected longstatic final byteprotected PhysicalAddressThe address (host and port) of this memberprotected LocalTransportprotected Stringprotected booleanWhether warnings about messages from different groups are logged - private flag, not for common useprotected booleanprotected LazyRemovalCache<Address, PhysicalAddress> Cache which maintains mappings between logical and physical addresses.protected longprotected intprotected Future<?> protected longprotected booleanprotected booleanThe members of this group (updated when a member joins or leaves).protected Stringprotected static final longprotected MessageFactoryprotected Stringstatic final intprotected MessageProcessingPolicyprotected final MsgStatsstatic final byteprotected intprotected static final LazyRemovalCache.Printable<Address, LazyRemovalCache.Entry<PhysicalAddress>> protected List<NetworkInterface> List of interfaces to receive multicasts on.protected booleanprotected RTTprotected SocketFactoryprotected SuppressLog<Address> Log to suppress identical warnings for messages from members in different clustersprotected SuppressLog<Address> Log to suppress identical warnings for messages from members with different (incompatible) versionsprotected longprotected longprotected ThreadFactoryFactory which is used by the thread poolprotected Stringprotected ThreadPoolThe thread pool which handles unmarshalling, version checks and dispatching of messagesprotected TimeServiceprotected longprotected TimeSchedulerprotected booleanprotected booleanprotected Viewprotected ExpiryCache<Address> Cache keeping track of WHO_HAS requests for physical addresses (given a logical address) and expiring them after who_has_cache_timeout msprotected longFields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleanaddPhysicalAddressToCache(Address logical_addr, PhysicalAddress physical_addr) protected booleanaddPhysicalAddressToCache(Address logical_addr, PhysicalAddress physical_addr, boolean overwrite) <T extends TP>
T<T extends TP>
T<T extends TP>
TvoidClears the cache.static BundlercreateBundler(String type, Class<?> cl) protected DiagnosticsHandlerdefaultHeaders(boolean detailed) voiddestroy()This method is called on aJChannel.close().voidvoidAn event is to be sent down the stack.A message needs to be sent to a single member or all members<T extends TP>
TenableBlockingTimerTasks(boolean flag) <T extends TP>
TvoidenableStats(boolean flag) voidvoidevictLogicalAddressCache(boolean force) protected voidGrabs the local address (or addresses in the shared transport case) and registers them with the physical address in the transport's cacheprotected voidfetchPhysicalAddrs(List<Address> missing) protected ResponsesfetchResponsesFromDiscoveryProtocol(List<Address> missing) protected Collection<PhysicalAddress> intintintintabstract StringgetInfo()booleanbooleanlongintlonglongDeprecated.longDeprecated.longDeprecated.longDeprecated.static intintlongDeprecated.longDeprecated.protected abstract PhysicalAddressgetPhysicalAddressFromCache(Address logical_addr) intgetRTT()Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call downlonglongSupposed to be overwritten by subclasses.Names the current thread.getTimer()intlonglongprotected voidprotected voidprotected voidhandleMessageBatch(DataInput in, boolean multicast, MessageFactory factory) handleProbe(String... keys) Handles a probe.protected voidhandleSingleMessage(DataInput in, boolean multicast) voidinit()Called after a protocol has been created and before the protocol is started.booleanbooleanbooleanbooleanisTrace()<T extends TP>
TisTrace(boolean i) boolean<T extends TP>
TlogDiscardMsgs(boolean l) boolean<T extends TP>
TlogDiscardMsgsVersion(boolean l) static Stringprotected voidboolean<T extends TP>
TloopbackCopy(boolean l) boolean<T extends TP>
TloopbackSeparateThread(boolean l) voidpassBatchUp(MessageBatch batch, boolean perform_cluster_name_matching, boolean discard_own_mcast) voidpassMessageUp(Message msg, byte[] cluster_name, boolean perform_cluster_name_matching, boolean multicast, boolean discard_own_mcast) protected voidprocessBatch(MessageBatch batch, boolean oob) voidSubclasses must call this method when a unicast or multicast message has been received.voidboolean<T extends TP>
TreceiveOnAllInterfaces(boolean r) protected voidregisterLocalAddress(Address addr) Associates the address with the physical address fetched from the cache<T extends TP>
Tvoidprotected voidremoveLogicalAddressFromCache(Address logical_addr) voidprotected booleansameCluster(String req) protected voidprotected voidsendToAll(byte[] buf, int offset, int length) Fetches the physical addrs for all mbrs and sends the msg to each physical address.abstract voidsendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) Send a unicast to a member.<T extends Protocol>
TsetAddress(Address addr) <T extends TP>
T<T extends TP>
T<T extends TP>
T<T extends TP>
TsetBindPort(int port) <T extends TP>
TsetBindToAllInterfaces(boolean f) <T extends TP>
TsetBundler(Bundler bundler) Installs a bundler<T extends TP>
T<T extends TP>
TsetDiagnosticsHandler(DiagnosticsHandler handler) Sets aDiagnosticsHandler.<T extends TP>
T<T extends TP>
TsetExternalPort(int e) protected voidsetInAllThreadFactories(String cluster_name, Address local_address, String pattern) <T extends Protocol>
TSets the level of a logger.<T extends TP>
TsetLocalTransport(String tp_class) <T extends TP>
T<T extends TP>
TsetLogDiscardMessages(boolean flag) <T extends TP>
TsetLogDiscardMessagesVersion(boolean f) <T extends TP>
TsetLogicalAddrCacheExpiration(long l) <T extends TP>
TsetLogicalAddrCacheMaxSize(int l) <T extends TP>
T<T extends TP>
TvoidsetMessageProcessingPolicy(String policy) <T extends TP>
T<T extends TP>
TsetPortRange(int range) voidsetSocketFactory(SocketFactory factory) Sets a SocketFactory.protected voidsetSourceAddress(Message msg) If the sender is null, set our own address.<T extends TP>
T<T extends TP>
T<T extends TP>
TsetThreadFactory(ThreadFactory factory) protected void<T extends TP>
TsetThreadPool(Executor thread_pool) <T extends TP>
TsetTimer(TimeScheduler timer) Sets a new timer.<T extends TP>
T<T extends TP>
TsetTimeServiceInterval(long t) <T extends TP>
TsetWhoHasCacheTimeout(long w) voidstart()Creates the unicast and multicast sockets and starts the unicast and multicast receiver threadsprotected voidvoidstop()Called on aJChannel.disconnect(); stops work (e.g.protected voidString[]Returns a list of supported keysabstract booleanWhether hardware multicasting is supportedprotected longtoString()booleanunicastDestMismatch(Address dest) <T extends TP>
Tprotected voidboolean<T extends TP>
TuseVirtualThreads(boolean b) protected booleanversionMatch(short version, Address sender) view()Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, down, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setPolicies, setProtocolStack, setUpProtocol, setValue, statsEnabled, up, up, up
-
Field Details
-
LIST
public static final byte LIST- See Also:
-
MULTICAST
public static final byte MULTICAST- See Also:
-
MSG_OVERHEAD
public static final int MSG_OVERHEAD- See Also:
-
MIN_WAIT_BETWEEN_DISCOVERIES
protected static final long MIN_WAIT_BETWEEN_DISCOVERIES -
bind_addr
-
external_addr
-
external_port
protected int external_port -
is_trace
protected boolean is_trace -
receive_on_all_interfaces
protected boolean receive_on_all_interfaces -
receive_interfaces
List of interfaces to receive multicasts on. The multicast receive socket will listen on all of these interfaces. This is a comma-separated list of IP addresses or interface names. E.g. "192.168.5.1,eth1,127.0.0.1". Duplicates are discarded; we only bind to an interface once. If this property is set, it overrides receive_on_all_interfaces. -
logical_addr_cache_max_size
protected int logical_addr_cache_max_size -
logical_addr_cache_expiration
protected long logical_addr_cache_expiration -
logical_addr_cache_reaper_interval
protected long logical_addr_cache_reaper_interval -
bind_port
protected int bind_portThe port to which the transport binds. 0 means to bind to any (ephemeral) port. See alsoport_range -
port_range
protected int port_range -
loopback_copy
protected boolean loopback_copy -
loopback_separate_thread
protected boolean loopback_separate_thread -
message_processing_policy
-
local_transport_class
-
use_virtual_threads
protected boolean use_virtual_threads -
thread_naming_pattern
-
time_service_interval
protected long time_service_interval -
log_discard_msgs
protected boolean log_discard_msgsWhether warnings about messages from different groups are logged - private flag, not for common use -
log_discard_msgs_version
protected boolean log_discard_msgs_version -
who_has_cache_timeout
protected long who_has_cache_timeout -
suppress_time_different_version_warnings
protected long suppress_time_different_version_warnings -
suppress_time_different_cluster_warnings
protected long suppress_time_different_cluster_warnings -
msg_factory_class
-
msg_factory
-
bundler_type
-
msg_stats
-
cluster_name
The name of the group to which this member is connected. With a shared transport, the channel name is in TP.ProtocolAdapter (cluster_name), and this field is not used -
timer_handle_non_blocking_tasks
protected boolean timer_handle_non_blocking_tasks -
local_physical_addr
The address (host and port) of this member -
view
-
members
The members of this group (updated when a member joins or leaves). With a shared transport, members contains _all_ members from all channels sitting on the shared transport -
connectLock
-
thread_pool
The thread pool which handles unmarshalling, version checks and dispatching of messages -
async_executor
-
thread_factory
Factory which is used by the thread pool -
timer
-
time_service
-
socket_factory
-
bundler
-
msg_processing_policy
-
local_transport
-
diag_handler
-
rtt
-
header
The header including the cluster name, sent with each message -
logical_addr_cache
Cache which maintains mappings between logical and physical addresses. When sending a message to a logical address, we look up the physical address from logical_addr_cache and send the message to the physical addressThe keys are logical addresses, the values physical addresses
-
last_discovery_request
protected long last_discovery_request -
logical_addr_cache_reaper
-
print_function
protected static final LazyRemovalCache.Printable<Address,LazyRemovalCache.Entry<PhysicalAddress>> print_function -
who_has_cache
Cache keeping track of WHO_HAS requests for physical addresses (given a logical address) and expiring them after who_has_cache_timeout ms -
suppress_log_different_version
Log to suppress identical warnings for messages from members with different (incompatible) versions -
suppress_log_different_cluster
Log to suppress identical warnings for messages from members in different clusters
-
-
Constructor Details
-
TP
protected TP()
-
-
Method Details
-
getBundlerClass
-
getMessageFactory
-
setMessageFactory
-
getBindAddr
-
setBindAddr
-
getExternalAddr
-
setExternalAddr
-
getExternalPort
public int getExternalPort() -
setExternalPort
-
isTrace
public boolean isTrace() -
isTrace
-
receiveOnAllInterfaces
public boolean receiveOnAllInterfaces() -
receiveOnAllInterfaces
-
getLogicalAddrCacheMaxSize
public int getLogicalAddrCacheMaxSize() -
setLogicalAddrCacheMaxSize
-
getLogicalAddrCacheExpiration
public long getLogicalAddrCacheExpiration() -
setLogicalAddrCacheExpiration
-
getLogicalAddrCacheReaperInterval
public long getLogicalAddrCacheReaperInterval() -
setLogicalAddrCacheReaperInterval
-
loopbackCopy
public boolean loopbackCopy() -
loopbackCopy
-
loopbackSeparateThread
public boolean loopbackSeparateThread() -
loopbackSeparateThread
-
useVirtualThreads
public boolean useVirtualThreads() -
useVirtualThreads
-
getTimeServiceInterval
public long getTimeServiceInterval() -
setTimeServiceInterval
-
logDiscardMsgs
public boolean logDiscardMsgs() -
logDiscardMsgs
-
logDiscardMsgsVersion
public boolean logDiscardMsgsVersion() -
logDiscardMsgsVersion
-
getWhoHasCacheTimeout
public long getWhoHasCacheTimeout() -
setWhoHasCacheTimeout
-
getSuppressTimeDifferentVersionWarnings
public long getSuppressTimeDifferentVersionWarnings() -
setSuppressTimeDifferentVersionWarnings
-
getSuppressTimeDifferentClusterWarnings
public long getSuppressTimeDifferentClusterWarnings() -
setSuppressTimeDifferentClusterWarnings
-
getMsgFactoryClass
-
setMsgFactoryClass
-
getBundlerType
-
setBundlerType
-
getMessageFactoryClass
-
isLogicalAddressCacheReaperRunning
public boolean isLogicalAddressCacheReaperRunning() -
setLevel
Description copied from class:ProtocolSets the level of a logger. This method is used to dynamically change the logging level of a running system, e.g. via JMX. The appender of a level needs to exist. -
setMessageProcessingPolicy
-
getMessageProcessingPolicy
-
getTimerClass
-
getClusterName
-
getClusterNameAscii
-
getDifferentClusterMessages
public int getDifferentClusterMessages() -
getDifferentVersionMessages
public int getDifferentVersionMessages() -
clearDifferentClusterCache
-
clearDifferentVersionCache
-
loggerType
-
enableBlockingTimerTasks
-
getMessageStats
-
getRTT
-
enableStats
public void enableStats(boolean flag) - Overrides:
enableStatsin classProtocol
-
supportsMulticasting
public abstract boolean supportsMulticasting()Whether hardware multicasting is supported -
isMulticastCapable
public boolean isMulticastCapable() -
getLogicalAddressCache
-
toString
-
setAddress
- Overrides:
setAddressin classProtocol
-
localPhysicalAddress
-
view
-
getLocalPhysicalAddress
-
resetStats
public void resetStats()- Overrides:
resetStatsin classProtocol
-
registerProbeHandler
-
unregisterProbeHandler
-
getDiagnosticsHandler
-
setDiagnosticsHandler
Sets aDiagnosticsHandler. Should be set before the stack is started- Throws:
Exception
-
getLocalTransport
-
setLocalTransport
-
setLocalTransport
- Throws:
Exception
-
getBundler
-
setBundler
Installs a bundler -
getThreadPool
-
setThreadPool
-
getNumRejectedMsgs
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
getNumberOfThreadDumps
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
getNumUcastMsgsSent
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
getNumMcastMsgsSent
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
getNumUcastMsgsReceived
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
getNumMcastMsgsReceived
Deprecated.Don't remove! https://issues.redhat.com/browse/JGRP-2814 -
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
-
getAsyncExecutor
-
setAsyncExecutor
-
getTimer
-
setTimer
Sets a new timer. This should be done before the transport is initialized; be very careful, as replacing a running timer with tasks in it can wreak havoc !- Parameters:
timer-
-
getTimeService
-
setTimeService
-
getSocketFactory
Description copied from class:ProtocolReturns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down- Overrides:
getSocketFactoryin classProtocol- Returns:
- SocketFactory
-
setSocketFactory
Description copied from class:ProtocolSets a SocketFactory. Socket factories are typically provided by the transport (TP)- Overrides:
setSocketFactoryin classProtocol- Parameters:
factory-
-
getThreadNamingPattern
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" -
getBindAddress
-
setBindAddress
-
getBindPort
public int getBindPort() -
setBindPort
-
setBindToAllInterfaces
-
isReceiveOnAllInterfaces
public boolean isReceiveOnAllInterfaces() -
getReceiveInterfaces
-
setPortRange
-
getPortRange
public int getPortRange() -
getNumTimerTasks
public int getNumTimerTasks() -
dumpTimerTasks
-
removeCancelledTimerTasks
public void removeCancelledTimerTasks() -
getTimerThreads
public int getTimerThreads() -
getNumThreads
public static int getNumThreads() -
setLogDiscardMessages
-
getLogDiscardMessages
public boolean getLogDiscardMessages() -
setLogDiscardMessagesVersion
-
getLogDiscardMessagesVersion
public boolean getLogDiscardMessagesVersion() -
printLogicalAddressCache
-
printWhoHasCache
-
evictLogicalAddressCache
public void evictLogicalAddressCache() -
evictLogicalAddressCache
public void evictLogicalAddressCache(boolean force) -
defaultHeaders
-
sendUnicast
public abstract void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception Send a unicast to a member. Note that the destination address is a *physical*, not a logical address- Parameters:
dest- Must be a non-null unicast addressdata- The data to be sent. This is not a copy, so don't modify it- Throws:
Exception
-
getInfo
-
init
Description copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent. -
start
Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads -
stop
public void stop()Description copied from class:ProtocolCalled on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom. -
destroy
public void destroy()Description copied from class:ProtocolThis method is called on aJChannel.close(). Does some cleanup; after the call, the VM will terminate -
bundler
- Throws:
Exception
-
enableDiagnostics
-
disableDiagnostics
public void disableDiagnostics() -
startDiagnostics
- Throws:
Exception
-
stopDiagnostics
protected void stopDiagnostics() -
handleProbe
Description copied from interface:DiagnosticsHandler.ProbeHandlerHandles a probe. For each key that is handled, the key and its result should be in the returned map.- Specified by:
handleProbein interfaceDiagnosticsHandler.ProbeHandler- Returns:
- A map of keys and values. A null return value is permissible.
-
supportedKeys
Description copied from interface:DiagnosticsHandler.ProbeHandlerReturns a list of supported keys- Specified by:
supportedKeysin interfaceDiagnosticsHandler.ProbeHandler
-
handleConnect
- Throws:
Exception
-
handleDisconnect
protected void handleDisconnect() -
down
Description copied from class:ProtocolAn event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down(). -
down
A message needs to be sent to a single member or all members -
createDiagnosticsHandler
-
createBundler
- Throws:
Exception
-
loopback
-
_send
-
setSourceAddress
If the sender is null, set our own address. We cannot just go ahead and set the address anyway, as we might be sending a message on behalf of someone else ! E.g. in case of retransmission, when the original sender has crashed, or in a FLUSH protocol when we have to return all unstable messages with the FLUSH_OK response. -
passMessageUp
public void passMessageUp(Message msg, byte[] cluster_name, boolean perform_cluster_name_matching, boolean multicast, boolean discard_own_mcast) -
passBatchUp
public void passBatchUp(MessageBatch batch, boolean perform_cluster_name_matching, boolean discard_own_mcast) -
sameCluster
-
receive
Subclasses must call this method when a unicast or multicast message has been received. -
receive
- Throws:
Exception
-
handleMessageBatch
-
handleSingleMessage
-
processBatch
-
unicastDestMismatch
-
versionMatch
-
doSend
- Throws:
Exception
-
sendTo
- Throws:
Exception
-
sendToAll
Fetches the physical addrs for all mbrs and sends the msg to each physical address. Asks discovery for missing members' physical addresses if needed- Throws:
Exception
-
fetchPhysicalAddrs
-
fetchResponsesFromDiscoveryProtocol
-
timestamp
protected long timestamp() -
registerLocalAddress
Associates the address with the physical address fetched from the cache- Parameters:
addr-
-
fetchLocalAddresses
protected void fetchLocalAddresses()Grabs the local address (or addresses in the shared transport case) and registers them with the physical address in the transport's cache -
setThreadNames
protected void setThreadNames() -
unsetThreadNames
protected void unsetThreadNames() -
setInAllThreadFactories
-
addPhysicalAddressToCache
-
addPhysicalAddressToCache
protected boolean addPhysicalAddressToCache(Address logical_addr, PhysicalAddress physical_addr, boolean overwrite) -
getPhysicalAddressFromCache
-
getAllPhysicalAddressesFromCache
-
removeLogicalAddressFromCache
-
clearLogicalAddressCache
public void clearLogicalAddressCache()Clears the cache. Do not use, this is only for unit testing ! -
getPhysicalAddress
-