atg.service.statistics
Class Sampler

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.service.statistics.Sampler
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, Schedulable, java.util.EventListener

public class Sampler
extends TimedOperationService
implements Schedulable

A Sampler is the base class for services that wish to keep a list of statistics about other services. The sampler is configured with a list of properties to be sampled. Each property is specified in the form {service name}.{property name}.The list is assigned to the property "sampleSources". For example:

 sampleSources=\
      /servers/HttpServer.handledRequestCount,\
      /requesthandling/FileCache.cacheHitRatio
 

On demand, the Sampler can sample all of the properties in the list and produce a SampleEvent, which contains the samples in the order they were specified.

The Sampler can also send out a SampleEvent as an event to all SampleListeners. This can happen on demand as well.

Finally, if Scheduler and Schedule properties are defined, then this Sampler will send out events to SampleListeners according to the given Schedule.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
protected  atg.service.statistics.Sampler.SampleSource[] mSources
          The sample sources
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
Sampler()
          Constructs a blank new Sampler
 
Method Summary
 void addSampleListener(SampleListener pListener)
          Adds a listener to the list of listeners to be notified when a new sample is taken.
 void doStartService()
          This will start the thread running
 void doStopService()
          This will stop the scheduler thread
protected  Sample getSample(atg.service.statistics.Sampler.SampleSource pSource, Sample pPreviousSample)
          Obtains a sample from the given source
 int getSampleListenerCount()
          Returns the number of sample listeners
 SampleListener[] getSampleListeners()
          Returns an array of the sample listeners
 java.lang.String[] getSampleSources()
          Returns the list of {service}.{property} values to be included in every sample.
 Schedule getSchedule()
          Returns the Schedule on which this sampler will run.
 Scheduler getScheduler()
          Returns the Scheduler that will run this sampler
 void initSources()
          Initializes the array of sources to be sampled from the SampleSources property
 void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
          Obtains a sample and sends it to the listeners
 void removeSampleListener(SampleListener pListener)
          Removes a listener from the list of listeners to be notified when a new sample is taken.
 SampleEvent sample()
          Performs a sample on all of the sources in the sample list and returns the result without notifying the listeners.
 SampleEvent sample(boolean pNotifyListeners)
          Performs a sample on all of the sources in the sample list and returns the result.
 void setSampleSources(java.lang.String[] pSampleSources)
          Sets the list of {service}.{property} values to be included in every sample.
 void setSchedule(Schedule pSchedule)
          Sets the Schedule on which this sampler will run.
 void setScheduler(Scheduler pScheduler)
          Sets the Scheduler that will run this sampler
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


mSources

protected atg.service.statistics.Sampler.SampleSource[] mSources
The sample sources

Constructor Detail

Sampler

public Sampler()
Constructs a blank new Sampler

Method Detail

sample

public SampleEvent sample(boolean pNotifyListeners)
                   throws ServiceException
Performs a sample on all of the sources in the sample list and returns the result.

Parameters:
pNotifyListeners - if true, then all SampleListeners will also be notified.
Throws:
ServiceException - if an error occurred while obtaining a sample.

sample

public SampleEvent sample()
                   throws ServiceException
Performs a sample on all of the sources in the sample list and returns the result without notifying the listeners.

Throws:
ServiceException - if an error occurred while obtaining a sample.

getSample

protected Sample getSample(atg.service.statistics.Sampler.SampleSource pSource,
                           Sample pPreviousSample)
                    throws ServiceException
Obtains a sample from the given source

Throws:
ServiceException - if an error occurred while obtaining the sample.

performScheduledTask

public void performScheduledTask(Scheduler pScheduler,
                                 ScheduledJob pJob)
Obtains a sample and sends it to the listeners

Specified by:
performScheduledTask in interface Schedulable
Parameters:
pScheduler - calling the job
pJob - the ScheduledJob

setSampleSources

public void setSampleSources(java.lang.String[] pSampleSources)
Sets the list of {service}.{property} values to be included in every sample.


getSampleSources

public java.lang.String[] getSampleSources()
Returns the list of {service}.{property} values to be included in every sample.


setScheduler

public void setScheduler(Scheduler pScheduler)
Sets the Scheduler that will run this sampler


getScheduler

public Scheduler getScheduler()
Returns the Scheduler that will run this sampler


setSchedule

public void setSchedule(Schedule pSchedule)
Sets the Schedule on which this sampler will run.


getSchedule

public Schedule getSchedule()
Returns the Schedule on which this sampler will run.


addSampleListener

public void addSampleListener(SampleListener pListener)
Adds a listener to the list of listeners to be notified when a new sample is taken.


removeSampleListener

public void removeSampleListener(SampleListener pListener)
Removes a listener from the list of listeners to be notified when a new sample is taken.


getSampleListenerCount

public int getSampleListenerCount()
Returns the number of sample listeners


getSampleListeners

public SampleListener[] getSampleListeners()
Returns an array of the sample listeners


doStartService

public void doStartService()
                    throws ServiceException
This will start the thread running

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

initSources

public void initSources()
                 throws ServiceException
Initializes the array of sources to be sampled from the SampleSources property

Throws:
ServiceException

doStopService

public void doStopService()
This will stop the scheduler thread

Overrides:
doStopService in class GenericService