Top Description Inners Fields Constructors Methods
io.netty5.channel.nio

public final Class NioHandler

extends Object
implements IoHandler
Class Inheritance
All Implemented Interfaces
io.netty5.channel.IoHandler
Imports
io.netty5.channel.Channel, .ChannelException, .DefaultSelectStrategyFactory, .IoExecutionContext, .IoHandle, .IoHandler, .IoHandlerFactory, .SelectStrategy, .SelectStrategyFactory, io.netty5.util.internal.PlatformDependent, .ReflectionUtil, .StringUtil, .SystemPropertyUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, .UncheckedIOException, java.lang.reflect.Field, java.nio.channels.CancelledKeyException, .SelectionKey, .Selector, java.nio.channels.spi.SelectorProvider, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collection, .Iterator, .Set, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicBoolean, java.util.function.IntSupplier

IoHandler implementation which register the Channel's to a Selector and so does the multi-plexing of these in the event loop.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private int
private static final int
private static final boolean
private static final InternalLogger
private static final int
private boolean
private final SelectorProvider
private SelectedSelectionKeySet
private final IntSupplier
private Selector
private static final int
private final SelectStrategy
private Selector
private final AtomicBoolean
wakenUp

Boolean that controls determines if a blocked Selector.select should break out of its selection process.

Constructor Summary

AccessConstructor and Description
private
private
NioHandler(SelectorProvider selectorProvider, SelectStrategy strategy)

Method Summary

Modifier and TypeMethod and Description
public void
deregister(IoHandle
the IoHandle to deregister..
handle
)

Implements io.netty5.channel.IoHandler.deregister.

Deregister a IoHandle for IO.
public void
destroy()

Implements io.netty5.channel.IoHandler.destroy.

Destroy the IoHandler and free all its resources.
private static void
public boolean
isCompatible(Class<? extends IoHandle>
the type of the IoHandle.
handleType
)

Implements io.netty5.channel.IoHandler.isCompatible.

Returns true if the given type is compatible with this IoHandler and so can be registered, false otherwise.
public static IoHandlerFactory
newFactory()

Returns a new IoHandlerFactory that creates NioHandler instances.

public static IoHandlerFactory
newFactory(final SelectorProvider selectorProvider, final SelectStrategyFactory selectStrategyFactory)

Returns a new IoHandlerFactory that creates NioHandler instances.

private static NioProcessor
private NioHandler.SelectorTuple
public void
private void
private int
private int
private int
pack-priv void
rebuildSelector()

Replaces the current Selector of this event loop with newly created Selectors to work around the infamous epoll 100% CPU bug.

public void
register(IoHandle
the Channel to register..
handle
)

Implements io.netty5.channel.IoHandler.register.

Register a Channel for IO.
public int
run(IoExecutionContext runner)

Implements io.netty5.channel.IoHandler.run.

Run the IO handled by this IoHandler.
private void
select(IoExecutionContext runner, boolean oldWakenUp)

private void
private int
public SelectorProvider
selectorProvider()

Returns the SelectorProvider used by this NioHandler to obtain the Selector.

private Selector
selectRebuildSelector(int selectCnt)

pack-priv Selector
public void
wakeup(boolean inEventLoop)

Implements io.netty5.channel.IoHandler.wakeup.

Wakeup the IoHandler, which means if any operation blocks it should be unblocked and return as soon as possible.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cancelledKeysback to summary
private int cancelledKeys
CLEANUP_INTERVALback to summary
private static final int CLEANUP_INTERVAL
DISABLE_KEY_SET_OPTIMIZATIONback to summary
private static final boolean DISABLE_KEY_SET_OPTIMIZATION
loggerback to summary
private static final InternalLogger logger
MIN_PREMATURE_SELECTOR_RETURNSback to summary
private static final int MIN_PREMATURE_SELECTOR_RETURNS
needsToSelectAgainback to summary
private boolean needsToSelectAgain
providerback to summary
private final SelectorProvider provider
selectedKeysback to summary
private SelectedSelectionKeySet selectedKeys
selectNowSupplierback to summary
private final IntSupplier selectNowSupplier
selectorback to summary
private Selector selector

The NIO Selector.

SELECTOR_AUTO_REBUILD_THRESHOLDback to summary
private static final int SELECTOR_AUTO_REBUILD_THRESHOLD
selectStrategyback to summary
private final SelectStrategy selectStrategy
unwrappedSelectorback to summary
private Selector unwrappedSelector
wakenUpback to summary
private final AtomicBoolean 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.

Constructor Detail

NioHandlerback to summary
private NioHandler()
NioHandlerback to summary
private NioHandler(SelectorProvider selectorProvider, SelectStrategy strategy)

Method Detail

deregisterback to summary
public void deregister(IoHandle handle)

