jrunx.metrics
Class MetricsService

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.metrics.MetricsService
All Implemented Interfaces:
Metrics, MetricsConstants, MetricsServiceMBean, javax.naming.Referenceable, java.io.Serializable, Service, ServiceMBean

public class MetricsService
extends ServiceAdapter
implements Metrics

See Also:
Serialized Form

Field Summary
protected  java.util.Stack available
           
protected  int freeMemoryMetric
           
protected  java.util.Vector history
           
protected  long lastSnapshotTime
           
protected  java.util.Map metricObjects
           
protected  int[] metrics
           
protected  int nextMetric
           
protected  java.lang.Runtime rt
           
protected  int totalMemoryMetric
           
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Fields inherited from interface jrunx.metrics.MetricsConstants
METRICS_BUSY_TH, METRICS_DELAY_MS, METRICS_DELAY_RQ, METRICS_DELAY_TH, METRICS_DROPPED_RQ, METRICS_FREE_MEMORY, METRICS_IDLE_TH, METRICS_LISTEN_TH, METRICS_TOTAL_MEMORY, METRICS_TOTAL_TH
 
Constructor Summary
MetricsService()
           
 
Method Summary
 int createMetric(java.lang.String name)
          create a metric with the given name
 int createMetric(java.lang.String name, boolean reset)
          create a metric with the given name.
 java.util.Properties createProperties(int[] values)
          Create a Properties object with the metrics name as the key and the given values as the corresponding element.
 void deleteMetric(java.lang.String name)
          remove a metric by name
 int[] exchangeMetrics(int[] values)
          swap metrics arrays atomically.
 int findMetric(java.lang.String name)
          look up a metric by name
 int getHistorySize()
          Gets the current size of the metrics history buffer
 int getInitialSize()
          Gets the initial size of the metrics array
 int getMetric(int index)
          obtain the value of a metric
 Metrics getMetricsService()
          Convenience method for returning a reference to the current object instance.
 int[] getSnapshot()
          Take a snapshot of the current metrics.
 int[] getSnapshot(boolean reset)
          Take a snapshot of the current metrics.
 java.util.Vector getSnapshotHistory()
          Returns the snapshot history.
 long getSnapshotTime()
          Returns the timestamp of the last snapshot.
 void init()
          Not every service needs to init, implement it out of convenience.
 boolean isReset(java.lang.String name)
          Determine if the metric should be reset when a snapshot is taken
 void setHistorySize(int size)
          Sets the size of the metrics history buffer.
 void setInitialSize(int size)
          Sets the initial size of the metrics array.
 void setMetric(int index, int value)
          change the value of a metric
protected  void trimHistory()
           
 int updateMetric(int index, int delta)
          update the value of a metric by adding the given delta value in an atomic operation.
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, destroy, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, start, stop, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, start, stop, updateStatus
 

Field Detail

history

protected java.util.Vector history

metrics

protected int[] metrics

nextMetric

protected int nextMetric

available

protected java.util.Stack available

metricObjects

protected java.util.Map metricObjects

rt

protected java.lang.Runtime rt

freeMemoryMetric

protected int freeMemoryMetric

totalMemoryMetric

protected int totalMemoryMetric

lastSnapshotTime

protected long lastSnapshotTime
Constructor Detail

MetricsService

public MetricsService()
Method Detail

getHistorySize

public int getHistorySize()
Description copied from interface: MetricsServiceMBean
Gets the current size of the metrics history buffer
Specified by:
getHistorySize in interface MetricsServiceMBean
Following copied from interface: jrunx.metrics.MetricsServiceMBean
Returns:
The size of the buffer

setHistorySize

public void setHistorySize(int size)
Description copied from interface: MetricsServiceMBean
Sets the size of the metrics history buffer. The default is 10.
Specified by:
setHistorySize in interface MetricsServiceMBean
Following copied from interface: jrunx.metrics.MetricsServiceMBean
Parameters:
size - The size of the buffer

trimHistory

protected void trimHistory()

getInitialSize

public int getInitialSize()
Description copied from interface: MetricsServiceMBean
Gets the initial size of the metrics array
Specified by:
getInitialSize in interface MetricsServiceMBean
Following copied from interface: jrunx.metrics.MetricsServiceMBean
Returns:
The size of the metrics array

setInitialSize

