public class DefaultSelectorLoopPool extends IdentifiableObject implements ISelectorLoopPool
This implementation is not thread safe.
| Modifier and Type | Field and Description |
|---|---|
protected SelectorLoop[] |
pool
The backing array for this selector-pool
|
protected ISelectorLoopStructureFactory |
selectorFactory
A factory used to create selectors for all selector loops in this pool
|
protected int |
size
The current size of this pool
|
protected ThreadFactory |
threadFactory
A factory used to create threads for all selector loops in this pool
|
| Constructor and Description |
|---|
DefaultSelectorLoopPool(int capacity)
Constructs a unnamed selector loop pool with given capacity.
|
DefaultSelectorLoopPool(String name,
int capacity)
Constructs a named selector loop pool with given capacity.
|
DefaultSelectorLoopPool(String name,
int capacity,
ThreadFactory threadFactory,
ISelectorLoopStructureFactory selectorFactory)
Constructs a named selector loop pool with given capacity and thread
factory.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getCapacity()
Gets the capacity of this pool.
|
SelectorLoop |
getLoop(SelectableChannel channel)
Gets the best selector loop from this pool that should be used to process
given channel.
|
SelectorLoop[] |
getPool()
Gets an array of all selector loops created in this pool.
|
int |
getSize()
Gets the current size of this pool.
|
void |
join()
Waits for all selector loop's threads to die.
|
boolean |
join(long millis)
Waits at most
millis milliseconds for all selector loop's
threads to die. |
void |
quickStop()
Quickly stops all selector loops in this pool.
|
void |
stop()
Gently stops all selector loops in this pool.
|
void |
update(SelectorLoop loop,
int newSize,
int prevSize)
Notifies the pool that given selector loop is now processing different
number of channels.
|
getId, getName, toStringprotected final SelectorLoop[] pool
protected final ThreadFactory threadFactory
protected final ISelectorLoopStructureFactory selectorFactory
protected int size
public DefaultSelectorLoopPool(String name, int capacity, ThreadFactory threadFactory, ISelectorLoopStructureFactory selectorFactory)
name - the name of the pool or null if the name should
be auto generatedcapacity - the capacity of this poolthreadFactory - a factory used to create threads for all selector loops in
this pool, or null to use the default factoryselectorFactory - a selector factory used to create selectors for all selector
loops in this pool, or null to use the default
factory
that will be used by this selector loop to open its selector,
or null if default factory should be usedpublic DefaultSelectorLoopPool(String name, int capacity)
name - the name of the pool or null if the name should
be auto generatedcapacity - the capacity of this poolpublic DefaultSelectorLoopPool(int capacity)
capacity - the capacity of this poolpublic SelectorLoop[] getPool()
public int getCapacity()
public int getSize()
public SelectorLoop getLoop(SelectableChannel channel)
getLoop in interface ISelectorLoopPoolchannel - the channel that needs to be processed by a selector loop form
this poolAbstractSelectorLoop#getSizepublic void stop()
ISelectorLoopPoolstop in interface ISelectorLoopPoolInternalSelectorLoop.stop(org.snf4j.core.StoppingType)public void quickStop()
ISelectorLoopPoolquickStop in interface ISelectorLoopPoolInternalSelectorLoop.quickStop()public void update(SelectorLoop loop, int newSize, int prevSize)
ISelectorLoopPoolgetLoop method.update in interface ISelectorLoopPoolloop - the selector loopnewSize - the new number of channels processed now by the selector loopprevSize - the previous number of channels processed by the selector looppublic boolean join(long millis)
throws InterruptedException
ISelectorLoopPoolmillis milliseconds for all selector loop's
threads to die.join in interface ISelectorLoopPoolmillis - the time to wait in millisecondstrue if the selector loop's thread diedInterruptedException - if any thread has interrupted the current threadpublic void join()
throws InterruptedException
ISelectorLoopPooljoin in interface ISelectorLoopPoolInterruptedException - if any thread has interrupted the current threadCopyright © 2017–2022 SNF4J.ORG. All rights reserved.