async
Interface ASyncService


public interface ASyncService

An interface to be implemented by services that perform I/O through an ASync instance.

Author:
Michael Parker

Method Summary
 void eventHappens(ASyncServiceEvent event, long curr_time)
          This method is invoked if the time the given ASyncServiceEvent was scheduled to execute at has passed.
 ASyncServiceKey getKey()
          Returns the ASyncServiceKey object that identifies this service.
 void keyAcceptable(java.nio.channels.SelectionKey sk, java.nio.channels.SelectableChannel sc, long curr_time)
          This method is invoked by the ASync instance when a channel registered by this service is acceptable.
 void keyConnectable(java.nio.channels.SelectionKey sk, java.nio.channels.SelectableChannel sc, long curr_time)
          This method is invoked by the ASync instance when a channel registered by this service is connectable.
 void keyReadable(java.nio.channels.SelectionKey sk, java.nio.channels.SelectableChannel sc, long curr_time)
          This method is invoked by the ASync instance when a channel registered by this service is readable.
 void keyWritable(java.nio.channels.SelectionKey sk, java.nio.channels.SelectableChannel sc, long curr_time)
          This method is invoked by the ASync instance when a channel registered by this service is writable.
 boolean nowRunning(ASyncProvider provider)
          This method is invoked when an ASync instance this service is registered with starts running.
 void nowStopped()
          This method is invoked when the provider with which this service is registered and active stops.
 

Method Detail

getKey

ASyncServiceKey getKey()
Returns the ASyncServiceKey object that identifies this service.

Returns:
the key for this service

nowRunning

boolean nowRunning(ASyncProvider provider)
This method is invoked when an ASync instance this service is registered with starts running. The interface through which this service can interact with the ASync instance is exported through the given ASyncProvider argument. Note that, while a service may be registered with multiple ASync instances, it should only use one instance at a time. If this service is not used by any instance when this method is invoked, it can commit to using the provider by returning true from this method. Otherwise, it can return false, and this service will be registered but inactive with the ASync instance.

Parameters:
provider - the ASync instance that has now started
Returns:
true if this service can participate with the provider, false otherwise

nowStopped

void nowStopped()
This method is invoked when the provider with which this service is registered and active stops. This means that all of its SelectableChannel objects are no longer registered, their respective keys are invalid, and all unexpired timers have been removed. The internal state of this service should be reset, allowing it to use another provider later once its nowRunning method is invoked again.


eventHappens

void eventHappens(ASyncServiceEvent event,
                  long curr_time)
This method is invoked if the time the given ASyncServiceEvent was scheduled to execute at has passed.

Parameters:
event - the event that was scheduled
curr_time - the current time, as last returned by System.currentTimeMillis()

keyReadable

void keyReadable(java.nio.channels.SelectionKey sk,
                 java.nio.channels.SelectableChannel sc,
                 long curr_time)
This method is invoked by the ASync instance when a channel registered by this service is readable. This means that the service has set interest bit SelectionKey.OP_READ via its associated SelectionKey, and the channel has been selected under this condition.

Parameters:
sk - the key belonging to the registered SelectableChannel object
sc - the SelectableChannel object that is now readable
curr_time - the current time, as last returned by System.currentTimeMillis()

keyWritable

void keyWritable(java.nio.channels.SelectionKey sk,
                 java.nio.channels.SelectableChannel sc,
                 long curr_time)
This method is invoked by the ASync instance when a channel registered by this service is writable. This means that the service has set interest bit SelectionKey.OP_WRITE via its associated SelectionKey, and the channel has been selected under this condition.

Parameters:
sk - the key belonging to the registered SelectableChannel object
sc - the SelectableChannel object that is now writable
curr_time - the current time, as last returned by System.currentTimeMillis()

keyConnectable

void keyConnectable(java.nio.channels.SelectionKey sk,
                    java.nio.channels.SelectableChannel sc,
                    long curr_time)
This method is invoked by the ASync instance when a channel registered by this service is connectable. This means that the service has set interest bit SelectionKey.OP_CONNECT via its associated SelectionKey, and the channel has been selected under this condition.

Parameters:
sk - the key belonging to the registered SelectableChannel object
sc - the SelectableChannel object that is now connectable
curr_time - the current time, as last returned by System.currentTimeMillis()

keyAcceptable

void keyAcceptable(java.nio.channels.SelectionKey sk,
                   java.nio.channels.SelectableChannel sc,
                   long curr_time)
This method is invoked by the ASync instance when a channel registered by this service is acceptable. This means that the service has set interest bit SelectionKey.OP_ACCEPT via its associated SelectionKey, and the channel has been selected under this condition.

Parameters:
sk - the key belonging to the registered SelectableChannel object
sc - the SelectableChannel object that is now acceptable
curr_time - the current time, as last returned by System.currentTimeMillis()