|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread rice.selector.SelectorManager
public class SelectorManager
This class is the class which handles the selector, and listens for activity. When activity occurs, it figures out who is interested in what has happened, and hands off to that object.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected java.util.HashSet |
cancelledKeys
|
protected java.lang.String |
instance
|
protected java.util.LinkedList |
invocations
|
protected Logger |
logger
|
protected java.util.HashSet |
modifyKeys
|
protected boolean |
running
|
protected boolean |
select
Can be disabled for the simulator to improve performance, only do this if you know you don't need to select on anything |
protected java.nio.channels.Selector |
selector
|
static int |
TIMEOUT
|
protected java.util.Queue |
timerQueue
|
protected TimeSource |
timeSource
|
protected boolean |
useLoopListeners
LoopListeners is used in case you are worried that your process may not get scheduled for a while such as on an overloaded planetlab node, or if you hibernate your laptop, this is not needed for the simulator |
protected long |
wakeupTime
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
SelectorManager(java.lang.String instance,
TimeSource timeSource,
LogManager log)
Constructor, which is private since there is only one selector per JVM. |
Method Summary | |
---|---|
void |
addLoopObserver(LoopObserver lo)
|
void |
cancel(java.nio.channels.SelectionKey key)
Method which asks the Selector Manager to add the given key to the cancelled set. |
void |
destroy()
|
protected void |
doInvocations()
Method which invokes all pending invocations. |
protected void |
doSelections()
|
protected void |
executeDueTasks()
Internal method which finds all due tasks and executes them. |
protected java.lang.Runnable |
getInvocation()
Method which synchroniously returns the first element off of the invocations list. |
java.nio.channels.SelectionKey |
getKey(java.nio.channels.SelectableChannel channel)
Utility method which returns the SelectionKey attached to the given channel, if one exists |
protected java.nio.channels.SelectionKey |
getModifyKey()
Method which synchroniously returns on element off of the modifyKeys list |
long |
getNextTaskExecutionTime()
|
int |
getNumInvocations()
Debug method which returns the number of pending invocations |
java.nio.channels.Selector |
getSelector()
|
Timer |
getTimer()
Returns the timer associated with this SelectorManager (in this case, it is this). |
void |
invoke(java.lang.Runnable d)
This method schedules a runnable task to be done by the selector thread during the next select() call. |
boolean |
isSelectorThread()
Returns whether or not this thread of execution is the selector thread |
void |
modifyKey(java.nio.channels.SelectionKey key)
Adds a selectionkey handler into the list of handlers which wish to change their keys. |
protected void |
notifyLoopListeners()
|
protected void |
onLoop()
This method is to be implemented by a subclass to do some task each loop. |
java.nio.channels.SelectionKey |
register(java.nio.channels.SelectableChannel channel,
SelectionKeyHandler handler,
int ops)
Registers a new channel with the selector, and attaches the given SelectionKeyHandler as the handler for the newly created key. |
void |
removeLoopObserver(LoopObserver lo)
|
void |
run()
This method starts the socket manager listening for events. |
void |
schedule(TimerTask task)
Method which schedules a task to run after a specified number of millis. |
void |
schedule(TimerTask task,
long delay)
|
void |
schedule(TimerTask task,
long delay,
long period)
Method which schedules a task to run repeatedly after a specified delay and period |
void |
scheduleAtFixedRate(TimerTask task,
long delay,
long period)
Method which schedules a task to run repeatedly (at a fixed rate) after a specified delay and period |
protected java.nio.channels.SelectionKey[] |
selectedKeys()
Selects all of the currenlty selected keys on the selector and returns the result as an array of keys. |
void |
setEnvironment(Environment env)
Can only be called once. |
void |
setSelect(boolean b)
|
void |
useLoopListeners(boolean val)
Set this to false when using the simulator, because you don't need to notify loop observers. |
void |
wakeup()
Note, should hold the selector's (this) lock to call this. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static int TIMEOUT
protected java.nio.channels.Selector selector
protected java.util.LinkedList invocations
protected java.util.HashSet modifyKeys
protected java.util.HashSet cancelledKeys
protected java.util.Queue timerQueue
protected long wakeupTime
protected TimeSource timeSource
protected Logger logger
protected java.lang.String instance
protected boolean running
protected boolean select
protected boolean useLoopListeners
Constructor Detail |
---|
public SelectorManager(java.lang.String instance, TimeSource timeSource, LogManager log)
Method Detail |
---|
public void setEnvironment(Environment env)
env
- public void cancel(java.nio.channels.SelectionKey key)
key
- The key to cancelpublic java.nio.channels.SelectionKey getKey(java.nio.channels.SelectableChannel channel)
channel
- The channel to return the key for
public java.nio.channels.SelectionKey register(java.nio.channels.SelectableChannel channel, SelectionKeyHandler handler, int ops) throws java.io.IOException
channel
- The channel to regster with the selectorhandler
- The handler to use for the callbacksops
- The initial interest operations
java.io.IOException
public void invoke(java.lang.Runnable d)
d
- The runnable task to invokepublic int getNumInvocations()
public void modifyKey(java.nio.channels.SelectionKey key)
key
- The key which is to be chanegdprotected void onLoop()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void destroy()
destroy
in interface Destructable
destroy
in class java.lang.Thread
public void useLoopListeners(boolean val)
val
- protected void notifyLoopListeners()
public void addLoopObserver(LoopObserver lo)
public void removeLoopObserver(LoopObserver lo)
protected void doSelections() throws java.io.IOException
java.io.IOException
protected void doInvocations()
protected java.lang.Runnable getInvocation()
protected java.nio.channels.SelectionKey getModifyKey()
protected java.nio.channels.SelectionKey[] selectedKeys() throws java.io.IOException
java.io.IOException
- DESCRIBE THE EXCEPTIONpublic boolean isSelectorThread()
public void schedule(TimerTask task)
schedule
in interface Timer
task
- The task to runpublic void schedule(TimerTask task, long delay)
schedule
in interface Timer
public void schedule(TimerTask task, long delay, long period)
schedule
in interface Timer
task
- The task to rundelay
- The delay before first running, in millisecondsperiod
- The period with which to run in millisecondspublic void scheduleAtFixedRate(TimerTask task, long delay, long period)
scheduleAtFixedRate
in interface Timer
task
- The task to rundelay
- The delay before first running in millisecondsperiod
- The period with which to run in millisecondspublic void wakeup()
public long getNextTaskExecutionTime()
protected void executeDueTasks()
public Timer getTimer()
public java.nio.channels.Selector getSelector()
public void setSelect(boolean b)
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |