Class NioEndpoint.Poller
java.lang.Object
org.apache.tomcat.util.net.NioEndpoint.Poller
- All Implemented Interfaces:
Runnable
- Enclosing class:
NioEndpoint
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(NioEndpoint.NioSocketWrapper socketWrapper, int interestOps) Add specified socket and associated pool to the poller.protected voiddestroy()Destroy the poller.booleanevents()Processes events in the event queue of the Poller.intReturns the number of registered keys.Returns the selector.protected voidprocessKey(SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper) Processes a selection key event.processSendfile(SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, boolean calledByProcessor) Processes a sendfile operation.protected voidreg(SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, int intops) Registers interest operations for a socket.voidregister(NioEndpoint.NioSocketWrapper socketWrapper) Registers a newly created socket with the poller.voidrun()The background thread that adds sockets to the Poller, checks the poller for triggered events and hands the associated socket off to an appropriate processor as events occur.protected voidtimeout(int keyCount, boolean hasEvents) Checks for socket timeouts.protected voidunreg(SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, int readyOps) Unregisters interest operations for a socket.
-
Constructor Details
-
Poller
Creates a new poller.- Throws:
IOException- If the selector cannot be opened
-
-
Method Details
-
getKeyCount
public int getKeyCount()Returns the number of registered keys.- Returns:
- the key count
-
getSelector
-
destroy
protected void destroy()Destroy the poller. -
add
Add specified socket and associated pool to the poller. The socket will be added to a temporary array, and polled first after a maximum amount of time equal to pollTime (in most cases, latency will be much lower, however).- Parameters:
socketWrapper- to add to the pollerinterestOps- Operations for which to register this socket with the Poller
-
events
public boolean events()Processes events in the event queue of the Poller.- Returns:
trueif some events were processed,falseif queue was empty
-
register
Registers a newly created socket with the poller.- Parameters:
socketWrapper- The socket wrapper
-
run
-
processKey
Processes a selection key event.- Parameters:
sk- The selection keysocketWrapper- The socket wrapper
-
processSendfile
public SendfileState processSendfile(SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, boolean calledByProcessor) Processes a sendfile operation.- Parameters:
sk- The selection keysocketWrapper- The socket wrappercalledByProcessor- Whether called from a processor thread- Returns:
- the sendfile state
-
unreg
Unregisters interest operations for a socket.- Parameters:
sk- The selection keysocketWrapper- The socket wrapperreadyOps- The ready operations to remove
-
reg
Registers interest operations for a socket.- Parameters:
sk- The selection keysocketWrapper- The socket wrapperintops- The interest operations to set
-
timeout
protected void timeout(int keyCount, boolean hasEvents) Checks for socket timeouts.- Parameters:
keyCount- Number of selected keyshasEvents- Whether there were events processed
-