Class PartitionDistributor
- java.lang.Object
-
- org.simpleframework.transport.reactor.PartitionDistributor
-
- All Implemented Interfaces:
OperationDistributor
class PartitionDistributor extends java.lang.Object implements OperationDistributor
ThePartitionDistributor
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 thePartitionDistributor
object.PartitionDistributor(java.util.concurrent.Executor executor, int count, long expiry)
Constructor for thePartitionDistributor
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 theOperation
object.private void
process(Operation task, int require, int length)
This is used to process theOperation
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.
-
-
-
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 thePartitionDistributor
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 operationscount
- 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 thePartitionDistributor
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 operationscount
- this is the number of partitions to be usedexpiry
- 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 operationsexpiry
- 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 theOperation
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 associatedSelectableChannel
for selection. The operation will then be executed when the channel is ready for the interested I/O events.- Specified by:
process
in interfaceOperationDistributor
- Parameters:
task
- this is the task that is scheduled for distributionrequire
- 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 theOperation
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 associatedSelectableChannel
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 distributionrequire
- this is the bit-mask value for interested eventslength
- 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 interfaceOperationDistributor
- Throws:
java.io.IOException
-
-