OpenNMS API 1.1.4

org.opennms.netmgt.poller
Class PollableServiceProxy

java.lang.Object
  extended byorg.opennms.netmgt.poller.PollableServiceProxy
All Implemented Interfaces:
ReadyRunnable, java.lang.Runnable

final class PollableServiceProxy
extends java.lang.Object
implements ReadyRunnable

A proxy to a PollableService which acts as a surrogate for rescheduling purposes. This was created as a temporary fix to allow us to schedule a PollableService for a sooner execution, despite the fact that it is already scheduled for a later time. At the time we created this class, the Scheduler did not provide any means to cancel or reschedule an element on its queue. Therefore, this workaround became necessary.

In order to use this class, create an instance of it with the desired PollableService and the timestamp at which you want it to run. Once you have the instance, you can schedule it with the Scheduler, since it is of type ReadyRunnable.

Each time it runs, it will reschedule itself at the interval currently valid for the PollableService it contains. Once it catches up to the originally scheduled time for its PollableService, it will politely quit rescheduling itself. Assuming that the scheduler was the only object that was keeping a reference to this proxy, it should be noticed by the garbage collector next time runs.

Author:
Justis Peters, OpenNMS
See Also:
PollableService, Scheduler

Field Summary
private  long _scheduledRuntime
          the time (in milliseconds) after which this proxy is supposed to run
private  PollableService _service
          interface that this service belongs to
 
Constructor Summary
(package private) PollableServiceProxy(PollableService psvc, long runAt)
          Constructs a new instance of a proxy object that proxies for the specified pollable service.
 
Method Summary
private  long getScheduledRuntime()
          Returns the time (in milliseconds) at which this Proxy is scheduled to run.
 boolean isReady()
          Returns true if this proxy wants to be run.
 void run()
          This is the main method of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_service

private PollableService _service
interface that this service belongs to


_scheduledRuntime

private long _scheduledRuntime
the time (in milliseconds) after which this proxy is supposed to run

Constructor Detail

PollableServiceProxy

PollableServiceProxy(PollableService psvc,
                     long runAt)
Constructs a new instance of a proxy object that proxies for the specified pollable service.

Parameters:
psvc - The PollableService to be proxied.
runAt - The timestamp after which this proxy should run.
Method Detail

isReady

public boolean isReady()
Returns true if this proxy wants to be run.

Specified by:
isReady in interface ReadyRunnable

run

public void run()

This is the main method of the class.

It passes a run() call through to the PollableService that it proxies, and then makes a rescheduling decision on its behalf. If it encounters an inability to finish processing on run() (such as a node lock unavailable or an interrupted thread) it will reschedule itself to retry at 10 seconds.

Specified by:
run in interface java.lang.Runnable

getScheduledRuntime

private long getScheduledRuntime()
Returns the time (in milliseconds) at which this Proxy is scheduled to run.


OpenNMS API 1.1.4

Generated by eevans on November 11 2004 1600.