Class RATE_LIMITER

  • All Implemented Interfaces:
    Lifecycle

    public class RATE_LIMITER
    extends Protocol
    Protocol which sends at most max_bytes in time_period milliseconds. Can be used instead of a flow control protocol, e.g. UFC or MFC (same position in the stack)
    Author:
    Bela Ban
    • Field Detail

      • max_bytes

        protected long max_bytes
      • time_period

        protected long time_period
      • time_period_ns

        protected long time_period_ns
      • num_bytes_sent_in_period

        protected long num_bytes_sent_in_period
        Keeps track of the number of bytes sent in the current time period
      • current_period_start

        protected long current_period_start
      • lock

        protected final java.util.concurrent.locks.Lock lock
      • num_blockings

        protected int num_blockings
      • total_block_time

        protected long total_block_time
      • frag_size

        protected int frag_size
      • running

        protected volatile boolean running
    • Constructor Detail

      • RATE_LIMITER

        public RATE_LIMITER()
    • Method Detail

      • getMaxBytes

        public long getMaxBytes()
      • setMaxBytes

        public void setMaxBytes​(long max_bytes)
      • getTimePeriod

        public long getTimePeriod()
      • setTimePeriod

        public void setTimePeriod​(long time_period)
      • getTotalBlockTime

        public long getTotalBlockTime()
      • getAverageBlockTime

        public double getAverageBlockTime()
      • init

        public void init()
                  throws java.lang.Exception
        Description copied from class: Protocol
        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
        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 the channel constructor will throw an exception
      • start

        public void start()
                   throws java.lang.Exception
        Description copied from class: Protocol
        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
        Overrides:
        start in class Protocol
        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
      • 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