|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectseda.nbio.SelectSet
public class SelectSet
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.
Selectable
,
SelectSetImpl, SelectSetPollImpl, SelectSetDevPollImpl
Constructor Summary | |
---|---|
SelectSet()
Create a SelectSet with no SelectItems. |
Method Summary | |
---|---|
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. |
SelectItem |
elementAt(int index)
Return the SelectItem at the given index. |
SelectItem[] |
getEvents()
Returns an array of SelectItems for which some events have occurred (that is, that the revents field is nonzero). |
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). |
int |
numActive()
Return the number of active SelectItems in this SelectSet. |
void |
remove(int index)
Remove the SelectItem at the given index from 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. |
int |
select(int timeout)
Wait for events to occur on the SelectItems in this SelectSet. |
int |
size()
Return the number of SelectItems in this SelectSet. |
java.lang.String |
toString()
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SelectSet()
Method Detail |
---|
public void add(SelectItem sel)
public void add(SelectItem[] selarr)
public void remove(SelectItem sel)
public void remove(SelectItem[] selarr)
public void remove(int index)
public void update()
public void update(SelectItem sel)
public int size()
public int numActive()
public SelectItem elementAt(int index)
public int select(int timeout)
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.
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.
public SelectItem[] getEvents(short mask)
public SelectItem[] getEvents()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |