Package org.glassfish.grizzly.strategies
Class SimpleDynamicNIOStrategy
- java.lang.Object
-
- org.glassfish.grizzly.strategies.SimpleDynamicNIOStrategy
-
- All Implemented Interfaces:
IOStrategy
,WorkerThreadPoolConfigProducer
public final class SimpleDynamicNIOStrategy extends Object implements IOStrategy
Simple dynamic strategy, which switches I/O processing strategies, basing on statistics. This implementation takes in consideration number ofSelectionKey
s, which were selected last time bySelector
. SimpleDynamicIOStrategy is able to use 2 strategies underneath:SameThreadIOStrategy
,WorkerThreadIOStrategy
. And is able to switch between them basing on corresponding threshold (threshold represents the number of selectedSelectionKey
s). So the strategy is getting applied following way:SameThreadIOStrategy
--(worker-thread threshold)-->WorkerThreadIOStrategy
.- Author:
- Alexey Stashok
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadPoolConfig
createDefaultWorkerPoolConfig(Transport transport)
boolean
executeIoEvent(Connection connection, IOEvent ioEvent)
TheSelectorRunner
will invoke this method to allow the strategy implementation to decide how theIOEvent
will be handled.boolean
executeIoEvent(Connection connection, IOEvent ioEvent, boolean isIoEventEnabled)
TheSelectorRunner
will invoke this method to allow the strategy implementation to decide how theIOEvent
will be handled.static SimpleDynamicNIOStrategy
getInstance()
Executor
getThreadPoolFor(Connection connection, IOEvent ioEvent)
Returns anExecutor
to be used to run given ioEvent processing for the given connection.
-
-
-
Method Detail
-
getInstance
public static SimpleDynamicNIOStrategy getInstance()
-
executeIoEvent
public boolean executeIoEvent(Connection connection, IOEvent ioEvent) throws IOException
Description copied from interface:IOStrategy
TheSelectorRunner
will invoke this method to allow the strategy implementation to decide how theIOEvent
will be handled.- Specified by:
executeIoEvent
in interfaceIOStrategy
- Parameters:
connection
- theConnection
upon which the providedIOEvent
occurred.ioEvent
- theIOEvent
that triggered execution of thisstrategy
- Returns:
- true, if this thread should keep processing IOEvents on the current and other Connections, or false if this thread should hand-off the farther IOEvent processing on any Connections, which means IOStrategy is becoming responsible for continuing IOEvent processing (possibly starting new thread, which will handle IOEvents).
- Throws:
IOException
- if an error occurs processing theIOEvent
.
-
getThreadPoolFor
public Executor getThreadPoolFor(Connection connection, IOEvent ioEvent)
Description copied from interface:IOStrategy
Returns anExecutor
to be used to run given ioEvent processing for the given connection. A null value will be returned if the ioEvent should be executed in the kernel thread.- Specified by:
getThreadPoolFor
in interfaceIOStrategy
- Parameters:
connection
-Connection
ioEvent
- the event to get the Executor for- Returns:
- an
Executor
to be used to run given ioEvent processing for the given connection
-
executeIoEvent
public boolean executeIoEvent(Connection connection, IOEvent ioEvent, boolean isIoEventEnabled) throws IOException
Description copied from interface:IOStrategy
TheSelectorRunner
will invoke this method to allow the strategy implementation to decide how theIOEvent
will be handled.- Specified by:
executeIoEvent
in interfaceIOStrategy
- Parameters:
connection
- theConnection
upon which the providedIOEvent
occurred.ioEvent
- theIOEvent
that triggered execution of thisstrategy
isIoEventEnabled
- true if IOEvent is still enabled on theConnection
, or false if IOEvent was preliminary disabled or IOEvent is being simulated.- Returns:
- true, if this thread should keep processing IOEvents on the current and other Connections, or false if this thread should hand-off the farther IOEvent processing on any Connections, which means IOStrategy is becoming responsible for continuing IOEvent processing (possibly starting new thread, which will handle IOEvents).
- Throws:
IOException
- if an error occurs processing theIOEvent
.
-
createDefaultWorkerPoolConfig
public ThreadPoolConfig createDefaultWorkerPoolConfig(Transport transport)
- Specified by:
createDefaultWorkerPoolConfig
in interfaceWorkerThreadPoolConfigProducer
-
-