Package org.jgroups.protocols.relay
Class RELAY2
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.relay.RELAY2
-
public class RELAY2 extends Protocol
Design: ./doc/design/RELAY2.txt and at https://github.com/belaban/JGroups/blob/master/doc/design/RELAY2.txt. JIRA: https://issues.jboss.org/browse/JGRP-1433- Since:
- 3.2
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RELAY2.Relay2Header
-
Field Summary
Fields Modifier and Type Field Description protected boolean
async_relay_creation
protected boolean
broadcast_route_notifications
protected boolean
can_become_site_master
static short
can_become_site_master_flag
protected boolean
can_forward_local_cluster
protected java.lang.String
config
protected boolean
enable_address_tagging
protected java.util.concurrent.atomic.LongAdder
forward_sm_time
protected java.util.concurrent.atomic.LongAdder
forward_to_local_mbr
Number of messages (received from a remote Sitemaster and) delivered by the local SiteMaster to a local nodeprotected java.util.concurrent.atomic.LongAdder
forward_to_local_mbr_time
protected java.util.concurrent.atomic.LongAdder
forward_to_site_master
Number of messages forwarded to the local SiteMasterprotected boolean
forwarding_protocol_present
Whether or not FORWARD_TO_COORD is on the stackprotected boolean
is_site_master
protected Address
local_addr
protected java.util.concurrent.atomic.LongAdder
local_deliveries
Number of messages delivered locally, e.g.protected java.util.concurrent.atomic.LongAdder
local_delivery_time
Total time (ms) for received messages that are delivered locallyprotected int
max_site_masters
protected java.util.List<Address>
members
protected short[]
prots_above
protected boolean
relay_multicasts
protected java.util.concurrent.atomic.LongAdder
relayed
Number of messages relayed by the local SiteMaster to a remote SiteMasterprotected java.util.concurrent.atomic.LongAdder
relayed_time
Total time spent relaying messages from the local SiteMaster to remote SiteMasters (in ns)protected Relayer
relayer
protected RouteStatusListener
route_status_listener
protected java.lang.String
site
protected RelayConfig.SiteConfig
site_config
static short
site_master_flag
protected java.util.function.Consumer<java.lang.Boolean>
site_master_listener
Listens for notifications about becoming site master (arg: true), or ceasing to be site master (arg: false)protected SiteMasterPicker
site_master_picker
protected java.lang.String
site_master_picker_impl
protected java.util.List<Address>
site_masters
protected double
site_masters_ratio
protected java.util.Map<java.lang.String,RelayConfig.SiteConfig>
sites
A map containing site names (e.g.protected SuppressLog<java.lang.String>
suppress_log_no_route
Log to suppress identical errors for messages to non-existing sites ('no route to site X')protected long
suppress_time_no_route_errors
protected TimeScheduler
timer
protected ResponseCollector<java.lang.String>
topo_collector
protected long
topo_wait_time
protected boolean
warn_when_ftc_missing
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description RELAY2()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_printTopology(Relayer rel)
RELAY2
addSite(java.lang.String site_name, RelayConfig.SiteConfig cfg)
void
addToRelayedTime(long delta)
boolean
asyncRelayCreation()
RELAY2
asyncRelayCreation(boolean flag)
boolean
broadcastRouteNotifications()
RELAY2
broadcastRouteNotifications(boolean b)
boolean
canBecomeSiteMaster()
RELAY2
canBecomeSiteMaster(boolean flag)
boolean
canForwardLocalCluster()
RELAY2
canForwardLocalCluster(boolean c)
RELAY2
clearNoRouteCache()
java.lang.String
config()
RELAY2
config(java.lang.String cfg)
void
configure()
protected Message
copy(Message msg)
Copies the message, but only the headers above the current protocol (RELAY) (or RpcDispatcher related headers)protected void
deliver(Address dest, Address sender, Message msg)
protected void
deliverLocally(SiteAddress dest, SiteAddress sender, Message msg)
protected java.util.List<Address>
determineSiteMasters(View view, int max_num_site_masters)
Iterates over the list of members and adds every member if the member's rank is below max_site_masters.java.lang.Object
down(Event evt)
An event is to be sent down the stack.java.lang.Object
down(Message msg)
A message is sent down the stack.boolean
enableAddressTagging()
RELAY2
enableAddressTagging(boolean flag)
protected java.lang.String
fetchTopoFromSiteMaster(Address sm)
protected void
forwardTo(Address next_dest, SiteAddress final_dest, Address original_sender, Message msg, boolean forward_to_current_coord)
long
getAvgMsgsDeliveringLocally()
long
getAvgMsgsForwardingToLocalMbr()
long
getAvgMsgsForwardingToSM()
long
getAvgMsgsRelaying()
JChannel
getBridge(java.lang.String site_name)
Returns the bridge channel to a given siteView
getBridgeView(java.lang.String cluster_name)
java.lang.String
getConfig()
java.util.List<java.lang.String>
getCurrentSites()
Address
getLocalAddress()
int
getMaxSiteMasters()
int
getNumberOfNoRouteErrors()
long
getNumForwardedToLocalMbr()
long
getNumForwardedToSiteMaster()
long
getNumLocalDeliveries()
long
getNumRelayed()
protected PhysicalAddress
getPhysicalAddress(Address mbr)
Route
getRoute(java.lang.String site_name)
Returns the route to a given siteRouteStatusListener
getRouteStatusListener()
java.lang.String
getSite()
java.lang.String
getSiteMasterPickerImpl()
double
getSiteMastersRatio()
java.util.List<java.lang.String>
getSites()
long
getTimeDeliveringLocally()
long
getTimeForwardingToLocalMbr()
long
getTimeForwardingToSM()
TimeScheduler
getTimer()
long
getTimeRelaying()
long
getTopoWaitTime()
protected boolean
handleAdminMessage(RELAY2.Relay2Header hdr, Address sender)
Handles SITES_UP/SITES_DOWN/TOPO_REQ/TOPO_RSP messagesprotected void
handleMessage(RELAY2.Relay2Header hdr, Message msg)
Called to handle a message received by the transportprotected void
handleRelayMessage(RELAY2.Relay2Header hdr, Message msg)
Called to handle a message received by the relayervoid
handleView(View view)
void
incrementRelayed()
void
init()
Called after instance has been created (null constructor) and before protocol is started.boolean
isSiteMaster()
java.util.List<Address>
members()
protected void
notifySiteMasterListener(boolean flag)
void
parse(XmlNode node)
Called by the XML parser when subelements are found in the configuration of a protocol.protected void
parseSiteConfiguration(java.util.Map<java.lang.String,RelayConfig.SiteConfig> map)
Parses the configuration by reading the config file.protected Address
pickSiteMaster(Address sender)
Returns a site master from site_mastersjava.lang.String
printLocalTopology()
java.lang.String
printRoutes()
java.lang.String
printSites()
java.lang.String
printTopology(boolean all_sites)
boolean
relayMulticasts()
RELAY2
relayMulticasts(boolean flag)
void
resetStats()
protected void
route(SiteAddress dest, SiteAddress sender, Message msg)
Routes the message to the target destination, used by a site master (coordinator)protected void
sendSiteUnreachableTo(Address src, java.lang.String target_site)
Sends a SITE-UNREACHABLE message to the sender of the message.protected void
sendToBridges(Address sender, Message msg, java.lang.String... excluded_sites)
Sends the message via all bridges excluding the excluded_sites bridgesprotected boolean
sendTopoReq(JChannel bridge, Address dest)
RELAY2
setConfig(java.lang.String c)
RELAY2
setMaxSiteMasters(int m)
void
setRouteStatusListener(RouteStatusListener l)
RELAY2
setSite(java.lang.String s)
RELAY2
setSiteMasterListener(java.util.function.Consumer<java.lang.Boolean> l)
RELAY2
setSiteMasterPickerImpl(java.lang.String s)
RELAY2
setSiteMastersRatio(double r)
RELAY2
setTopoWaitTime(long t)
java.lang.String
site()
RELAY2
site(java.lang.String site_name)
RELAY2
siteMasterPicker(SiteMasterPicker s)
java.util.List<Address>
siteMasters()
java.util.List<java.lang.String>
siteNames()
protected void
sitesChange(boolean down, java.lang.String... sites)
protected void
startRelayer(Relayer rel, java.lang.String bridge_name)
void
stop()
This method is called on aJChannel.disconnect()
.java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.void
up(MessageBatch batch)
Sends up a multiple messages in aMessageBatch
.-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled
-
-
-
-
Field Detail
-
site_master_flag
public static final short site_master_flag
- See Also:
- Constant Field Values
-
can_become_site_master_flag
public static final short can_become_site_master_flag
- See Also:
- Constant Field Values
-
site
protected java.lang.String site
-
config
protected java.lang.String config
-
can_become_site_master
protected boolean can_become_site_master
-
max_site_masters
protected int max_site_masters
-
site_masters_ratio
protected double site_masters_ratio
-
enable_address_tagging
protected boolean enable_address_tagging
-
relay_multicasts
protected boolean relay_multicasts
-
async_relay_creation
protected boolean async_relay_creation
-
warn_when_ftc_missing
protected boolean warn_when_ftc_missing
-
site_master_picker_impl
protected java.lang.String site_master_picker_impl
-
suppress_time_no_route_errors
protected long suppress_time_no_route_errors
-
sites
protected final java.util.Map<java.lang.String,RelayConfig.SiteConfig> sites
A map containing site names (e.g. "LON") as keys and SiteConfigs as values
-
site_config
protected RelayConfig.SiteConfig site_config
-
is_site_master
protected volatile boolean is_site_master
-
broadcast_route_notifications
protected volatile boolean broadcast_route_notifications
-
site_masters
protected volatile java.util.List<Address> site_masters
-
site_master_picker
protected SiteMasterPicker site_master_picker
-
site_master_listener
protected java.util.function.Consumer<java.lang.Boolean> site_master_listener
Listens for notifications about becoming site master (arg: true), or ceasing to be site master (arg: false)
-
relayer
protected volatile Relayer relayer
-
timer
protected TimeScheduler timer
-
local_addr
protected volatile Address local_addr
-
members
protected volatile java.util.List<Address> members
-
forwarding_protocol_present
protected boolean forwarding_protocol_present
Whether or not FORWARD_TO_COORD is on the stack
-
can_forward_local_cluster
protected boolean can_forward_local_cluster
-
topo_wait_time
protected long topo_wait_time
-
prots_above
protected short[] prots_above
-
route_status_listener
protected volatile RouteStatusListener route_status_listener
-
forward_to_site_master
protected final java.util.concurrent.atomic.LongAdder forward_to_site_master
Number of messages forwarded to the local SiteMaster
-
forward_sm_time
protected final java.util.concurrent.atomic.LongAdder forward_sm_time
-
relayed
protected final java.util.concurrent.atomic.LongAdder relayed
Number of messages relayed by the local SiteMaster to a remote SiteMaster
-
relayed_time
protected final java.util.concurrent.atomic.LongAdder relayed_time
Total time spent relaying messages from the local SiteMaster to remote SiteMasters (in ns)
-
forward_to_local_mbr
protected final java.util.concurrent.atomic.LongAdder forward_to_local_mbr
Number of messages (received from a remote Sitemaster and) delivered by the local SiteMaster to a local node
-
forward_to_local_mbr_time
protected final java.util.concurrent.atomic.LongAdder forward_to_local_mbr_time
-
local_deliveries
protected final java.util.concurrent.atomic.LongAdder local_deliveries
Number of messages delivered locally, e.g. received and delivered to self
-
local_delivery_time
protected final java.util.concurrent.atomic.LongAdder local_delivery_time
Total time (ms) for received messages that are delivered locally
-
topo_collector
protected final ResponseCollector<java.lang.String> topo_collector
-
suppress_log_no_route
protected SuppressLog<java.lang.String> suppress_log_no_route
Log to suppress identical errors for messages to non-existing sites ('no route to site X')
-
-
Method Detail
-
site
public RELAY2 site(java.lang.String site_name)
-
config
public RELAY2 config(java.lang.String cfg)
-
canBecomeSiteMaster
public RELAY2 canBecomeSiteMaster(boolean flag)
-
enableAddressTagging
public RELAY2 enableAddressTagging(boolean flag)
-
relayMulticasts
public RELAY2 relayMulticasts(boolean flag)
-
asyncRelayCreation
public RELAY2 asyncRelayCreation(boolean flag)
-
siteMasterPicker
public RELAY2 siteMasterPicker(SiteMasterPicker s)
-
site
public java.lang.String site()
-
siteMasters
public java.util.List<Address> siteMasters()
-
members
public java.util.List<Address> members()
-
siteNames
public java.util.List<java.lang.String> siteNames()
-
config
public java.lang.String config()
-
canBecomeSiteMaster
public boolean canBecomeSiteMaster()
-
enableAddressTagging
public boolean enableAddressTagging()
-
relayMulticasts
public boolean relayMulticasts()
-
asyncRelayCreation
public boolean asyncRelayCreation()
-
getLocalAddress
public Address getLocalAddress()
-
getTimer
public TimeScheduler getTimer()
-
incrementRelayed
public void incrementRelayed()
-
addToRelayedTime
public void addToRelayedTime(long delta)
-
getSite
public java.lang.String getSite()
-
setSite
public RELAY2 setSite(java.lang.String s)
-
getConfig
public java.lang.String getConfig()
-
setConfig
public RELAY2 setConfig(java.lang.String c)
-
getMaxSiteMasters
public int getMaxSiteMasters()
-
setMaxSiteMasters
public RELAY2 setMaxSiteMasters(int m)
-
getSiteMastersRatio
public double getSiteMastersRatio()
-
setSiteMastersRatio
public RELAY2 setSiteMastersRatio(double r)
-
getSiteMasterPickerImpl
public java.lang.String getSiteMasterPickerImpl()
-
setSiteMasterPickerImpl
public RELAY2 setSiteMasterPickerImpl(java.lang.String s)
-
broadcastRouteNotifications
public boolean broadcastRouteNotifications()
-
broadcastRouteNotifications
public RELAY2 broadcastRouteNotifications(boolean b)
-
canForwardLocalCluster
public boolean canForwardLocalCluster()
-
canForwardLocalCluster
public RELAY2 canForwardLocalCluster(boolean c)
-
getTopoWaitTime
public long getTopoWaitTime()
-
setTopoWaitTime
public RELAY2 setTopoWaitTime(long t)
-
getRouteStatusListener
public RouteStatusListener getRouteStatusListener()
-
setRouteStatusListener
public void setRouteStatusListener(RouteStatusListener l)
-
setSiteMasterListener
public RELAY2 setSiteMasterListener(java.util.function.Consumer<java.lang.Boolean> l)
-
getNumForwardedToSiteMaster
public long getNumForwardedToSiteMaster()
-
getTimeForwardingToSM
public long getTimeForwardingToSM()
-
getAvgMsgsForwardingToSM
public long getAvgMsgsForwardingToSM()
-
getNumRelayed
public long getNumRelayed()
-
getTimeRelaying
public long getTimeRelaying()
-
getAvgMsgsRelaying
public long getAvgMsgsRelaying()
-
getNumForwardedToLocalMbr
public long getNumForwardedToLocalMbr()
-
getTimeForwardingToLocalMbr
public long getTimeForwardingToLocalMbr()
-
getAvgMsgsForwardingToLocalMbr
public long getAvgMsgsForwardingToLocalMbr()
-
getNumLocalDeliveries
public long getNumLocalDeliveries()
-
getTimeDeliveringLocally
public long getTimeDeliveringLocally()
-
getAvgMsgsDeliveringLocally
public long getAvgMsgsDeliveringLocally()
-
isSiteMaster
public boolean isSiteMaster()
-
getNumberOfNoRouteErrors
public int getNumberOfNoRouteErrors()
-
clearNoRouteCache
public RELAY2 clearNoRouteCache()
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
getBridgeView
public View getBridgeView(java.lang.String cluster_name)
-
addSite
public RELAY2 addSite(java.lang.String site_name, RelayConfig.SiteConfig cfg)
-
getSites
public java.util.List<java.lang.String> getSites()
-
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.
-
configure
public void configure() throws java.lang.Exception
- Throws:
java.lang.Exception
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aJChannel.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
-
parseSiteConfiguration
protected void parseSiteConfiguration(java.util.Map<java.lang.String,RelayConfig.SiteConfig> map) throws java.lang.Exception
Parses the configuration by reading the config file.- Throws:
java.lang.Exception
-
parse
public void parse(XmlNode node) throws java.lang.Exception
Description copied from class:Protocol
Called by the XML parser when subelements are found in the configuration of a protocol. This allows a protocol to define protocol-specific information and to parse it
-
printRoutes
public java.lang.String printRoutes()
-
printSites
public java.lang.String printSites()
-
printTopology
public java.lang.String printTopology(boolean all_sites)
-
printLocalTopology
public java.lang.String printLocalTopology()
-
getBridge
public JChannel getBridge(java.lang.String site_name)
Returns the bridge channel to a given site- Parameters:
site_name
- The site name, e.g. "SFO"- Returns:
- The JChannel to the given site, or null if no route was found or we're not the coordinator
-
getRoute
public Route getRoute(java.lang.String site_name)
Returns the route to a given site- Parameters:
site_name
- The site name, e.g. "SFO"- Returns:
- The route to the given site, or null if no route was found or we're not the coordinator
-
getCurrentSites
public java.util.List<java.lang.String> getCurrentSites()
- Returns:
- A
List
of sites name that are currently up ornull
if this node is not a Site Master (i.e.isSiteMaster()
returns false).
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
An 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
public java.lang.Object down(Message msg)
Description copied from class:Protocol
A message is sent down the stack. Protocols may examine the message and do something (e.g. add a header) with it before passing it down.
-
up
public java.lang.Object up(Event evt)
Description copied from class:Protocol
An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()
or c) the event (or another event) is sent up the stack usingup_prot.up()
.
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
up
public void up(MessageBatch batch)
Description copied from class:Protocol
Sends up a multiple messages in aMessageBatch
. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages. The default processing below sends messages up the stack individually, based on a matching criteria (callingProtocol.accept(org.jgroups.Message)
), and - if true - callsProtocol.up(org.jgroups.Event)
for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped. Subclasses should check if there are any messages destined for them (e.g. usingMessageBatch.getMatchingMessages(short,boolean)
), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.
-
getPhysicalAddress
protected PhysicalAddress getPhysicalAddress(Address mbr)
-
handleView
public void handleView(View view)
-
handleRelayMessage
protected void handleRelayMessage(RELAY2.Relay2Header hdr, Message msg)
Called to handle a message received by the relayer
-
handleAdminMessage
protected boolean handleAdminMessage(RELAY2.Relay2Header hdr, Address sender)
Handles SITES_UP/SITES_DOWN/TOPO_REQ/TOPO_RSP messages
-
handleMessage
protected void handleMessage(RELAY2.Relay2Header hdr, Message msg)
Called to handle a message received by the transport
-
route
protected void route(SiteAddress dest, SiteAddress sender, Message msg)
Routes the message to the target destination, used by a site master (coordinator)- Parameters:
dest
- the destination site addresssender
- the address of the sendermsg
- The message
-
sendToBridges
protected void sendToBridges(Address sender, Message msg, java.lang.String... excluded_sites)
Sends the message via all bridges excluding the excluded_sites bridges
-
sendSiteUnreachableTo
protected void sendSiteUnreachableTo(Address src, java.lang.String target_site)
Sends a SITE-UNREACHABLE message to the sender of the message. Because the sender is always local (we're the relayer), no routing needs to be done- Parameters:
src
- The node who is trying to send a message to thetarget_site
target_site
- The remote site's name.
-
forwardTo
protected void forwardTo(Address next_dest, SiteAddress final_dest, Address original_sender, Message msg, boolean forward_to_current_coord)
-
deliverLocally
protected void deliverLocally(SiteAddress dest, SiteAddress sender, Message msg)
-
sitesChange
protected void sitesChange(boolean down, java.lang.String... sites)
-
copy
protected Message copy(Message msg)
Copies the message, but only the headers above the current protocol (RELAY) (or RpcDispatcher related headers)
-
startRelayer
protected void startRelayer(Relayer rel, java.lang.String bridge_name)
-
notifySiteMasterListener
protected void notifySiteMasterListener(boolean flag)
-
determineSiteMasters
protected java.util.List<Address> determineSiteMasters(View view, int max_num_site_masters)
Iterates over the list of members and adds every member if the member's rank is below max_site_masters. Skips members which cannot become site masters (can_become_site_master == false). If no site master can be found, the first member of the view will be returned (even if it has can_become_site_master == false)
-
pickSiteMaster
protected Address pickSiteMaster(Address sender)
Returns a site master from site_masters
-
_printTopology
protected java.lang.String _printTopology(Relayer rel)
-
fetchTopoFromSiteMaster
protected java.lang.String fetchTopoFromSiteMaster(Address sm)
-
-