OpenNMS API 1.1.4

org.opennms.netmgt.poller
Class PollableService

java.lang.Object
  extended byorg.opennms.netmgt.poller.IPv4NetworkInterface
      extended byorg.opennms.netmgt.poller.PollableService
All Implemented Interfaces:
NetworkInterface, Pollable, ReadyRunnable, java.lang.Runnable

final class PollableService
extends IPv4NetworkInterface
implements Pollable, ReadyRunnable

The PollableService class ...

Author:
Mike Davidson, OpenNMS

Field Summary
private  boolean m_deletionFlag
          Deletion flag...set to indicate that the service/interface/node tuple represented by this PollableService object has been deleted and should no longer be polled.
private  long m_lastInterval
          This was the interval to use when the node was last rescheduled.
private  long m_lastPoll
          The last time the service was polled...whether due to a scheduled poll or node outage processing.
private  long m_lastScheduledPoll
          The last time the service was scheduled for a poll.
private  ServiceMonitor m_monitor
          The service monitor used to poll this service/interface pair.
private  Package m_package
          The package for this polling interface.
private  PollableInterface m_pInterface
          interface that this service belongs to
private  java.util.List m_pollableServices
          List of all scheduled PollableService objects
private  boolean m_pollImmediate
          Set to true when service is first constructed which will cause the recalculateInterval() method to return 0 resulting in an immediate poll.
private  Scheduler m_scheduler
          The scheduler for the poller
private  Service m_service
          The service inforamtion for this interface.
private  int m_status
          Last known/current status.
private  boolean m_statusChangedFlag
          Indicates if the service changed status as the result of most recent poll.
private  long m_statusChangeTime
          When the last status change occured.
private  java.lang.String m_svcPropKey
          The key used to lookup the service properties that are passed to the monitor.
private  boolean m_unresponsiveFlag
          Flag which indicates if previous poll returned SnmpMonitor.SERVICE_UNRESPONSIVE.
private static java.util.Map SVC_PROP_MAP
          The map of service parameters.
 
Fields inherited from class org.opennms.netmgt.poller.IPv4NetworkInterface
m_address
 
Fields inherited from interface org.opennms.netmgt.poller.Pollable
STATUS_DOWN, STATUS_UNKNOWN, STATUS_UP, statusType
 
Fields inherited from interface org.opennms.netmgt.poller.NetworkInterface
TYPE_IPV4, TYPE_UNKNOWN
 
Constructor Summary
(package private) PollableService(PollableInterface pInterface, java.lang.String svcName, Package pkg, int status, java.util.Date svcLostDate)
          Constructs a new instance of a pollable service object that is polled using the passed monitor.
 
Method Summary
(package private)  void cleanupScheduledServices()
          This method is called to remove a pollable service from the service updates map.
private  void doRun(boolean allowedToRescheduleMyself)
          This used to be the implementation for the run() method.
 boolean equals(java.lang.Object aService)
          Tests if two PollableService objects refer to the same nodeid/interface/service tuple.
 PollableInterface getInterface()
           
 long getLastPollTime()
           
 long getLastScheduleInterval()
           
 Package getPackage()
          Returns the package associated with this service.
 java.lang.String getPackageName()
           
 long getScheduledRuntime()
          Returns the time (in milliseconds) after which this is scheduled to run.
 java.lang.String getServiceName()
          Returns the service name
 int getStatus()
          Returns current status of the object
 boolean isDeleted()
           
 boolean isReady()
          This method is used to evaluate the status of this interface and service pair.
 void markAsDeleted()
           
 int poll()
          Invokes a poll of the service via the ServiceMonitor.
(package private)  long recalculateInterval()
          This method is used to return the next interval for this interface.
(package private)  void reschedule(boolean reUseInterval)
          This method is called to reschedule the service for polling.
(package private)  void reschedule(long interval)
          Reschedules the service at the specified interval (in milliseconds).
 void resetStatusChanged()
           
 void run()
          This is the main method of the class.
 void run(boolean reschedule)
          This an alternative entry point into the class.
