Class 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
    • Field Detail

      • 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
      • 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_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
      • 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
      • 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
      • 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')
    • Constructor Detail

      • RELAY2

        public RELAY2()
    • 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)
      • 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()
      • 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)
      • 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()
      • getBridgeView

        public View getBridgeView​(java.lang.String cluster_name)
      • 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.
        Overrides:
        init in class Protocol
        Throws:
        java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
      • 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 a JChannel.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
        Overrides:
        stop in class Protocol
      • 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
        Overrides:
        parse in class Protocol
        Throws:
        java.lang.Exception
      • 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 or null 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 using down_prot.down().
        Overrides:
        down in class Protocol
      • 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.
        Overrides:
        down in class Protocol
      • 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 using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
        Overrides:
        up in class Protocol
      • 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.
        Overrides:
        up in class Protocol
      • up

        public void up​(MessageBatch batch)
        Description copied from class: Protocol
        Sends up a multiple messages in a MessageBatch. 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 (calling Protocol.accept(org.jgroups.Message)), and - if true - calls Protocol.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. using MessageBatch.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.

        Overrides:
        up in class Protocol
        Parameters:
        batch - The message batch
      • 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 address
        sender - the address of the sender
        msg - 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 the target_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)
      • 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)
      • sendTopoReq

        protected boolean sendTopoReq​(JChannel bridge,
                                      Address dest)
      • fetchTopoFromSiteMaster

        protected java.lang.String fetchTopoFromSiteMaster​(Address sm)