com.threerings.nio
Class SelectorIterable

java.lang.Object
  extended by com.threerings.nio.SelectorIterable
All Implemented Interfaces:
Iterable<SelectionKey>

public class SelectorIterable
extends Object
implements Iterable<SelectionKey>

Exposes selected keys from Selector.selectedKeys() as an Iterable, removing them from the selected set as they're iterated over.


Nested Class Summary
static interface SelectorIterable.SelectFailureHandler
          An interface for hearing about catastrophic selection failure.
 
Field Summary
protected  SelectorIterable.SelectFailureHandler _failureHandler
           
protected  int _runtimeExceptionCount
           
protected  int _selectLoopTime
           
protected  Selector _selector
           
static int MAX_SELECT_FAILURES
          The maximum allowed consecutive select() failures, after which we will declare ourselves irreparably hosed.
 
Constructor Summary
SelectorIterable(Selector selector, int selectLoopTime, SelectorIterable.SelectFailureHandler handler)
          Creates an iterable for the given selector's selectedKeys.
 
Method Summary
 Iterator<SelectionKey> iterator()
           
protected  Set<SelectionKey> select()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_SELECT_FAILURES

public static final int MAX_SELECT_FAILURES
The maximum allowed consecutive select() failures, after which we will declare ourselves irreparably hosed.

See Also:
Constant Field Values

_runtimeExceptionCount

protected int _runtimeExceptionCount

_selectLoopTime

protected final int _selectLoopTime

_selector

protected final Selector _selector

_failureHandler

protected final SelectorIterable.SelectFailureHandler _failureHandler
Constructor Detail

SelectorIterable

public SelectorIterable(Selector selector,
                        int selectLoopTime,
                        SelectorIterable.SelectFailureHandler handler)
Creates an iterable for the given selector's selectedKeys.

Parameters:
selectLoopTime - - the amount of time to wait in select, or 0 to skip the wait at all.
handler - - a callback for the Selector going awol.
Method Detail

iterator

public Iterator<SelectionKey> iterator()
Specified by:
iterator in interface Iterable<SelectionKey>

select

protected Set<SelectionKey> select()