private  boolean scheduledOutage()
          Checks the package information for the pollable service and determines if any of the calendar outages associated with the package apply to the current time and the service's interface.
private  void sendEvent(java.lang.String uei, java.util.Map properties)
           
 void setStatus(int status)
           
 boolean statusChanged()
          Returns true if status of service changed as a result of the last poll.
 
Methods inherited from class org.opennms.netmgt.poller.IPv4NetworkInterface
getAddress, getAttribute, getType, setAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_pInterface

private PollableInterface m_pInterface
interface that this service belongs to


m_service

private final Service m_service
The service inforamtion for this interface.


m_package

private final Package m_package
The package for this polling interface.


m_status

private int m_status
Last known/current status.


m_unresponsiveFlag

private boolean m_unresponsiveFlag
Flag which indicates if previous poll returned SnmpMonitor.SERVICE_UNRESPONSIVE.


m_statusChangedFlag

private boolean m_statusChangedFlag
Indicates if the service changed status as the result of most recent poll. Set by poll() method.


m_statusChangeTime

private long m_statusChangeTime
When the last status change occured. Set by the poll() method.


m_deletionFlag

private boolean m_deletionFlag
Deletion flag...set to indicate that the service/interface/node tuple represented by this PollableService object has been deleted and should no longer be polled.


m_monitor

private final ServiceMonitor m_monitor
The service monitor used to poll this service/interface pair.


m_scheduler

private final Scheduler m_scheduler
The scheduler for the poller


m_pollableServices

private final java.util.List m_pollableServices
List of all scheduled PollableService objects


m_pollImmediate

private boolean m_pollImmediate
Set to true when service is first constructed which will cause the recalculateInterval() method to return 0 resulting in an immediate poll.


m_lastPoll

private long m_lastPoll
The last time the service was polled...whether due to a scheduled poll or node outage processing.


m_lastScheduledPoll

private long m_lastScheduledPoll
The last time the service was scheduled for a poll.


m_lastInterval

private long m_lastInterval
This was the interval to use when the node was last rescheduled. This must be used or it could block a queue! (i.e. its ready time gets longer while the elements behind it are ready to go!)


m_svcPropKey

private final java.lang.String m_svcPropKey
The key used to lookup the service properties that are passed to the monitor.


SVC_PROP_MAP

private static java.util.Map SVC_PROP_MAP
The map of service parameters. These parameters are mapped by the composite key (package name, service name).

Constructor Detail

PollableService

PollableService(PollableInterface pInterface,
                java.lang.String svcName,
                Package pkg,
                int status,
                java.util.Date svcLostDate)
Constructs a new instance of a pollable service object that is polled using the passed monitor. The service is scheduled based upon the values in the packages.

Parameters:
pInterface - The interface to poll
svcName - The name of the service being polled.
pkg - The package with the polling information
Method Detail

getInterface

public PollableInterface getInterface()

getServiceName

public java.lang.String getServiceName()
Returns the service name


statusChanged

public boolean statusChanged()
Returns true if status of service changed as a result of the last poll. WARNING: value of m_statusChangedFlag is only reliable immediately following a call to poll()

Specified by:
statusChanged in interface Pollable

resetStatusChanged

public void resetStatusChanged()

getStatus

public int getStatus()
Description copied from interface: Pollable
Returns current status of the object

Specified by:
getStatus in interface Pollable

setStatus

public void setStatus(int status)

markAsDeleted

public void markAsDeleted()

isDeleted

public boolean isDeleted()

getLastPollTime

public long getLastPollTime()

getLastScheduleInterval

public long getLastScheduleInterval()

getScheduledRuntime

public long getScheduledRuntime()
Returns the time (in milliseconds) after which this is scheduled to run.


getPackageName

public java.lang.String getPackageName()

getPackage

public Package getPackage()
Returns the package associated with this service.


