Class SelectorHandler

java.lang.Object
org.omegazero.net.common.SelectorHandler
Direct Known Subclasses:
ConnectionSelectorHandler

public abstract class SelectorHandler extends Object
Wraps a java.nio Selector.

A thread must call initSelector() followed by runSelectorLoop() to start selecting keys, which can then be handled in the abstract method handleSelectedKey(SelectionKey). Additional keys may be added safely while running using registerChannel(SelectableChannel, int, Object).

This class defines the following system properties:
  • org.omegazero.net.nioselector.rebuildThreshold (integer, default 1024) - The maximum number of times the selection operation may return in a row without having any keys selected. If this threshold is exceeded, the selector will be rebuilt. This feature exists to mitigate the selector/epoll immediate return bug, which may exist on older JVM distributions
  • org.omegazero.net.nioselector.maxRebuilds (integer, default 8) - The maximum number of times the selector may be rebuilt in a row (see above). If this threshold is exceeded, the selector loop will exit with an IOException