Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.selector
Class SelectorManager

    java.lang.Object
      java.lang.Thread
          rice.selector.SelectorManager

All Implemented Interfaces:
  java.lang.Runnable, Timer

Direct Known Subclasses:
  ProfileSelector

public class SelectorManager
extends java.lang.Thread
implements Timer

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.

Version:
  $Id: SelectorManager.java,v 1.24 2005/03/11 00:58:14 jeffh Exp $
Author:
  Alan Mislove

Field Summary
`protected java.util.HashSet` | `cancelledKeys` DESCRIBE THE FIELD
`protected java.util.LinkedList` | `invocations` DESCRIBE THE FIELD
`protected java.util.HashSet` | `modifyKeys` DESCRIBE THE FIELD
`protected java.nio.channels.Selector` | `selector` DESCRIBE THE FIELD
`static int` | `TIMEOUT` DESCRIBE THE FIELD
`protected java.util.TreeSet` | `timerQueue` DESCRIBE THE FIELD
`protected long` | `wakeupTime` DESCRIBE THE FIELD

Fields inherited from class java.lang.Thread
`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

Constructor Summary
`protected` | `SelectorManager(boolean profile)` Constructor, which is private since there is only one selector per JVM.

Method Summary
`void` | `cancel(java.nio.channels.SelectionKey key)` Method which asks the Selector Manager to add the given key to the cancelled set.
`protected void` | `doInvocations()` Method which invokes all pending invocations.
`protected void` | `doSelections()` DESCRIBE THE METHOD
`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
`int` | `getNumInvocations()` Debug method which returns the number of pending invocations
`static SelectorManager` | `getSelectorManager()` Returns the SelectorManager applications should use.
`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.
`static 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` | `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` | `run()` This method starts the socket manager listening for events.
`void` | `schedule(TimerTask task, java.util.Date time)` Method which schedules a task to run at a specified time
`void` | `schedule(TimerTask task, java.util.Date firstTime, long period)` Method which schedules a task to run repeatedly first at a specified time and period
`void` | `schedule(TimerTask task, long delay)` Method which schedules a task to run after a specified number of millis
`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, java.util.Date firstTime, long period)` Method which schedules a task to run repeatedly (at a fixed rate) 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.

Methods inherited from class java.lang.Thread
`activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

### selector

    protected java.nio.channels.Selector selector

  DESCRIBE THE FIELD

### invocations

    protected java.util.LinkedList invocations

  DESCRIBE THE FIELD

### modifyKeys

    protected java.util.HashSet modifyKeys

  DESCRIBE THE FIELD

### cancelledKeys

    protected java.util.HashSet cancelledKeys

  DESCRIBE THE FIELD

### timerQueue

    protected java.util.TreeSet timerQueue

  DESCRIBE THE FIELD

### wakeupTime

    protected long wakeupTime

  DESCRIBE THE FIELD

### TIMEOUT

    public static int TIMEOUT

  DESCRIBE THE FIELD

Constructor Detail

### SelectorManager

    protected SelectorManager(boolean profile)

  Constructor, which is private since there is only one selector per JVM.

Parameters:
  `profile` - DESCRIBE THE PARAMETER

Method Detail

### getKey

    public java.nio.channels.SelectionKey getKey(java.nio.channels.SelectableChannel channel)

  Utility method which returns the SelectionKey attached to the given channel, if one exists

  Parameters:
    `channel` - The channel to return the key for
  Returns:
    The key

### getNumInvocations

    public int getNumInvocations()

  Debug method which returns the number of pending invocations

  Returns:
    The number of pending invocations

### getInvocation

    protected java.lang.Runnable getInvocation()

  Method which synchroniously returns the first element off of the invocations list.

  Returns:
    An item from the invocations list

### getModifyKey

    protected java.nio.channels.SelectionKey getModifyKey()

  Method which synchroniously returns on element off of the modifyKeys list

  Returns:
    An item from the invocations list

### getTimer

    public Timer getTimer()

  Returns the timer associated with this SelectorManager (in this case, it is this).

  Returns:
    The associated timer

