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, setOverloaded
public ConnectionController(ConnectionHelper<?> helper)
helper
- The parent connector helper.protected void controlConnection(Connection<?> conn) throws IOException
conn
- The connection to control.IOException
protected void controlConnections() throws IOException
IOException
protected Selector createSelector()
protected void doInit()
Controller
doInit
in class Controller
protected void doRelease()
Controller
doRelease
in class Controller
protected void doRun(long sleepTime) throws IOException
Controller
Controller.run()
to provide an
easy method to overload.doRun
in class Controller
sleepTime
- The maximum amount of sleep time.IOException
protected Queue<SelectionRegistration> getNewRegistrations()
protected Selector getSelector()
protected Queue<SelectionRegistration> getUpdatedRegistrations()
protected void onSelected(SelectionKey selectedKey) throws IOException
selectedKey
- The selected key selected.IOException
public void onWokeup(SelectionRegistration selectionRegistration) throws IOException
onWokeup
in interface WakeupListener
selectionRegistration
- The selected registration.IOException
public 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.IOException
protected void registerKeys()
protected void selectKeys(long sleepTime) throws IOException, ClosedByInterruptException
sleepTime
- The max sleep time.IOException
ClosedByInterruptException
public void shutdown()
Controller
shutdown
in class Controller
protected void updateKeys() throws IOException
IOException
public void wakeup()
Copyright © 2005–2018. All rights reserved.