net.jxta.util
Class SimpleSelector
java.lang.Object
net.jxta.util.AbstractSimpleSelectable
net.jxta.util.SimpleSelector
- All Implemented Interfaces:
- SimpleSelectable
- public final class SimpleSelector
- extends AbstractSimpleSelectable
A very primitive version of NIO's select mechanism. Applications should not code to that API yet. This is subject to change
and for use only by internal mechanisms. This is only good at implementing efficient polling. Users must wait for a batch of
state changes and then figure out which item's state changed to something interresting. The batch returned by simpleSelect is
a set of the items which state did change since the previous time select returned. Since a batch is returned as soon as there
is at least one item in it, most batches are very small, they will contain the first item that was added, plus whatever few
could sneak in between then and when select wakes-up and grabs that batch.
Method Summary |
void |
itemChanged(SimpleSelectable item)
This is invoked by registered items when their state changes. |
List |
select()
This blocks unless and until at least one of the selected items reports to have changed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SimpleSelector
public SimpleSelector()
- Let it be newed for now. We need to find a place for a factory.
itemChanged
public final void itemChanged(SimpleSelectable item)
- This is invoked by registered items when their state changes. Records changes for the benefit of
select()
,
and performs notifyChange(), which will cause notification of cascaded selectors, if any. It is thus possible to register
selectors with a selector and come to a particular one only when it has something to report.
- Parameters:
item
- the object that has changed.- See Also:
AbstractSimpleSelectable
select
public List select()
throws InterruptedException
- This blocks unless and until at least one of the selected items reports to have changed. Then the list of such items
is returned. More than one item may be added to the list by the time it is returned to the invoker.
The name is deliberately not "select", so that we easily catch spots where retrofitting is required
when moving to NIO (if ever). Note: the result cannot be a set, otherwise we would be prevented
from returning objects that overload hashCode/equals. It is thus a List. However, an item will never be found twice
in that list.
The invoker should never assume that all items in the result have indeed changed in any expected manner or even
changed at all. The simple action of registering a selector may and usually does cause the selectable object to report
a change. In some cases a selectable object may just be unable to prove that it has not changed, and thus report a
change. It is up to the invoker to inspect the relevant item's state every time.
- Throws:
InterruptedException