public abstract class

AbstractIOReactor

extends Object
implements IOReactor
java.lang.Object
   ↳ org.apache.http.impl.nio.reactor.AbstractIOReactor
Known Direct Subclasses

Class Overview

Generic implementation of IOReactor that can used as a subclass for more specialized I/O reactors. It is based on a single Selector instance.

Summary

Public Constructors
AbstractIOReactor(long selectTimeout)
Creates new AbstractIOReactor instance.
AbstractIOReactor(long selectTimeout, boolean interestOpsQueueing)
Creates new AbstractIOReactor instance.
Public Methods
void addChannel(ChannelEntry channelEntry)
Adds new channel entry.
void awaitShutdown(long timeout)
Blocks for the given period of time in milliseconds awaiting the completion of the reactor shutdown.
boolean getInterestOpsQueueing()
Returns true if interest Ops queueing is enabled, false otherwise.
IOReactorStatus getStatus()
Returns the current status of the reactor.
void gracefulShutdown()
Attempts graceful shutdown of this I/O reactor.
void hardShutdown()
Attempts force-shutdown of this I/O reactor.
void shutdown(long gracePeriod)
Initiates shutdown of the reactor and blocks approximately for the given period of time in milliseconds waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.
void shutdown()
Initiates shutdown of the reactor and blocks for a default period of time waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.
Protected Methods
abstract void acceptable(SelectionKey key)
Triggered when the key signals OP_ACCEPT readiness.
void closeActiveChannels()
Closes out all active channels registered with the selector of this I/O reactor.
void closeNewChannels()
Closes out all new channels pending registration with the selector of this I/O reactor.
void closeSessions()
Closes out all I/O sessions maintained by this I/O reactor.
abstract void connectable(SelectionKey key)
Triggered when the key signals OP_CONNECT readiness.
void execute()
Activates the I/O reactor.
abstract IOSession getSession(SelectionKey key)
Obtains IOSession instance associated with the given selection key.
void processEvent(SelectionKey key)
Processes new event on the given selection key.
void queueClosedSession(IOSession session)
Queues the given I/O session to be processed asynchronously as closed.
abstract void readable(SelectionKey key)
Triggered when the key signals OP_READ readiness.
abstract void sessionClosed(IOSession session)
Triggered when a session has been closed.
abstract void sessionCreated(SelectionKey key, IOSession session)
Triggered when new session has been created.
abstract void timeoutCheck(SelectionKey key, long now)
Triggered to verify whether the I/O session associated with the given selection key has not timed out.
abstract void validate(Set<SelectionKey> keys)
Triggered to validate keys currently registered with the selector.
abstract void writable(SelectionKey key)
Triggered when the key signals OP_WRITE readiness.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.http.nio.reactor.IOReactor

Public Constructors

public AbstractIOReactor (long selectTimeout)

Creates new AbstractIOReactor instance.

Parameters
selectTimeout the select timeout.
Throws
IOReactorException in case if a non-recoverable I/O error.

public AbstractIOReactor (long selectTimeout, boolean interestOpsQueueing)

Creates new AbstractIOReactor instance.

Parameters
selectTimeout the select timeout.
interestOpsQueueing Ops queueing flag.
Throws
IOReactorException in case if a non-recoverable I/O error.

Public Methods

public void addChannel (ChannelEntry channelEntry)

Adds new channel entry. The channel will be asynchronously registered with the selector.

Parameters
channelEntry the channel entry.

public void awaitShutdown (long timeout)

Blocks for the given period of time in milliseconds awaiting the completion of the reactor shutdown.

Parameters
timeout the maximum wait time.
Throws
InterruptedException if interrupted.

public boolean getInterestOpsQueueing ()

Returns true if interest Ops queueing is enabled, false otherwise.

public IOReactorStatus getStatus ()

Returns the current status of the reactor.

Returns
  • reactor status.

public void gracefulShutdown ()

Attempts graceful shutdown of this I/O reactor.

public void hardShutdown ()

Attempts force-shutdown of this I/O reactor.

public void shutdown (long gracePeriod)

Initiates shutdown of the reactor and blocks approximately for the given period of time in milliseconds waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.

Parameters
gracePeriod wait time in milliseconds.

public void shutdown ()

Initiates shutdown of the reactor and blocks for a default period of time waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds. It is up to individual implementations to decide for how long this method can remain blocked.

Protected Methods

protected abstract void acceptable (SelectionKey key)

Triggered when the key signals OP_ACCEPT readiness.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.

protected void closeActiveChannels ()

Closes out all active channels registered with the selector of this I/O reactor.

Throws
IOReactorException - not thrown currently

protected void closeNewChannels ()

Closes out all new channels pending registration with the selector of this I/O reactor.

Throws
IOReactorException - not thrown currently

protected void closeSessions ()

Closes out all I/O sessions maintained by this I/O reactor.

protected abstract void connectable (SelectionKey key)

Triggered when the key signals OP_CONNECT readiness.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.

protected void execute ()

Activates the I/O reactor. The I/O reactor will start reacting to I/O events and triggering notification methods.

This method will enter the infinite I/O select loop on the Selector instance associated with this I/O reactor.

The method will remain blocked unto the I/O reactor is shut down or the execution thread is interrupted.

Throws
InterruptedIOException if the dispatch thread is interrupted.
IOReactorException in case if a non-recoverable I/O error.

protected abstract IOSession getSession (SelectionKey key)

Obtains IOSession instance associated with the given selection key.

Parameters
key the selection key.
Returns
  • I/O session.

protected void processEvent (SelectionKey key)

Processes new event on the given selection key.

Parameters
key the selection key that triggered an event.

protected void queueClosedSession (IOSession session)

Queues the given I/O session to be processed asynchronously as closed.

Parameters
session the closed I/O session.

protected abstract void readable (SelectionKey key)

Triggered when the key signals OP_READ readiness.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.

protected abstract void sessionClosed (IOSession session)

Triggered when a session has been closed.

Super-classes can implement this method to react to the event.

Parameters
session closed I/O session.

protected abstract void sessionCreated (SelectionKey key, IOSession session)

Triggered when new session has been created.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.
session new I/O session.

protected abstract void timeoutCheck (SelectionKey key, long now)

Triggered to verify whether the I/O session associated with the given selection key has not timed out.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.
now current time as long value.

protected abstract void validate (Set<SelectionKey> keys)

Triggered to validate keys currently registered with the selector. This method is called after each I/O select loop.

Super-classes can implement this method to run validity checks on active sessions and include additional processing that needs to be executed after each I/O select loop.

Parameters
keys all selection keys registered with the selector.

protected abstract void writable (SelectionKey key)

Triggered when the key signals OP_WRITE readiness.

Super-classes can implement this method to react to the event.

Parameters
key the selection key.