Class NioIoHandler
java.lang.Object
io.netty.channel.nio.NioIoHandler
- All Implemented Interfaces:
IoHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate static final intprivate static final booleanprivate final ThreadAwareExecutorprivate static final InternalLoggerprivate static final intprivate booleanprivate final SelectorProviderprivate SelectedSelectionKeySetprivate final IntSupplierprivate SelectorThe NIOSelector.private static final intprivate final SelectStrategyprivate Selectorprivate final AtomicBooleanBoolean that controls determines if a blocked Selector.select should break out of its selection process. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNioIoHandler(ThreadAwareExecutor executor, SelectorProvider selectorProvider, SelectStrategy strategy) -
Method Summary
Modifier and TypeMethodDescriptionprivate static NioIoOpsvoiddestroy()Destroy theIoHandlerand free all its resources.private static voidbooleanisCompatible(Class<? extends IoHandle> handleType) Returnstrueif the given type is compatible with thisIoHandlerand so can be registered,falseotherwise.private static longmillisBeforeDeadline(long selectDeadLineNanos, long currentTimeNanos) static IoHandlerFactoryReturns a newIoHandlerFactorythat createsNioIoHandlerinstancesstatic IoHandlerFactorynewFactory(SelectorProvider selectorProvider) Returns a newIoHandlerFactorythat createsNioIoHandlerinstances.static IoHandlerFactorynewFactory(SelectorProvider selectorProvider, SelectStrategyFactory selectStrategyFactory) Returns a newIoHandlerFactorythat createsNioIoHandlerinstances.private static NioIoHandle(package private) intprivate NioIoHandler.SelectorTuplevoidPrepare to destroy thisIoHandler.private voidprivate intprivate intprivate intprocessSelectedKeysPlain(Set<SelectionKey> selectedKeys) (package private) voidRegister aIoHandlefor IO.(package private) Set<SelectionKey> intrun(IoHandlerContext context) Run the IO handled by thisIoHandler.private voidselect(IoHandlerContext runner, boolean oldWakenUp) private void(package private) int(package private) Selectorselector()private SelectorselectRebuildSelector(int selectCnt) (package private) Selectorvoidwakeup()Wakeup theIoHandler, which means if any operation blocks it should be unblocked and return as soon as possible.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IoHandler
initialize
-
Field Details
-
logger
-
CLEANUP_INTERVAL
private static final int CLEANUP_INTERVAL- See Also:
-
DISABLE_KEY_SET_OPTIMIZATION
private static final boolean DISABLE_KEY_SET_OPTIMIZATION -
MIN_PREMATURE_SELECTOR_RETURNS
private static final int MIN_PREMATURE_SELECTOR_RETURNS- See Also:
-
SELECTOR_AUTO_REBUILD_THRESHOLD
private static final int SELECTOR_AUTO_REBUILD_THRESHOLD -
selectNowSupplier
-
selector
-
unwrappedSelector
-
selectedKeys
-
provider
-
wakenUp
Boolean that controls determines if a blocked Selector.select should break out of its selection process. In our case we use a timeout for the select method and the select method will block for that time unless waken up. -
selectStrategy
-
executor
-
cancelledKeys
private int cancelledKeys -
needsToSelectAgain
private boolean needsToSelectAgain
-
-
Constructor Details
-
NioIoHandler
private NioIoHandler(ThreadAwareExecutor executor, SelectorProvider selectorProvider, SelectStrategy strategy)
-
-
Method Details
-
openSelector
-
selectorProvider
-
selector
Selector selector() -
numRegistered
int numRegistered() -
registeredSet
Set<SelectionKey> registeredSet() -
rebuildSelector0
void rebuildSelector0() -
nioHandle
-
cast
-
register
-
run
Description copied from interface:IoHandlerRun the IO handled by thisIoHandler. TheIoHandlerContextshould be used to ensure we not execute too long and so block the processing of other task that are scheduled on theThreadAwareExecutor. This is done by takingIoHandlerContext.delayNanos(long)orIoHandlerContext.deadlineNanos()into account.- Specified by:
runin interfaceIoHandler- Parameters:
context- theIoHandlerContext.- Returns:
- the number of
IoHandlefor which I/O was handled. Internal events such as wakeups and timer expirations must not be included in this count.
-
handleLoopException
-
processSelectedKeys
private int processSelectedKeys() -
destroy
-
processSelectedKeysPlain
-
processSelectedKeysOptimized
private int processSelectedKeysOptimized() -
processSelectedKey
-
prepareToDestroy
public void prepareToDestroy()Description copied from interface:IoHandlerPrepare to destroy thisIoHandler. This method will be called beforeIoHandler.destroy()and may be called multiple times.- Specified by:
prepareToDestroyin interfaceIoHandler
-
wakeup
-
isCompatible
Description copied from interface:IoHandlerReturnstrueif the given type is compatible with thisIoHandlerand so can be registered,falseotherwise.- Specified by:
isCompatiblein interfaceIoHandler- Parameters:
handleType- the type of theIoHandle.- Returns:
- if compatible of not.
-
unwrappedSelector
Selector unwrappedSelector() -
select
- Throws:
IOException
-
millisBeforeDeadline
private static long millisBeforeDeadline(long selectDeadLineNanos, long currentTimeNanos) -
selectNow
- Throws:
IOException
-
selectRebuildSelector
- Throws:
IOException
-
selectAgain
private void selectAgain() -
newFactory
Returns a newIoHandlerFactorythat createsNioIoHandlerinstances- Returns:
- factory the
IoHandlerFactory.
-
newFactory
Returns a newIoHandlerFactorythat createsNioIoHandlerinstances.- Parameters:
selectorProvider- theSelectorProviderto use.- Returns:
- factory the
IoHandlerFactory.
-
newFactory
public static IoHandlerFactory newFactory(SelectorProvider selectorProvider, SelectStrategyFactory selectStrategyFactory) Returns a newIoHandlerFactorythat createsNioIoHandlerinstances.- Parameters:
selectorProvider- theSelectorProviderto use.selectStrategyFactory- theSelectStrategyFactoryto use.- Returns:
- factory the
IoHandlerFactory.
-