org.opennms.netmgt.scheduler
Class LegacyScheduler

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

public class LegacyScheduler
extends Object
implements Runnable, PausableFiber, Scheduler

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 LegacyScheduler.PeekableFifoQueue<T>
          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
 
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
LegacyScheduler(String parent, int maxSize)
          Constructs a new instance of the scheduler.
LegacyScheduler(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
 String getName()
          Returns the name of this fiber.
 RunnableConsumerThreadPool getRunner()
          Returns the pool of threads that are used to executed the runnable instances scheduled by the class' instance.
 int getScheduled()
          Returns total number of elements currently scheduled.
 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
 

Constructor Detail

LegacyScheduler

public LegacyScheduler(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.

LegacyScheduler

public LegacyScheduler(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:
RuntimeException - Thrown if an error occurs adding the element to the queue.

schedule

public void schedule(long interval,
                     ReadyRunnable runnable)
Description copied from interface: Scheduler
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 Scheduler
Specified by:
schedule in interface ScheduleTimer
Parameters:
interval - The queue to add the runnable to.
runnable - The element to run when interval expires.

getCurrentTime

public long getCurrentTime()
Description copied from interface: Scheduler
This returns the current time for the scheduler

Specified by:
getCurrentTime in interface Scheduler
Specified by:
getCurrentTime in interface Timer

start

public void start()
Description copied from interface: Scheduler
Starts the fiber.

Specified by:
start in interface Fiber
Specified by:
start in interface Scheduler

stop

public void stop()
Description copied from interface: Scheduler
Stops the fiber. If the fiber has never been run then an exception is generated.

Specified by:
stop in interface Fiber
Specified by:
stop in interface Scheduler

pause

public void pause()
Description copied from interface: Scheduler
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
Specified by:
pause in interface Scheduler

resume

public void resume()
Description copied from interface: Scheduler
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
Specified by:
resume in interface Scheduler

getStatus

public int getStatus()
Description copied from interface: Scheduler
Returns the current of this fiber.

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

getName

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

Specified by:
getName in interface Fiber

getScheduled

public int getScheduled()
Returns total number of elements currently scheduled.

Returns:
the sum of all the elements in the various queues

getRunner

public RunnableConsumerThreadPool getRunner()
Returns the pool of threads that are used to executed the runnable instances scheduled by the class' instance.

Returns:
thread pool

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 Runnable


Copyright © 2009. All Rights Reserved.