Class PartitionDistributor

  • All Implemented Interfaces:
    OperationDistributor

    class PartitionDistributor
    extends java.lang.Object
    implements OperationDistributor
    The PartitionDistributor object is a distributor that partitions the selection process in to several threads. Each of the threads has a single selector, and operations are distributed amongst the threads using the hash code of the socket. Partitions ensure that several selector threads can share a higher load and respond to a more I/O events.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private OperationDistributor[] list
      This contains the distributors that represent a partition.
    • Constructor Summary

      Constructors 
      Constructor Description
      PartitionDistributor​(java.util.concurrent.Executor executor, int count)
      Constructor for the PartitionDistributor object.
      PartitionDistributor​(java.util.concurrent.Executor executor, int count, long expiry)
      Constructor for the PartitionDistributor object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      This is used to close the distributor such that it cancels all of the registered channels and closes down the selector.
      void process​(Operation task, int require)
      This is used to process the Operation object.
      private void process​(Operation task, int require, int length)
      This is used to process the Operation object.
      private void start​(java.util.concurrent.Executor executor, long expiry)
      This is used to create the partitions that represent a thread used for selection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • list

        private final OperationDistributor[] list
        This contains the distributors that represent a partition.
    • Constructor Detail

      • PartitionDistributor

        public PartitionDistributor​(java.util.concurrent.Executor executor,
                                    int count)
                             throws java.io.IOException
        Constructor for the PartitionDistributor object. This will create a distributor that partitions the operations amongst a pool of selectors using the channels hash code.
        Parameters:
        executor - this is the executor used to run operations
        count - this is the number of partitions to be used
        Throws:
        java.io.IOException
      • PartitionDistributor

        public PartitionDistributor​(java.util.concurrent.Executor executor,
                                    int count,
                                    long expiry)
                             throws java.io.IOException
        Constructor for the PartitionDistributor object. This will create a distributor that partitions the operations amongst a pool of selectors using the channels hash code.
        Parameters:
        executor - this is the executor used to run operations
        count - this is the number of partitions to be used
        expiry - this is the expiry duration that is to be used
        Throws:
        java.io.IOException
    • Method Detail

      • start

        private void start​(java.util.concurrent.Executor executor,
                           long expiry)
                    throws java.io.IOException
        This is used to create the partitions that represent a thread used for selection. Operations will index to a particular one using the hash code of the operations channel. If there is only one partition all operations will index to the partition.
        Parameters:
        executor - the executor used to run the operations
        expiry - this is the expiry duration that is to be used
        Throws:
        java.io.IOException
      • process

        public void process​(Operation task,
                            int require)
                     throws java.io.IOException
        This is used to process the Operation object. This will wake up the selector if it is currently blocked selecting and register the operations associated channel. Once the selector is awake it will acquire the operation from the queue and register the associated SelectableChannel for selection. The operation will then be executed when the channel is ready for the interested I/O events.
        Specified by:
        process in interface OperationDistributor
        Parameters:
        task - this is the task that is scheduled for distribution
        require - this is the bit-mask value for interested events
        Throws:
        java.io.IOException
      • process

        private void process​(Operation task,
                             int require,
                             int length)
                      throws java.io.IOException
        This is used to process the Operation object. This will wake up the selector if it is currently blocked selecting and register the operations associated channel. Once the selector is awake it will acquire the operation from the queue and register the associated SelectableChannel for selection. The operation will then be executed when the channel is ready for the interested I/O events.
        Parameters:
        task - this is the task that is scheduled for distribution
        require - this is the bit-mask value for interested events
        length - this is the number of distributors to hash with
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        This is used to close the distributor such that it cancels all of the registered channels and closes down the selector. This is used when the distributor is no longer required, after the close further attempts to process operations will fail.
        Specified by:
        close in interface OperationDistributor
        Throws:
        java.io.IOException