Driver.Factory| Modifier and Type | Field and Description |
|---|---|
private java.util.Collection<Connector> |
_connectors |
private java.util.Collection<Listener> |
_listeners |
private java.util.logging.Logger |
_logger |
private java.util.Queue<ConnectorImpl> |
_selectedConnectors |
private java.util.Queue<ListenerImpl> |
_selectedListeners |
private java.nio.channels.Selector |
_selector |
private java.lang.Object |
_wakeupLock |
private boolean |
_woken |
| Constructor and Description |
|---|
DriverImpl() |
| Modifier and Type | Method and Description |
|---|---|
Connector |
connector()
Get the next active connector in the driver.
|
java.lang.Iterable<Connector> |
connectors()
Return an iterator over all connectors.
|
<C> Connector<C> |
createConnector(java.nio.channels.SelectableChannel c,
C context)
Create a connector using the existing file descriptor.
|
<C> Connector<C> |
createConnector(java.lang.String host,
int port,
C context)
Construct a connector to the given remote address.
|
<C> Listener<C> |
createListener(java.nio.channels.ServerSocketChannel c,
C context)
Create a listener using the existing channel.
|
<C> Listener<C> |
createListener(java.lang.String host,
int port,
C context)
Construct a listener for the given address.
|
protected <C> Connector<C> |
createServerConnector(java.nio.channels.SelectableChannel c,
C context,
Listener<C> l) |
void |
destroy()
Destruct the driver and all associated listeners, connectors and other resources.
|
boolean |
doWait(long timeout)
Wait for an active connector or listener, or for
Driver.wakeup() to be called. |
Listener |
listener()
Get the next listener with pending data in the driver.
|
java.lang.Iterable<Listener> |
listeners()
Return an iterator over all listeners.
|
private <C> java.nio.channels.SelectionKey |
registerInterest(java.nio.channels.SelectableChannel c,
int opKeys) |
<C> void |
removeConnector(Connector<C> c) |
(package private) void |
selectConnector(ConnectorImpl c) |
(package private) void |
selectListener(ListenerImpl l) |
void |
wakeup()
Force
Driver.doWait(long) to return. |
private java.nio.channels.Selector _selector
private java.util.Collection<Listener> _listeners
private java.util.Collection<Connector> _connectors
private java.util.logging.Logger _logger
private java.lang.Object _wakeupLock
private boolean _woken
private java.util.Queue<ConnectorImpl> _selectedConnectors
private java.util.Queue<ListenerImpl> _selectedListeners
public DriverImpl()
throws java.io.IOException
java.io.IOExceptionpublic void wakeup()
DriverDriver.doWait(long) to return.
If the driver is not currently waiting then the next invocation of Driver.doWait(long)
will return immediately unless the Driver.connector() method is invoked in the meantime.
Thread-safe.public boolean doWait(long timeout)
DriverDriver.wakeup() to be called.
Thread-safe.void selectListener(ListenerImpl l)
public Listener listener()
Drivervoid selectConnector(ConnectorImpl c)
public Connector connector()
DriverDriver.wakeup().public void destroy()
Driverpublic <C> Listener<C> createListener(java.lang.String host, int port, C context)
DrivercreateListener in interface Driverhost - local host address to listen onport - local port to listen oncontext - application-supplied, can be accessed via
getContext() method on a listener.public <C> Listener<C> createListener(java.nio.channels.ServerSocketChannel c, C context)
DrivercreateListener in interface Driverc - existing SocketChannel for listener to listen oncontext - application-supplied, can be accessed via
getContext() method on a listener.public <C> Connector<C> createConnector(java.lang.String host, int port, C context)
DrivercreateConnector in interface Driverhost - remote host to connect to.port - remote port to connect to.context - application-supplied, can be accessed via
getContext() method on a listener.public <C> Connector<C> createConnector(java.nio.channels.SelectableChannel c, C context)
DrivercreateConnector in interface Driverc - existing SocketChannel for listener to listen oncontext - application-supplied, can be accessed via
getContext() method on a listener.public <C> void removeConnector(Connector<C> c)
public java.lang.Iterable<Listener> listeners()
Driverpublic java.lang.Iterable<Connector> connectors()
Driverconnectors in interface Driverprotected <C> Connector<C> createServerConnector(java.nio.channels.SelectableChannel c, C context, Listener<C> l)
private <C> java.nio.channels.SelectionKey registerInterest(java.nio.channels.SelectableChannel c,
int opKeys)