### cancel

    public void cancel(java.nio.channels.SelectionKey key)

  Method which asks the Selector Manager to add the given key to the cancelled set. If noone calls register on this key during the rest of this select() operation, the key will be cancelled. Otherwise, it will be returned as a result of the register operation.

  Parameters:
    `key` - The key to cancel

### register

    public java.nio.channels.SelectionKey register(java.nio.channels.SelectableChannel channel,
                                                   SelectionKeyHandler handler,
                                                   int ops)
                                            throws java.io.IOException

  Registers a new channel with the selector, and attaches the given SelectionKeyHandler as the handler for the newly created key. Operations which the hanlder is interested in will be called as available.

  Parameters:
    `channel` - The channel to regster with the selector
    `handler` - The handler to use for the callbacks
    `ops` - The initial interest operations
  Returns:
    The SelectionKey which uniquely identifies this channel
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### invoke

    public void invoke(java.lang.Runnable d)

  This method schedules a runnable task to be done by the selector thread during the next select() call. All operations which modify the selector should be done using this method, as they must be done in the selector thread.

  Parameters:
    `d` - The runnable task to invoke

### modifyKey

    public void modifyKey(java.nio.channels.SelectionKey key)

  Adds a selectionkey handler into the list of handlers which wish to change their keys. Thus, modifyKeys() will be called on the next selection operation

  Parameters:
    `key` - The key which is to be chanegd

### onLoop

    protected void onLoop()

  This method is to be implemented by a subclass to do some task each loop.

### run

    public void run()

  This method starts the socket manager listening for events. It is designed to be started when this thread's start() method is invoked.

  Specified by:
    `run` in interface `java.lang.Runnable`

### doSelections

    protected void doSelections()
                         throws java.io.IOException

  DESCRIBE THE METHOD

  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### doInvocations

    protected void doInvocations()

  Method which invokes all pending invocations. This method should *only* be called by the selector thread.

### selectedKeys

    protected java.nio.channels.SelectionKey[] selectedKeys()
                                                     throws java.io.IOException

  Selects all of the currenlty selected keys on the selector and returns the result as an array of keys.

  Returns:
    The array of keys
  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### schedule

    public void schedule(TimerTask task,
                         long delay)

  Method which schedules a task to run after a specified number of millis

  Specified by:
    `schedule` in interface `Timer`
  Parameters:
    `task` - The task to run
    `delay` - The delay

### schedule

    public void schedule(TimerTask task,
                         java.util.Date time)

  Method which schedules a task to run at a specified time

  Parameters:
    `task` - The task to run
    `time` - The time to run

### schedule

    public void schedule(TimerTask task,
                         long delay,
                         long period)

  Method which schedules a task to run repeatedly after a specified delay and period

  Specified by:
    `schedule` in interface `Timer`
  Parameters:
    `task` - The task to run
    `delay` - The delay
    `period` - The period with which to run

### schedule

    public void schedule(TimerTask task,
                         java.util.Date firstTime,
                         long period)

  Method which schedules a task to run repeatedly first at a specified time and period

  Parameters:
    `task` - The task to run
    `firstTime` - The first time
    `period` - The period with which to run

### scheduleAtFixedRate

    public 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

  Specified by:
    `scheduleAtFixedRate` in interface `Timer`
  Parameters:
    `task` - The task to run
    `delay` - The delay
    `period` - The period with which to run

### scheduleAtFixedRate

    public void scheduleAtFixedRate(TimerTask task,
                                    java.util.Date firstTime,
                                    long period)

  Method which schedules a task to run repeatedly (at a fixed rate) after a specified delay and period

  Parameters:
    `task` - The task to run
    `period` - The period with which to run
    `firstTime` - DESCRIBE THE PARAMETER

### executeDueTasks

    protected void executeDueTasks()

  Internal method which finds all due tasks and executes them.

### getSelectorManager

    public static SelectorManager getSelectorManager()

  Returns the SelectorManager applications should use.

  Returns:
    The SelectorManager which applications should use

### isSelectorThread

    public static boolean isSelectorThread()

  Returns whether or not this thread of execution is the selector thread

  Returns:
    Whether or not this is the selector thread

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.