seda.nbio.SelectSet Class Reference

List of all members.

Detailed Description

A SelectSet represents a set of SelectItems which you wish to poll or wait for events to occur on.

The interface is very much like the poll(2) system call in SVR4.

To poll for events across many sockets or file descriptors, create a SelectSet and initialize it with one or more SelectItems. The 'events' field of each SelectItem should be set to the mask of event types you wish to receive. The event types are specified by the constants in the Selectable class.

Calling the select method (with an optional timeout) checks each of the file descriptors in the SelectSet for events, and sets the 'revents' field of each SelectItem accordingly. The getEvents method is provided for convenience; it returns an array of SelectItems for which some event occurred.

Multiple implementations of SelectSet may be available on a given system. The particular implementation used is determined on the features of the underlying OS, but the default choice can be overridden by setting the nbio.SelectSetImpl runtime property. See the subclasses of SelectSetImpl for details.

Author:
Matt Welsh (mdw@cs.berkeley.edu)
See also:
Selectable

SelectSetImpl, SelectSetPollImpl, SelectSetDevPollImpl


Public Member Functions

 SelectSet ()
 Create a SelectSet with no SelectItems.
void add (SelectItem sel)
 Add a SelectItem to this SelectSet.
void add (SelectItem selarr[])
 Add all of the SelectItems in the given array to the SelectSet.
void remove (SelectItem sel)
 Remove a SelectItem from the SelectSet.
void remove (SelectItem selarr[])
 Remove all of the SelectItems in the given array from the SelectSet.
void remove (int index)
 Remove the SelectItem at the given index from the SelectSet.
void update ()
 Update any changed 'events' fields in SelectItems registered with this SelectSet.
void update (SelectItem sel)
 Update any changed 'events' fields in the given SelectItem.
int size ()
 Return the number of SelectItems in this SelectSet.
int numActive ()
 Return the number of active SelectItems in this SelectSet.
SelectItem elementAt (int index)
 Return the SelectItem at the given index.
int select (int timeout)
 Wait for events to occur on the SelectItems in this SelectSet.
SelectItem[] getEvents (short mask)
 Returns an array of SelectItems for which events matching the given event mask have occurred (that is, that the revents field matches the given mask).
SelectItem[] getEvents ()
 Returns an array of SelectItems for which some events have occurred (that is, that the revents field is nonzero).
String toString ()

Static Package Functions

 [static initializer]

Private Attributes

SelectSetImpl impl

Static Private Attributes

static final boolean DEBUG = false
static final int POLL_IMPL = 0
static final int DEVPOLL_IMPL = 1
static int IMPL_TO_USE


Constructor & Destructor Documentation

seda.nbio.SelectSet.SelectSet  ) 
 

Create a SelectSet with no SelectItems.


Member Function Documentation

seda.nbio.SelectSet.[static initializer]  )  [static, package]
 

void seda.nbio.SelectSet.add SelectItem  selarr[]  ) 
 

Add all of the SelectItems in the given array to the SelectSet.

void seda.nbio.SelectSet.add SelectItem  sel  ) 
 

Add a SelectItem to this SelectSet.

SelectItem seda.nbio.SelectSet.elementAt int  index  ) 
 

Return the SelectItem at the given index.

SelectItem [] seda.nbio.SelectSet.getEvents  ) 
 

Returns an array of SelectItems for which some events have occurred (that is, that the revents field is nonzero).

This is a convenience method and is not meant to be optimized; since it scans the SelectItem array and creates a new reference array, it imposes higher overhead than the application scanning the SelectItem array directly, using the size() and elementAt() methods.

SelectItem [] seda.nbio.SelectSet.getEvents short  mask  ) 
 

Returns an array of SelectItems for which events matching the given event mask have occurred (that is, that the revents field matches the given mask).

This is a convenience method and is not meant to be optimized; since it scans the SelectItem array and creates a new reference array, it imposes higher overhead than the application scanning the SelectItem array directly, using the size() and elementAt() methods.

int seda.nbio.SelectSet.numActive  ) 
 

Return the number of active SelectItems in this SelectSet.

An active SelectItem is defined as one with a non-zero events request mask.

void seda.nbio.SelectSet.remove int  index  ) 
 

Remove the SelectItem at the given index from the SelectSet.

void seda.nbio.SelectSet.remove SelectItem  selarr[]  ) 
 

Remove all of the SelectItems in the given array from the SelectSet.

void seda.nbio.SelectSet.remove SelectItem  sel  ) 
 

Remove a SelectItem from the SelectSet.

int seda.nbio.SelectSet.select int  timeout  ) 
 

Wait for events to occur on the SelectItems in this SelectSet.

Upon return, the 'revents' field of each SelectItem will be set to the mask of events that occurred. Note that this method does not set revents to 0 when called; after processing an event, it is the application's responsibility to clear the revents field. This is intentional: if the application wishes to delay the processing of an event, it can leave the revents field as-is so that subsequent calls to select will continue to indicate that the event is pending.

IMPORTANT NOTE: If timeout is non-zero, this call will block the thread which invokes it. If you are using Green Threads, this will block the entire JVM. Unless you have a single-threaded application, you should only use SelectSet.select() with native threads.

Parameters:
timeout The maximum number of milliseconds to block waiting for an event to occur. A timeout of 0 means than select should not block; a timeout of -1 means that select should block indefinitely.
Returns:
The number of events received, or 0 if no events occurred.

int seda.nbio.SelectSet.size  ) 
 

Return the number of SelectItems in this SelectSet.

String seda.nbio.SelectSet.toString  ) 
 

void seda.nbio.SelectSet.update SelectItem  sel  ) 
 

Update any changed 'events' fields in the given SelectItem.

This method should be called if a SelectItem 'events' field is modified after adding it to this SelectSet.

void seda.nbio.SelectSet.update  ) 
 

Update any changed 'events' fields in SelectItems registered with this SelectSet.

This method should be called if a SelectItem 'events' field is modified after adding it to this SelectSet.


Member Data Documentation

final boolean seda.nbio.SelectSet.DEBUG = false [static, private]
 

final int seda.nbio.SelectSet.DEVPOLL_IMPL = 1 [static, private]
 

SelectSetImpl seda.nbio.SelectSet.impl [private]
 

int seda.nbio.SelectSet.IMPL_TO_USE [static, private]
 

final int seda.nbio.SelectSet.POLL_IMPL = 0 [static, private]
 


The documentation for this class was generated from the following file:
Generated on Wed Jun 21 12:23:44 2006 for libnbio2-java by  doxygen 1.4.6