public void setInitialSize(int size)
Description copied from interface: MetricsServiceMBean
Sets the initial size of the metrics array. The default is 100.
Specified by:
setInitialSize in interface MetricsServiceMBean
Following copied from interface: jrunx.metrics.MetricsServiceMBean
Parameters:
size - The size of the metrics array

init

public void init()
          throws java.lang.Exception
Description copied from class: ServiceAdapter
Not every service needs to init, implement it out of convenience.
Specified by:
init in interface Service
Overrides:
init in class ServiceAdapter

createMetric

public int createMetric(java.lang.String name)
Description copied from interface: Metrics
create a metric with the given name
Specified by:
createMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
the - name of the metric
Returns:
index of the new metric

createMetric

public int createMetric(java.lang.String name,
                        boolean reset)
Description copied from interface: Metrics
create a metric with the given name. If the 'reset' value is true then the value will be reset after logging
Specified by:
createMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
name - the name of the metric
reset - true if the value should be reset after logging
Returns:
index of the new metric

deleteMetric

public void deleteMetric(java.lang.String name)
Description copied from interface: Metrics
remove a metric by name
Specified by:
deleteMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
name - String name of the metric to be deleted

findMetric

public int findMetric(java.lang.String name)
Description copied from interface: Metrics
look up a metric by name
Specified by:
findMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
the - name
Returns:
the index of the metric, or -1 if not found

setMetric

public void setMetric(int index,
                      int value)
Description copied from interface: Metrics
change the value of a metric
Specified by:
setMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
index - metric to be updated
value - the new value

getMetric

public int getMetric(int index)
Description copied from interface: Metrics
obtain the value of a metric
Specified by:
getMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
index - metric to be fetched

updateMetric

public int updateMetric(int index,
                        int delta)
Description copied from interface: Metrics
update the value of a metric by adding the given delta value in an atomic operation.
Specified by:
updateMetric in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
index - the metric index
Returns:
the new metric value, equal to [old-value] + delta

exchangeMetrics

public int[] exchangeMetrics(int[] values)
Description copied from interface: Metrics
swap metrics arrays atomically. This method can be used to efficiently take a snapshot of the current metrics. A separate entity can maintain a set of buffers and rotate them in and out of the metrics manager.
Specified by:
exchangeMetrics in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
values - an old buffer to install
Returns:
the current buffer with the latest values

getSnapshot

public int[] getSnapshot()
Description copied from interface: Metrics
Take a snapshot of the current metrics.
Specified by:
getSnapshot in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Returns:
The current metrics

getSnapshot

public int[] getSnapshot(boolean reset)
Description copied from interface: Metrics
Take a snapshot of the current metrics. Optionally reset any metrics that should be reset (reset flag true on createMetric).
Specified by:
getSnapshot in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
reset - true if the metrics should be reset
Returns:
The current metrics

getSnapshotHistory

public java.util.Vector getSnapshotHistory()
Description copied from interface: Metrics
Returns the snapshot history. The history is returned as a Vector of MetricsSnapshot objects, with the first element being the most recent and the last element being the oldest.
Specified by:
getSnapshotHistory in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Returns:
The vector of MetricsSnapshot objects

getSnapshotTime

public long getSnapshotTime()
Description copied from interface: Metrics
Returns the timestamp of the last snapshot. This can be used to determine the current elapsed time of the metrics that are reset
Specified by:
getSnapshotTime in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Returns:
The last time a snapshot (and reset) was performed

createProperties

public java.util.Properties createProperties(int[] values)
Description copied from interface: Metrics
Create a Properties object with the metrics name as the key and the given values as the corresponding element.
Specified by:
createProperties in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
The - values
Returns:
The Properties object

isReset

public boolean isReset(java.lang.String name)
Description copied from interface: Metrics
Determine if the metric should be reset when a snapshot is taken
Specified by:
isReset in interface Metrics
Following copied from interface: jrunx.metrics.Metrics
Parameters:
name - The metric name
Returns:
true if the metric should be reset

getMetricsService

public Metrics getMetricsService()
Description copied from interface: MetricsServiceMBean
Convenience method for returning a reference to the current object instance. There is no way using JMX to directly reference an object (you must make method calls via invoke). Since this would incur additional overhead, and metrics gathering should be as non-obtrusive as possible, this method allows you direct access to the metrics service.
Specified by:
getMetricsService in interface MetricsServiceMBean


Copyright � 2002 Macromedia Corporation. All Rights Reserved.