Implements io.netty5.channel.IoHandler.deregister.

Doc from io.netty5.channel.IoHandler.deregister.

Deregister a IoHandle for IO.

Parameters
handle:IoHandle

the IoHandle to deregister..

Annotations
@Override
destroyback to summary
public void destroy()

Implements io.netty5.channel.IoHandler.destroy.

Doc from io.netty5.channel.IoHandler.destroy.

Destroy the IoHandler and free all its resources.

Annotations
@Override
handleLoopExceptionback to summary
private static void handleLoopException(Throwable t)
isCompatibleback to summary
public boolean isCompatible(Class<? extends IoHandle> handleType)

Implements io.netty5.channel.IoHandler.isCompatible.

Doc from io.netty5.channel.IoHandler.isCompatible.

Returns true if the given type is compatible with this IoHandler and so can be registered, false otherwise.

Parameters
handleType:Class<? extends IoHandle>

the type of the IoHandle.

Returns:boolean

if compatible of not.

Annotations
@Override
newFactoryback to summary
public static IoHandlerFactory newFactory()

Returns a new IoHandlerFactory that creates NioHandler instances.

newFactoryback to summary
public static IoHandlerFactory newFactory(final SelectorProvider selectorProvider, final SelectStrategyFactory selectStrategyFactory)

Returns a new IoHandlerFactory that creates NioHandler instances.

nioHandleback to summary
private static NioProcessor nioHandle(IoHandle handle)
openSelectorback to summary
private NioHandler.SelectorTuple openSelector()
prepareToDestroyback to summary
public void prepareToDestroy()

Implements io.netty5.channel.IoHandler.prepareToDestroy.

Doc from io.netty5.channel.IoHandler.prepareToDestroy.

Prepare to destroy this IoHandler. This method will be called before destroy() and may be called multiple times.

Annotations
@Override
processSelectedKeyback to summary
private void processSelectedKey(SelectionKey k)
processSelectedKeysback to summary
private int processSelectedKeys()
processSelectedKeysOptimizedback to summary
private int processSelectedKeysOptimized()
processSelectedKeysPlainback to summary
private int processSelectedKeysPlain(Set<SelectionKey> selectedKeys)
rebuildSelectorback to summary
pack-priv void rebuildSelector()

Replaces the current Selector of this event loop with newly created Selectors to work around the infamous epoll 100% CPU bug.

registerback to summary
public void register(IoHandle handle) throws Exception

Implements io.netty5.channel.IoHandler.register.

Doc from io.netty5.channel.IoHandler.register.

Register a Channel for IO.

Parameters
handle:IoHandle

the Channel to register..

Annotations
@Override
Exceptions
Exception:
thrown if an error happens during registration.
runback to summary
public int run(IoExecutionContext runner)

Implements io.netty5.channel.IoHandler.run.

Doc from io.netty5.channel.IoHandler.run.

Run the IO handled by this IoHandler. The IoExecutionContext should be used to ensure we not execute too long and so block the processing of other task that are scheduled on the EventLoop. This is done by taking IoExecutionContext#delayNanos(long) or IoExecutionContext#deadlineNanos() into account.

Returns:int

the number of IoHandle for which I/O was handled.

Annotations
@Override
selectback to summary
private void select(IoExecutionContext runner, boolean oldWakenUp) throws IOException
selectAgainback to summary
private void selectAgain()
selectNowback to summary
private int selectNow() throws IOException
selectorProviderback to summary
public SelectorProvider selectorProvider()

Returns the SelectorProvider used by this NioHandler to obtain the Selector.

selectRebuildSelectorback to summary
private Selector selectRebuildSelector(int selectCnt) throws IOException
unwrappedSelectorback to summary
pack-priv Selector unwrappedSelector()
wakeupback to summary
public void wakeup(boolean inEventLoop)

Implements io.netty5.channel.IoHandler.wakeup.

Doc from io.netty5.channel.IoHandler.wakeup.

Wakeup the IoHandler, which means if any operation blocks it should be unblocked and return as soon as possible.

Annotations
@Override
io.netty5.channel.nio back to summary

private final Class NioHandler.SelectorTuple

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Selector
pack-priv final Selector

Constructor Summary

AccessConstructor and Description
pack-priv
SelectorTuple(Selector unwrappedSelector)

pack-priv
SelectorTuple(Selector unwrappedSelector, Selector selector)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

selectorback to summary
pack-priv final Selector selector
unwrappedSelectorback to summary
pack-priv final Selector unwrappedSelector

Constructor Detail

SelectorTupleback to summary
pack-priv SelectorTuple(Selector unwrappedSelector)
SelectorTupleback to summary
pack-priv SelectorTuple(Selector unwrappedSelector, Selector selector)