Package org.apache.tomcat.util.net
Class NioEndpoint.Poller
- java.lang.Object
-
- org.apache.tomcat.util.net.NioEndpoint.Poller
-
- All Implemented Interfaces:
java.lang.Runnable
- Enclosing class:
- NioEndpoint
public class NioEndpoint.Poller extends java.lang.Object implements java.lang.RunnablePoller class.
-
-
Constructor Summary
Constructors Constructor Description Poller()Creates a new poller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(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.intgetKeyCount()Returns the number of registered keys.java.nio.channels.SelectorgetSelector()Returns the selector.protected voidprocessKey(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper)Processes a selection key event.SendfileStateprocessSendfile(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, boolean calledByProcessor)Processes a sendfile operation.protected voidreg(java.nio.channels.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(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, int readyOps)Unregisters interest operations for a socket.
-
-
-
Method Detail
-
getKeyCount
public int getKeyCount()
Returns the number of registered keys.- Returns:
- the key count
-
getSelector
public java.nio.channels.Selector getSelector()
Returns the selector.- Returns:
- the selector
-
destroy
protected void destroy()
Destroy the poller.
-
add
public void add(NioEndpoint.NioSocketWrapper socketWrapper, int interestOps)
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
public void register(NioEndpoint.NioSocketWrapper socketWrapper)
Registers a newly created socket with the poller.- Parameters:
socketWrapper- The socket wrapper
-
run
public void run()
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.- Specified by:
runin interfacejava.lang.Runnable
-
processKey
protected void processKey(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper)Processes a selection key event.- Parameters:
sk- The selection keysocketWrapper- The socket wrapper
-
processSendfile
public SendfileState processSendfile(java.nio.channels.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
protected void unreg(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, int readyOps)Unregisters interest operations for a socket.- Parameters:
sk- The selection keysocketWrapper- The socket wrapperreadyOps- The ready operations to remove
-
reg
protected void reg(java.nio.channels.SelectionKey sk, NioEndpoint.NioSocketWrapper socketWrapper, int intops)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
-
-