isReady

public boolean isReady()
This method is used to evaluate the status of this interface and service pair. If it is time to run the poll again then a value of true is returned. If the interface is not ready then a value of false is returned.

Specified by:
isReady in interface ReadyRunnable
Throws:
java.lang.RuntimeException - Throws if the ready time cannot be computed due to invalid downtime model.

reschedule

void reschedule(long interval)
Reschedules the service at the specified interval (in milliseconds).


reschedule

void reschedule(boolean reUseInterval)
This method is called to reschedule the service for polling. NOTE: Scheduler calls reschedule() with reUseInterval parm set to true in the event that a scheduled outage is in effect when a service is popped from the interval queue for polling.

Parameters:
reUseInterval - Flag which controls how the interval at which to reschedule the interface is determined. If true, value of m_lastInterval is used. Otherwise recalculateInterval() is called to recalculate the interval.

recalculateInterval

long recalculateInterval()
This method is used to return the next interval for this interface. If the interval is zero then this service has never run and should be scheduled immediantly. If the time is -1 then the node should be deleted. Otherwise the appropriate scheduled time is returned.

Throws:
java.lang.RuntimeException - Throws if the ready time cannot be computed due to invalid downtime model.

sendEvent

private void sendEvent(java.lang.String uei,
                       java.util.Map properties)

equals

public boolean equals(java.lang.Object aService)
Tests if two PollableService objects refer to the same nodeid/interface/service tuple.

Parameters:
aService - the PollableService object to compare
Returns:
TRUE if the two pollable service objects are equivalent, FALSE otherwise.

cleanupScheduledServices

void cleanupScheduledServices()
This method is called to remove a pollable service from the service updates map. It is necessary to not only remove the passed PollableService object but also to mark any other pollable services which share the same nodeid, interface address and service name for deletion. The reason for this is that the interface/service pair may have applied to multiple packages resulting in the same interface/service pair being polled multiple times.


scheduledOutage

private boolean scheduledOutage()
Checks the package information for the pollable service and determines if any of the calendar outages associated with the package apply to the current time and the service's interface. If an outage applies true is returned...otherwise false is returned.

Returns:
false if no outage found (indicating a poll may be performed) or true if applicable outage is found (indicating poll should be skipped).

run

public void run()
This is the main method of the class. An instance is normally enqueued on the scheduler which checks its isReady method to determine execution. If the instance is ready for execution then it is started with it's own thread context to execute the query. The last step in the method before it exits is to reschedule the interface.

Specified by:
run in interface java.lang.Runnable

run

public void run(boolean reschedule)
         throws LockUnavailableException,
                java.lang.InterruptedException
This an alternative entry point into the class. This was originally created in order to support the PollableServiceProxy, which needed the option of handling its own scheduling and needed to keep the PollableService from rescheduling itself. In addition to allowing this, it also allows exceptions that require a rescheduling decision to pass back up the stack. In all other ways, this method works the same as run().

Parameters:
reschedule - set this to true if you want the pollable service to reschedule itself when done processing.
Throws:
LockUnavailableException - If it was unable to obtain a node lock
ThreadInterruped - If the thread was interrtuped while waiting for a node lock.
java.lang.InterruptedException

doRun

private void doRun(boolean allowedToRescheduleMyself)
            throws LockUnavailableException,
                   java.lang.InterruptedException
This used to be the implementation for the run() method. When we created run(boolean), however, we needed to move the implementation down a level lower so that we could overload the run() method.

Parameters:
allowedToRescheduleMyself - set this to true if you want the pollable service to reschedule itself when done processing.
Throws:
LockUnavailableException - If it was unable to obtain a node lock
ThreadInterruped - If the thread was interrtuped while waiting for a node lock.
java.lang.InterruptedException

poll

public int poll()

Invokes a poll of the service via the ServiceMonitor.


OpenNMS API 1.1.4

Generated by eevans on November 12 2004 1715.