Class Protocol

    • Field Detail

      • down_prot

        protected Protocol down_prot
      • stats

        protected boolean stats
      • ergonomics

        protected boolean ergonomics
      • after_creation_hook

        protected java.lang.String after_creation_hook
      • id

        protected short id
      • local_addr

        protected Address local_addr
      • log

        protected final Log log
      • policies

        protected java.util.List<Policy> policies
    • Constructor Detail

      • Protocol

        public Protocol()
    • Method Detail

      • setLevel

        public <T extends Protocol> T setLevel​(java.lang.String level)
        Sets 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.
        Parameters:
        level - The new level. Valid values are "fatal", "error", "warn", "info", "debug", "trace" (capitalization not relevant)
      • getLevel

        public java.lang.String getLevel()
      • level

        public <T extends Protocol> T level​(java.lang.String level)
      • getAddress

        public Address getAddress()
      • isErgonomics

        public boolean isErgonomics()
      • setErgonomics

        public <T extends Protocol> T setErgonomics​(boolean ergonomics)
      • statsEnabled

        public boolean statsEnabled()
      • enableStats

        public void enableStats​(boolean flag)
      • getName

        public java.lang.String getName()
      • getId

        public short getId()
      • setId

        public <T extends Protocol> T setId​(short id)
      • getUpProtocol

        public <T extends Protocol> T getUpProtocol()
      • getDownProtocol

        public <T extends Protocol> T getDownProtocol()
      • setUpProtocol

        public <T extends Protocol> T setUpProtocol​(Protocol prot)
      • setDownProtocol

        public <T extends Protocol> T setDownProtocol​(Protocol prot)
      • afterCreationHook

        public java.lang.String afterCreationHook()
      • getLog

        public Log getLog()
      • getPolicies

        public java.util.List<? extends Policy> getPolicies()
      • policies

        public java.lang.String policies()
      • setPolicies

        public <T extends Protocol> T setPolicies​(java.util.List<Policy> l)
      • removePolicy

        public <T extends Protocol> T removePolicy​(Policy p)
      • getValue

        public java.lang.Object getValue​(java.lang.String name)
      • setValue

        public <T extends Protocol> T setValue​(java.lang.String name,
                                               java.lang.Object value)
      • getComponents

        public java.util.List<java.lang.Object> getComponents()
        After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional component objects which need to be configured. This callback allows a protocol developer to configure those other objects. This call is guaranteed to be invoked after the protocol itself has been configured.
        See AUTH for an example.
      • parse

        public void parse​(XmlNode node)
                   throws java.lang.Exception
        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
        Throws:
        java.lang.Exception
      • getIdsAbove

        public short[] getIdsAbove()
        Returns the protocol IDs of all protocols above this one (excluding the current protocol)
      • getTransport

        public TP getTransport()
      • getThreadFactory

        public ThreadFactory getThreadFactory()
        Supposed 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
        Returns:
      • getSocketFactory

        public SocketFactory getSocketFactory()
        Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down
        Returns:
        SocketFactory
      • setSocketFactory

        public void setSocketFactory​(SocketFactory factory)
        Sets a SocketFactory. Socket factories are typically provided by the transport (TP)
        Parameters:
        factory -
      • resetStatistics

        public void resetStatistics()
      • resetStats

        public void resetStats()
      • init

        public void init()
                  throws java.lang.Exception
        Called 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.
        Specified by:
        init in interface Lifecycle
        Throws:
        java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
      • start

        public void start()
                   throws java.lang.Exception
        This method is called on a JChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.
        Specified by:
        start in interface Lifecycle
        Throws:
        java.lang.Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
      • stop

        public void stop()
        Called on a JChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
        Specified by:
        stop in interface Lifecycle
      • destroy

        public void destroy()
        This method is called on a JChannel.close(). Does some cleanup; after the call, the VM will terminate
        Specified by:
        destroy in interface Lifecycle
      • requiredUpServices

        public java.util.List<java.lang.Integer> requiredUpServices()
        List of events that are required to be answered by some layer above
      • requiredDownServices

        public java.util.List<java.lang.Integer> requiredDownServices()
        List of events that are required to be answered by some layer below
      • providedUpServices

        public java.util.List<java.lang.Integer> providedUpServices()
        List of events that are provided to layers above (they will be handled when sent down from above)
      • providedDownServices

        public java.util.List<java.lang.Integer> providedDownServices()
        List of events that are provided to layers below (they will be handled when sent from down below)
      • getDownServices

        public final java.util.List<java.lang.Integer> getDownServices()
        Returns all services provided by protocols below the current protocol
      • getUpServices

        public final java.util.List<java.lang.Integer> getUpServices()
        Returns all services provided by the protocols above the current protocol
      • down

        public java.lang.Object down​(Event evt)
        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().
      • down

        public java.lang.Object down​(Message msg)
        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.
        Since:
        4.0
      • down

        public java.util.concurrent.CompletableFuture<java.lang.Object> down​(Message msg,
                                                                             boolean async)
        Passes a message down asynchronously. The sending is executed in the transport's thread pool. If the pool is full and the message is marked as Message.TransientFlag.DONT_BLOCK, then it will be dropped, otherwise it will be sent on the caller's thread.
        Parameters:
        msg - The message to be sent
        async - Whether to send the message asynchronously
        Returns:
        A CompletableFuture of the result (or exception)
      • up

        public java.lang.Object up​(Event evt)
        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().
      • up

        public java.lang.Object up​(Message msg)
        A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
        Since:
        4.0
      • up

        public void up​(MessageBatch batch)
        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 accept(Message)), and - if true - calls 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.iterator(Predicate)), 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.

        Parameters:
        batch - The message batch
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • accept

        protected boolean accept​(Message msg)
        Called by the default implementation of up(org.jgroups.util.MessageBatch) for each message to determine if the message should be removed from the message batch (and handled by the current protocol) or not.
        Parameters:
        msg - The message. Guaranteed to be non-null
        Returns:
        True if the message should be handled by this protocol (will be removed from the batch), false if the message should remain in the batch and be passed up.

        The default implementation tries to find a header matching the current protocol's ID and returns true if there is a match, or false otherwise