Class AbstractTrafficShapingHandler

    • Field Detail

      • DEFAULT_CHECK_INTERVAL

        public static final long DEFAULT_CHECK_INTERVAL
        Default delay between two checks: 1s
        See Also:
        Constant Field Values
      • DEFAULT_MAX_TIME

        public static final long DEFAULT_MAX_TIME
        Default max delay in case of traffic shaping (during which no communication will occur). Shall be less than TIMEOUT. Here half of "standard" 30s
        See Also:
        Constant Field Values
      • trafficCounter

        protected TrafficCounter trafficCounter
        Traffic Counter
      • timer

        protected Timer timer
        Timer associated to any TrafficCounter
      • checkInterval

        protected volatile long checkInterval
        Delay between two performance snapshots
      • maxTime

        protected volatile long maxTime
        Max delay in wait
    • Constructor Detail

      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(Timer timer,
                                                long writeLimit,
                                                long readLimit,
                                                long checkInterval)
        Constructor using default ObjectSizeEstimator and default max time as delay allowed value of 15000L ms.
        Parameters:
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(ObjectSizeEstimator objectSizeEstimator,
                                                Timer timer,
                                                long writeLimit,
                                                long readLimit,
                                                long checkInterval)
        Constructor using the specified ObjectSizeEstimator and default max time as delay allowed value of 15000L ms.
        Parameters:
        objectSizeEstimator - the ObjectSizeEstimator that will be used to compute the size of the message.
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(Timer timer,
                                                long writeLimit,
                                                long readLimit)
        Constructor using default ObjectSizeEstimator and using default Check Interval value of 1000L ms and default max time as delay allowed value of 15000L ms.
        Parameters:
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(ObjectSizeEstimator objectSizeEstimator,
                                                Timer timer,
                                                long writeLimit,
                                                long readLimit)
        Constructor using the specified ObjectSizeEstimator and using default Check Interval value of 1000L ms and default max time as delay allowed value of 15000L ms.
        Parameters:
        objectSizeEstimator - the ObjectSizeEstimator that will be used to compute the size of the message.
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(Timer timer)
        Constructor using default ObjectSizeEstimator and using NO LIMIT and default Check Interval value of 1000L ms and default max time as delay allowed value of 15000L ms.
        Parameters:
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(ObjectSizeEstimator objectSizeEstimator,
                                                Timer timer)
        Constructor using the specified ObjectSizeEstimator and using NO LIMIT and default Check Interval value of 1000L ms and default max time as delay allowed value of 15000L ms.
        Parameters:
        objectSizeEstimator - the ObjectSizeEstimator that will be used to compute the size of the message.
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(Timer timer,
                                                long checkInterval)
        Constructor using default ObjectSizeEstimator and using NO LIMIT and default max time as delay allowed value of 15000L ms.
        Parameters:
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(ObjectSizeEstimator objectSizeEstimator,
                                                Timer timer,
                                                long checkInterval)
        Constructor using the specified ObjectSizeEstimator and using NO LIMIT and default max time as delay allowed value of 15000L ms.
        Parameters:
        objectSizeEstimator - the ObjectSizeEstimator that will be used to compute the size of the message.
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(Timer timer,
                                                long writeLimit,
                                                long readLimit,
                                                long checkInterval,
                                                long maxTime)
        Constructor using default ObjectSizeEstimator.
        Parameters:
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
        maxTime - The max time to wait in case of excess of traffic (to prevent Time Out event). Must be positive.
      • AbstractTrafficShapingHandler

        protected AbstractTrafficShapingHandler​(ObjectSizeEstimator objectSizeEstimator,
                                                Timer timer,
                                                long writeLimit,
                                                long readLimit,
                                                long checkInterval,
                                                long maxTime)
        Constructor using the specified ObjectSizeEstimator.
        Parameters:
        objectSizeEstimator - the ObjectSizeEstimator that will be used to compute the size of the message.
        timer - created once for instance like HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024).
        writeLimit - 0 or a limit in bytes/s
        readLimit - 0 or a limit in bytes/s
        checkInterval - The delay between two computations of performances for channels or 0 if no stats are to be computed.
        maxTime - The max time to wait in case of excess of traffic (to prevent Time Out event). Must be positive.
    • Method Detail

      • configure

        public void configure​(long newWriteLimit,
                              long newReadLimit,
                              long newCheckInterval)
        Change the underlying limitations and check interval.

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        newWriteLimit - The new write limit (in bytes)
        newReadLimit - The new read limit (in bytes)
        newCheckInterval - The new check interval (in milliseconds)
      • configure

        public void configure​(long newWriteLimit,
                              long newReadLimit)
        Change the underlying limitations.

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        newWriteLimit - The new write limit (in bytes)
        newReadLimit - The new read limit (in bytes)
      • configure

        public void configure​(long newCheckInterval)
        Change the check interval.
      • getWriteLimit

        public long getWriteLimit()
        Returns:
        the writeLimit
      • setWriteLimit

        public void setWriteLimit​(long writeLimit)

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        writeLimit - the writeLimit to set
      • getReadLimit

        public long getReadLimit()
        Returns:
        the readLimit
      • setReadLimit

        public void setReadLimit​(long readLimit)

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        readLimit - the readLimit to set
      • getCheckInterval

        public long getCheckInterval()
        Returns:
        the checkInterval
      • setCheckInterval

        public void setCheckInterval​(long newCheckInterval)
        Parameters:
        newCheckInterval - the checkInterval to set
      • getMaxTimeWait

        public long getMaxTimeWait()
        Returns:
        the max delay on wait
      • setMaxTimeWait

        public void setMaxTimeWait​(long maxTime)

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        maxTime - Max delay in wait, shall be less than TIME OUT in related protocol. Must be positive.
      • getMaxWriteDelay

        public long getMaxWriteDelay()
        Returns:
        the maxWriteDelay
      • setMaxWriteDelay

        public void setMaxWriteDelay​(long maxWriteDelay)

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        maxWriteDelay - the maximum Write Delay in ms in the buffer allowed before write suspended is set. Must be positive.
      • getMaxWriteSize

        public long getMaxWriteSize()
        Returns:
        the maxWriteSize default being 4194304L bytes
      • setMaxWriteSize

        public void setMaxWriteSize​(long maxWriteSize)

        Note the change will be taken as best effort, meaning that all already scheduled traffics will not be changed, but only applied to new traffics.

        So the expected usage of this method is to be used not too often, accordingly to the traffic shaping configuration.
        Parameters:
        maxWriteSize - the maximum Write Size allowed in the buffer per channel before write suspended is set, default being 4194304L bytes
      • doAccounting

        protected void doAccounting​(TrafficCounter counter)
        Called each time the accounting is computed from the TrafficCounters. This method could be used for instance to implement almost real time accounting.
        Parameters:
        counter - the TrafficCounter that computes its performance
      • getTrafficCounter

        public TrafficCounter getTrafficCounter()
        Returns:
        the current TrafficCounter (if channel is still connected).
      • calculateSize

        protected long calculateSize​(Object obj)