org.restlet.engine.connector
Class ConnectionController

java.lang.Object
  extended by org.restlet.engine.connector.Controller
      extended by org.restlet.engine.connector.ConnectionController
All Implemented Interfaces:
Runnable, WakeupListener
Direct Known Subclasses:
ServerConnectionController

public class ConnectionController
extends Controller
implements Runnable, WakeupListener

Controls the IO work of parent connector helper and manages its connections.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.engine.connector.Controller
helper, overloaded, running
 
Constructor Summary
ConnectionController(ConnectionHelper<?> helper)
          Constructor.
 
Method Summary
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.
 
Methods inherited from class org.restlet.engine.connector.Controller
getHelper, getWorkerService, isOverloaded, isRunning, run, setOverloaded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Constructor Detail

ConnectionController

public ConnectionController(ConnectionHelper<?> helper)
Constructor.

Parameters:
helper - The parent connector helper.
Method Detail

controlConnection

protected void controlConnection(Connection<?> conn)
                          throws IOException
Controls a given connection for messages to read or write. Close inactive connections, select ready connections or register interest in NIO operations.

Parameters:
conn - The connection to control.
Throws:
IOException

controlConnections

protected void controlConnections()
                           throws IOException
Controls all helper connections.

Throws:
IOException

createSelector

protected Selector createSelector()
Creates a new NIO selector.

Returns:
A new NIO selector.

doInit

protected void doInit()
Description copied from class: Controller
Initializes the controller before entering the control loop.

Overrides:
doInit in class Controller

doRelease

protected void doRelease()
Description copied from class: Controller
Method called-back with the controller stops running.

Overrides:
doRelease in class Controller

doRun

protected void doRun(long sleepTime)
              throws IOException
Description copied from class: Controller
Do the actual controller work. Called by the Controller.run() to provide an easy method to overload.

Overrides:
doRun in class Controller
Parameters:
sleepTime - The maximum amount of sleep time.
Throws:
IOException

getNewRegistrations

protected Queue<SelectionRegistration> getNewRegistrations()
Returns the queue of new selection registrations.

Returns:
The queue of new selection registrations.

getSelector

protected Selector getSelector()
Returns the NIO selector.

Returns:
The NIO selector.

getUpdatedRegistrations

protected Queue<SelectionRegistration> getUpdatedRegistrations()
Returns the queue of updated selection registrations.

Returns:
The queue of updated selection registrations.

onSelected

protected void onSelected(SelectionKey selectedKey)
                   throws IOException
Called back when a ready key has been selected.

Parameters:
selectedKey - The selected key selected.
Throws:
IOException

onWokeup

public void onWokeup(SelectionRegistration selectionRegistration)
              throws IOException
Invoked when one of the connections needs to wake up the controller.

Specified by:
onWokeup in interface WakeupListener
Parameters:
selectionRegistration - The selected registration.
Throws:
IOException

register

public SelectionRegistration register(SelectableChannel selectableChannel,
                                      int interestOperations,
                                      SelectionListener listener)
                               throws IOException
Registers a selection listener with the underlying selector for the given operations and returns the registration created.

Parameters:
selectableChannel - The NIO selectable channel.
interestOperations - The initial operations of interest.
listener - The listener to notify.
Returns:
The created registration.
Throws:
IOException

registerKeys

protected void registerKeys()
Registers all the new selection registration requests.


selectKeys

protected void selectKeys(long sleepTime)
                   throws IOException,
                          ClosedByInterruptException
Selects the keys ready for IO operations.

Parameters:
sleepTime - The max sleep time.
Throws:
IOException
ClosedByInterruptException

shutdown

public void shutdown()
Description copied from class: Controller
Abort the controller.

Overrides:
shutdown in class Controller

updateKeys

protected void updateKeys()
                   throws IOException
Updates all the selection registrations for new interest or cancellation.

Throws:
IOException

wakeup

public void wakeup()
Wakes up the controller thread if wait for an NIO selection.



Copyright © 2005-2013 Restlet.