OpenNMS API 1.2.3

org.opennms.netmgt.scheduler
Class Scheduler

java.lang.Object
  extended byorg.opennms.netmgt.scheduler.Scheduler
All Implemented Interfaces:
Fiber, PausableFiber, java.lang.Runnable, ScheduleTimer, Timer

public class Scheduler
extends java.lang.Object
implements java.lang.Runnable, PausableFiber, ScheduleTimer

This class implements a simple scheduler to ensure the polling occurs at the expected intervals. The scheduler employees a dynamic thread pool that adjust to the load until a maximum thread count is reached.

Author:
Mike Davidson , Brian Weaver , OpenNMS

Nested Class Summary
static class Scheduler.PeekableFifoQueue
          This queue extends the standard FIFO queue instance so that it is possible to peek at an instance without removing it from the queue.
 
Field Summary
private  java.lang.String m_name
          The name of this fiber.
 java.util.Map m_queues
          The map of queue that contain ready runnable instances.
 RunnableConsumerThreadPool m_runner
          The pool of threads that are used to executed the runnable instances scheduled by the class' instance.
 int m_scheduled
          The total number of elements currently scheduled.
 int m_status
          The status for this fiber.
private  java.lang.Thread m_worker
          The worker thread that executes this instance.
 
Fields inherited from interface org.opennms.core.fiber.PausableFiber
PAUSE_PENDING, PAUSED, RESUME_PENDING
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
Scheduler(java.lang.String parent, int maxSize)
          Constructs a new instance of the scheduler.
Scheduler(java.lang.String parent, int maxSize, float lowMark, float hiMark)
          Constructs a new instance of the scheduler.
 
Method Summary
 long getCurrentTime()
          This returns the current time for the scheduler
 java.lang.String getName()
          Returns the name of this fiber.
 int getStatus()
          Returns the current of this fiber.
 void pause()
          Pauses the scheduler if it is current running.
 void resume()
          Resumes the scheduler if it has been paused.
 void run()
          The main method of the scheduler.
 void schedule(long interval, ReadyRunnable runnable)
          This method is used to schedule a ready runnable in the system.
 void schedule(ReadyRunnable runnable, long interval)
          This method is used to schedule a ready runnable in the system.
 void start()
          Starts the fiber.
 void stop()
          Stops the fiber.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_queues

public java.util.Map m_queues
The map of queue that contain ready runnable instances. The queues are mapped according to the interval of scheduling.


m_scheduled

public int m_scheduled
The total number of elements currently scheduled. This should be the sum of all the elements in the various queues.


m_runner

public RunnableConsumerThreadPool m_runner
The pool of threads that are used to executed the runnable instances scheduled by the class' instance.


m_name

private java.lang.String m_name
The name of this fiber.


m_status

public int m_status
The status for this fiber.


m_worker

private java.lang.Thread m_worker
The worker thread that executes this instance.

Constructor Detail

Scheduler

public Scheduler(java.lang.String parent,
                 int maxSize)
Constructs a new instance of the scheduler. The maximum number of executable threads is specified in the constructor. The executable threads are part of a runnable thread pool where the scheduled runnables are executed.

Parameters:
parent - String prepended to "Scheduler" to create fiber name
maxSize - The maximum size of the thread pool.

Scheduler

public Scheduler(java.lang.String parent,
                 int maxSize,
                 float lowMark,
                 float hiMark)
Constructs a new instance of the scheduler. The maximum number of executable threads is specified in the constructor. The executable threads are part of a runnable thread pool where the scheduled runnables are executed.

Parameters:
parent - String prepended to "Scheduler" to create fiber name
maxSize - The maximum size of the thread pool.
lowMark - The low water mark ratios of thread size to threads when threads are stopped.
hiMark - The high water mark ratio of thread size to threads when threads are started.
Method Detail

schedule

public void schedule(ReadyRunnable runnable,
                     long interval)
This method is used to schedule a ready runnable in the system. The interval is used as the key for determining which queue to add the runnable.

Parameters:
runnable - The element to run when interval expires.
interval - The queue to add the runnable to.
Throws:
java.lang.RuntimeException - Thrown if an error occurs adding the element to the queue.

schedule

public void schedule(long interval,
                     ReadyRunnable runnable)
This method is used to schedule a ready runnable in the system. The interval is used as the key for determining which queue to add the runnable.

Specified by:
schedule in interface ScheduleTimer
Parameters:
interval - The queue to add the runnable to.
runnable - The element to run when interval expires.
Throws:
java.lang.RuntimeException - Thrown if an error occurs adding the element to the queue.

getCurrentTime

public long getCurrentTime()
This returns the current time for the scheduler

Specified by:
getCurrentTime in interface Timer

start

public void start()
Starts the fiber.

Specified by:
start in interface Fiber
Throws:
java.lang.IllegalStateException - Thrown if the fiber is already running.

stop

public void stop()
Stops the fiber. If the fiber has never been run then an exception is generated.

Specified by:
stop in interface Fiber
Throws:
java.lang.IllegalStateException - Throws if the fiber has never been started.

pause

public void pause()
Pauses the scheduler if it is current running. If the fiber has not been run or has already stopped then an exception is generated.

Specified by:
pause in interface PausableFiber
Throws:
java.lang.IllegalStateException - Throws if the operation could not be completed due to the fiber's state.

resume

public void resume()
Resumes the scheduler if it has been paused. If the fiber has not been run or has already stopped then an exception is generated.

Specified by:
resume in interface PausableFiber
Throws:
java.lang.IllegalStateException - Throws if the operation could not be completed due to the fiber's state.

getStatus

public int getStatus()
Returns the current of this fiber.

Specified by:
getStatus in interface Fiber
Returns:
The current status.

getName

public java.lang.String getName()
Returns the name of this fiber.

Specified by:
getName in interface Fiber
Returns:
The name of the Fiber.

run

public void run()
The main method of the scheduler. This method is responsible for checking the runnable queues for ready objects and then enqueuing them into the thread pool for execution.

Specified by:
run in interface java.lang.Runnable

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.