Package org.apache.http.impl.nio.reactor
Class DefaultListeningIOReactor
- java.lang.Object
-
- org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor
-
- org.apache.http.impl.nio.reactor.DefaultListeningIOReactor
-
- All Implemented Interfaces:
IOReactor
,ListeningIOReactor
public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor implements ListeningIOReactor
Default implementation ofListeningIOReactor
. This class extendsAbstractMultiworkerIOReactor
with capability to listen for incoming connections.- Since:
- 4.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor
AbstractMultiworkerIOReactor.DefaultThreadFactory, AbstractMultiworkerIOReactor.Worker
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<ListenerEndpointImpl>
endpoints
private boolean
paused
private java.util.Set<java.net.SocketAddress>
pausedEndpoints
private java.util.Queue<ListenerEndpointImpl>
requestQueue
-
Fields inherited from class org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor
auditLog, config, exceptionHandler, interestOpsQueueing, params, selector, selectTimeout, status
-
-
Constructor Summary
Constructors Constructor Description DefaultListeningIOReactor()
Creates an instance of DefaultListeningIOReactor with default configuration.DefaultListeningIOReactor(int workerCount, java.util.concurrent.ThreadFactory threadFactory, HttpParams params)
Deprecated.DefaultListeningIOReactor(int workerCount, HttpParams params)
Deprecated.DefaultListeningIOReactor(IOReactorConfig config)
Creates an instance of DefaultListeningIOReactor with the given configuration.DefaultListeningIOReactor(IOReactorConfig config, java.util.concurrent.ThreadFactory threadFactory)
Creates an instance of DefaultListeningIOReactor with the given configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cancelRequests()
Triggered to cancel pending session requests.private ListenerEndpointImpl
createEndpoint(java.net.SocketAddress address)
java.util.Set<ListenerEndpoint>
getEndpoints()
Returns a set of endpoints for this I/O reactor.ListenerEndpoint
listen(java.net.SocketAddress address)
Opens a new listener endpoint with the given socket address.void
pause()
Suspends the I/O reactor preventing it from accepting new connections on all active endpoints.private void
processEvent(java.nio.channels.SelectionKey key)
protected void
processEvents(int readyCount)
Triggered to process I/O events registered by the mainSelector
.private void
processSessionRequests()
void
resume()
Resumes the I/O reactor restoring its ability to accept incoming connections on all active endpoints.-
Methods inherited from class org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor
addChannel, addExceptionEvent, addExceptionEvent, awaitShutdown, closeChannel, convert, doShutdown, execute, getAuditLog, getStatus, prepareSocket, registerChannel, setExceptionHandler, shutdown, shutdown
-
-
-
-
Field Detail
-
requestQueue
private final java.util.Queue<ListenerEndpointImpl> requestQueue
-
endpoints
private final java.util.Set<ListenerEndpointImpl> endpoints
-
pausedEndpoints
private final java.util.Set<java.net.SocketAddress> pausedEndpoints
-
paused
private volatile boolean paused
-
-
Constructor Detail
-
DefaultListeningIOReactor
public DefaultListeningIOReactor(IOReactorConfig config, java.util.concurrent.ThreadFactory threadFactory) throws IOReactorException
Creates an instance of DefaultListeningIOReactor with the given configuration.- Parameters:
config
- I/O reactor configuration.threadFactory
- the factory to create threads. Can benull
.- Throws:
IOReactorException
- in case if a non-recoverable I/O error.- Since:
- 4.2
-
DefaultListeningIOReactor
public DefaultListeningIOReactor(IOReactorConfig config) throws IOReactorException
Creates an instance of DefaultListeningIOReactor with the given configuration.- Parameters:
config
- I/O reactor configuration. Can benull
.- Throws:
IOReactorException
- in case if a non-recoverable I/O error.- Since:
- 4.2
-
DefaultListeningIOReactor
public DefaultListeningIOReactor() throws IOReactorException
Creates an instance of DefaultListeningIOReactor with default configuration.- Throws:
IOReactorException
- in case if a non-recoverable I/O error.- Since:
- 4.2
-
DefaultListeningIOReactor
@Deprecated public DefaultListeningIOReactor(int workerCount, java.util.concurrent.ThreadFactory threadFactory, HttpParams params) throws IOReactorException
Deprecated.- Throws:
IOReactorException
-
DefaultListeningIOReactor
@Deprecated public DefaultListeningIOReactor(int workerCount, HttpParams params) throws IOReactorException
Deprecated.- Throws:
IOReactorException
-
-
Method Detail
-
cancelRequests
protected void cancelRequests() throws IOReactorException
Description copied from class:AbstractMultiworkerIOReactor
Triggered to cancel pending session requests.Super-classes can implement this method to react to the event.
- Specified by:
cancelRequests
in classAbstractMultiworkerIOReactor
- Throws:
IOReactorException
- in case if a non-recoverable I/O error.
-
processEvents
protected void processEvents(int readyCount) throws IOReactorException
Description copied from class:AbstractMultiworkerIOReactor
Triggered to process I/O events registered by the mainSelector
.Super-classes can implement this method to react to the event.
- Specified by:
processEvents
in classAbstractMultiworkerIOReactor
- Parameters:
readyCount
- event count.- Throws:
IOReactorException
- in case if a non-recoverable I/O error.
-
processEvent
private void processEvent(java.nio.channels.SelectionKey key) throws IOReactorException
- Throws:
IOReactorException
-
createEndpoint
private ListenerEndpointImpl createEndpoint(java.net.SocketAddress address)
-
listen
public ListenerEndpoint listen(java.net.SocketAddress address)
Description copied from interface:ListeningIOReactor
Opens a new listener endpoint with the given socket address. Once the endpoint is fully initialized it starts accepting incoming connections and propagates I/O activity notifications to the I/O event dispatcher.ListenerEndpoint.waitFor()
can be used to wait for the listener to be come ready to accept incoming connections.ListenerEndpoint.close()
can be used to shut down the listener even before it is fully initialized.- Specified by:
listen
in interfaceListeningIOReactor
- Parameters:
address
- the socket address to listen on.- Returns:
- listener endpoint.
-
processSessionRequests
private void processSessionRequests() throws IOReactorException
- Throws:
IOReactorException
-
getEndpoints
public java.util.Set<ListenerEndpoint> getEndpoints()
Description copied from interface:ListeningIOReactor
Returns a set of endpoints for this I/O reactor.- Specified by:
getEndpoints
in interfaceListeningIOReactor
- Returns:
- set of endpoints.
-
pause
public void pause() throws java.io.IOException
Description copied from interface:ListeningIOReactor
Suspends the I/O reactor preventing it from accepting new connections on all active endpoints.- Specified by:
pause
in interfaceListeningIOReactor
- Throws:
java.io.IOException
- in case of an I/O error.
-
resume
public void resume() throws java.io.IOException
Description copied from interface:ListeningIOReactor
Resumes the I/O reactor restoring its ability to accept incoming connections on all active endpoints.- Specified by:
resume
in interfaceListeningIOReactor
- Throws:
java.io.IOException
- in case of an I/O error.
-
-