public class ConnectionController extends Controller implements Runnable, WakeupListener
helper, overloaded, running| Constructor and Description |
|---|
ConnectionController(ConnectionHelper<?> helper)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
controlConnection(Connection<?> conn)
Controls a given connection for messages to read or write.
|
protected void |
controlConnections()
Controls all helper connections.
|
protected Selector |
createSelector()
Creates a new NIO selector.
|
protected void |
doInit()
Initializes the controller before entering the control loop.
|
protected void |
doRelease()
Method called-back with the controller stops running.
|
protected void |
doRun(long sleepTime)
Do the actual controller work.
|
protected Queue<SelectionRegistration> |
getNewRegistrations()
Returns the queue of new selection registrations.
|
protected Selector |
getSelector()
Returns the NIO selector.
|
protected Queue<SelectionRegistration> |
getUpdatedRegistrations()
Returns the queue of updated selection registrations.
|
protected void |
onSelected(SelectionKey selectedKey)
Called back when a ready key has been selected.
|
void |
onWokeup(SelectionRegistration selectionRegistration)
Invoked when one of the connections needs to wake up the controller.
|
SelectionRegistration |
register(SelectableChannel selectableChannel,
int interestOperations,
SelectionListener listener)
Registers a selection listener with the underlying selector for the given
operations and returns the registration created.
|
protected void |
registerKeys()
Registers all the new selection registration requests.
|
protected void |
selectKeys(long sleepTime)
Selects the keys ready for IO operations.
|
void |
shutdown()
Abort the controller.
|
protected void |
updateKeys()
Updates all the selection registrations for new interest or cancellation.
|
void |
wakeup()
Wakes up the controller thread if wait for an NIO selection.
|
getHelper, getWorkerService, isOverloaded, isRunning, run, setOverloadedpublic ConnectionController(ConnectionHelper<?> helper)
helper - The parent connector helper.protected void controlConnection(Connection<?> conn) throws IOException
conn - The connection to control.IOExceptionprotected void controlConnections()
throws IOException
IOExceptionprotected Selector createSelector()
protected void doInit()
ControllerdoInit in class Controllerprotected void doRelease()
ControllerdoRelease in class Controllerprotected void doRun(long sleepTime)
throws IOException
ControllerController.run() to provide an
easy method to overload.doRun in class ControllersleepTime - The maximum amount of sleep time.IOExceptionprotected Queue<SelectionRegistration> getNewRegistrations()
protected Selector getSelector()
protected Queue<SelectionRegistration> getUpdatedRegistrations()
protected void onSelected(SelectionKey selectedKey) throws IOException
selectedKey - The selected key selected.IOExceptionpublic void onWokeup(SelectionRegistration selectionRegistration) throws IOException
onWokeup in interface WakeupListenerselectionRegistration - The selected registration.IOExceptionpublic SelectionRegistration register(SelectableChannel selectableChannel, int interestOperations, SelectionListener listener) throws IOException
selectableChannel - The NIO selectable channel.interestOperations - The initial operations of interest.listener - The listener to notify.IOExceptionprotected void registerKeys()
protected void selectKeys(long sleepTime)
throws IOException,
ClosedByInterruptException
sleepTime - The max sleep time.IOExceptionClosedByInterruptExceptionpublic void shutdown()
Controllershutdown in class Controllerprotected void updateKeys()
throws IOException
IOExceptionpublic void wakeup()
Copyright © 2005–2015. All rights reserved.