Class PartitionDistributor

java.lang.Object
org.simpleframework.transport.reactor.PartitionDistributor
All Implemented Interfaces:
OperationDistributor

class PartitionDistributor extends 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 final OperationDistributor[]
    This contains the distributors that represent a partition.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    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(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 Details

    • list

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

    • PartitionDistributor

      public PartitionDistributor(Executor executor, int count) throws 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:
      IOException
    • PartitionDistributor

      public PartitionDistributor(Executor executor, int count, long expiry) throws 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:
      IOException
  • Method Details

    • start

      private void start(Executor executor, long expiry) throws 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:
      IOException
    • process

      public void process(Operation task, int require) throws 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:
      IOException
    • process

      private void process(Operation task, int require, int length) throws 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:
      IOException
    • close

      public void close() throws 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:
      IOException