org.ow2.jasmine.probe.collectors
Class JCollector

java.lang.Object
  extended by org.ow2.jasmine.probe.collectors.JCollector
All Implemented Interfaces:
JasmineCollector

public abstract class JCollector
extends Object
implements JasmineCollector

This object represents a Collector in use. It is abstract, because implementation may be various. These implementations are in separate modules.

Author:
durieuxp, danesa

Field Summary
protected  String hostName
          Host name corresponding to the IP address of the local host
protected  JasmineIndicator indicator
          Indicator definition
protected  org.ow2.util.log.Log logger
          Logger
protected  String MISC_TARGET
          Can't say which target is, indicator's value may be a result of combining values of indicators having different targets.
protected  String NO_TARGET
          Target not defined (for example, for a constant indicator)
protected  int period
          Period of polling in seconds
protected  String probeId
          Probe id
protected  ProbeManager probeManager
          Reference to the ProbeManager
 
Constructor Summary
JCollector(String probeId, JasmineIndicator def, int period)
          Constructor
 
Method Summary
protected  Number addJsr(Collection<JasmineSingleResult> jsrs)
          Add the values of a list of JSRs.
protected  long addLongJsr(Collection<JasmineSingleResult> jsrs)
          Add the values of a list of JSRs.
protected  long addLongValues(Collection<Number> values)
          Add a list of values of same type (short, int, long or float casted to long)
protected  Number addValues(Collection<Number> values)
          Add a list of values of one of the following types: short, integer, long, float or doubles
protected  Number averageJsr(Collection<JasmineSingleResult> jsrs)
           
protected  Number diffJsr(Collection<JasmineSingleResult> jsrs)
          Make a diff between 2 same type values of a list containing 2 JSRs.
protected  long diffLongValues(Number v1, Number v2)
          Make a diff between 2 values
protected  Number diffValues(Number v1, Number v2)
          Make a difference between 2 values of one of the following types: short, integer, long, float or doubles
protected  Number divideJsr(Collection<JasmineSingleResult> jsrs)
          Make a division of 2 values of 2 JSRs contained in a given JSRs list
protected  float divideLongValues(Number v1, Number v2)
          Make a div between 2 values
protected  Number divideValues(Number v1, Number v2)
          Make a div between 2 values
protected  String getDefaultTarget()
          The default policy is to use the host name.
protected  String getDomainName()
           
 JasmineIndicator getIndicator()
           
 String getIndicatorName()
          Return the name of the indicator corresponding to this Collector
protected  JasmineSingleResult getJsr(String name, Object value, long timestamp, int scale)
          Return the JasmineSingleResult corresponding to a polled value (for example an MBean attribute).
abstract  JasmineIndicatorValue getLastResult()
          return the last result for this indicator
 String getProbeId()
           
protected  String getServerName()
           
 boolean isRemoved()
           
protected  HashMap<String,String> jsrProps(Collection<JasmineSingleResult> jsrs)
          Construct properties for a JSR by aggregating the properties of a collection of JSRs.
protected  long longValue(Number nb)
          Try to cast a Number into a long value
protected  Number maxJsr(Collection<JasmineSingleResult> jsrs)
          Return the max value in a collection of JSRs.
protected  Number minJsr(Collection<JasmineSingleResult> jsrs)
          Return the min value in a collection of JSRs.
protected  Number multiplyJsr(Collection<JasmineSingleResult> jsrs)
          Multiply the values of a list of JSRs.
protected  long multiplyLongValues(Collection<Number> values)
          Multiply a list of values of same type
protected  Number multiplyValues(Collection<Number> values)
          Multiply a list of values of one of the following types: short, integer, long, float or doubles
 void remove()
          Mark collector as removed.
 void setProbeManager(ProbeManager probeManager)
          Set the probeManager ref when it is needed, for some Collectors.
abstract  void startPolling()
          Restart polling
abstract  void stopPolling()
          Stop polling
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.ow2.util.log.Log logger
Logger


indicator

protected JasmineIndicator indicator
Indicator definition


period

protected int period
Period of polling in seconds


probeId

protected String probeId
Probe id


probeManager

protected ProbeManager probeManager
Reference to the ProbeManager


hostName

protected String hostName
Host name corresponding to the IP address of the local host


NO_TARGET

protected final String NO_TARGET
Target not defined (for example, for a constant indicator)

See Also:
Constant Field Values

MISC_TARGET

protected final String MISC_TARGET
Can't say which target is, indicator's value may be a result of combining values of indicators having different targets.

See Also:
Constant Field Values
Constructor Detail

JCollector

public JCollector(String probeId,
                  JasmineIndicator def,
                  int period)
Constructor

Method Detail

remove

public void remove()
Mark collector as removed. Called when a JasmineCollectorService stops.

Specified by:
remove in interface JasmineCollector

isRemoved

public boolean isRemoved()
Specified by:
isRemoved in interface JasmineCollector
Returns:
true if collector marked as removed.

getIndicator

public JasmineIndicator getIndicator()

setProbeManager

public void setProbeManager(ProbeManager probeManager)
Set the probeManager ref when it is needed, for some Collectors.

Parameters:
probeManager -

getDomainName

protected String getDomainName()

getServerName

protected String getServerName()

getIndicatorName

public String getIndicatorName()
Return the name of the indicator corresponding to this Collector

Specified by:
getIndicatorName in interface JasmineCollector

getProbeId

public String getProbeId()
Specified by:
getProbeId in interface JasmineCollector
Returns:
Return the Id of the probe corresponding to this Collector

getLastResult

public abstract JasmineIndicatorValue getLastResult()
                                             throws JasmineCollectorException
return the last result for this indicator

Specified by:
getLastResult in interface JasmineCollector
Returns:
JasmineIndicatorValue or null if no value available
Throws:
JasmineCollectorException

stopPolling

public abstract void stopPolling()
Stop polling

Specified by:
stopPolling in interface JasmineCollector

startPolling

public abstract void startPolling()
Restart polling

Specified by:
startPolling in interface JasmineCollector

getDefaultTarget

protected String getDefaultTarget()
The default policy is to use the host name. If a name corresponding to the IP address of the local host could not be determined, use the current server's name. This policy could be replaced with another one if necessary.

Returns:
A name corresponding to the default naming policy for targets.

getJsr

protected JasmineSingleResult getJsr(String name,
                                     Object value,
                                     long timestamp,
                                     int scale)
                              throws JasmineCollectorException
Return the JasmineSingleResult corresponding to a polled value (for example an MBean attribute). Currently, a JSR is returned only for Numbers, Strings and Booleans.

Parameters:
name - the name of the polled object
value - the obtained value
timestamp - time stamp in milliseconds to put into the JSR
scale - scale to use when calculating the value to put into the JSR
Returns:
A JSR corresponding to the attribute's value or null if the value could not be calculated (in the current implementation, if the value is not a number).
Throws:
JasmineCollectorException - Raised by divideValues.

maxJsr

protected Number maxJsr(Collection<JasmineSingleResult> jsrs)
                 throws JasmineCollectorException
Return the max value in a collection of JSRs.

Parameters:
jsrs - collection of JSRs to be aggregated
Returns:
the maximum numeric value
Throws:
JasmineCollectorException

minJsr

protected Number minJsr(Collection<JasmineSingleResult> jsrs)
                 throws JasmineCollectorException
Return the min value in a collection of JSRs.

Parameters:
jsrs - collection of JSRs to be aggregated
Returns:
the minimum numeric value
Throws:
JasmineCollectorException

averageJsr

protected Number averageJsr(Collection<JasmineSingleResult> jsrs)
                     throws JasmineCollectorException
Throws:
JasmineCollectorException

diffLongValues

protected long diffLongValues(Number v1,
                              Number v2)
                       throws JasmineCollectorException
Make a diff between 2 values

Parameters:
v1 -
v2 -
Returns:
v1 - v2
Throws:
JasmineCollectorException

diffJsr

protected Number diffJsr(Collection<JasmineSingleResult> jsrs)
                  throws JasmineCollectorException
Make a diff between 2 same type values of a list containing 2 JSRs.

Parameters:
jsrs - the list of JSRs
Returns:
Object of same type representing the diff
Throws:
JasmineCollectorException

divideLongValues

protected float divideLongValues(Number v1,
                                 Number v2)
                          throws JasmineCollectorException
Make a div between 2 values

Parameters:
v1 -
v2 -
Returns:
v1 / v2
Throws:
JasmineCollectorException

divideValues

protected Number divideValues(Number v1,
                              Number v2)
                       throws JasmineCollectorException
Make a div between 2 values

Parameters:
v1 -
v2 -
Returns:
v1 / v2
Throws:
JasmineCollectorException

divideJsr

protected Number divideJsr(Collection<JasmineSingleResult> jsrs)
                    throws JasmineCollectorException
Make a division of 2 values of 2 JSRs contained in a given JSRs list

Parameters:
jsrs - the list of 2 JSRs
Returns:
Object of same type representing the division
Throws:
JasmineCollectorException

addValues

protected Number addValues(Collection<Number> values)
                    throws JasmineCollectorException
Add a list of values of one of the following types: short, integer, long, float or doubles

Parameters:
values - to sum
Returns:
Number representing the sum of all values
Throws:
JasmineCollectorException

diffValues

protected Number diffValues(Number v1,
                            Number v2)
                     throws JasmineCollectorException
Make a difference between 2 values of one of the following types: short, integer, long, float or doubles

Parameters:
v1 -
v2 -
Returns:
v1 - v2
Throws:
JasmineCollectorException

addLongValues

protected long addLongValues(Collection<Number> values)
                      throws JasmineCollectorException
Add a list of values of same type (short, int, long or float casted to long)

Parameters:
values -
Returns:
Object a long representing the sum of all the values
Throws:
JasmineCollectorException

addLongJsr

protected long addLongJsr(Collection<JasmineSingleResult> jsrs)
                   throws JasmineCollectorException
Add the values of a list of JSRs.

Parameters:
jsrs - the list of JSRs
Returns:
Number representing the sum of all the JSR values casted to long
Throws:
JasmineCollectorException

addJsr

protected Number addJsr(Collection<JasmineSingleResult> jsrs)
                 throws JasmineCollectorException
Add the values of a list of JSRs.

Parameters:
jsrs - the list of JSRs
Returns:
Number representing the sum of all the JSR values casted to long, float or double
Throws:
JasmineCollectorException

multiplyLongValues

protected long multiplyLongValues(Collection<Number> values)
                           throws JasmineCollectorException
Multiply a list of values of same type

Parameters:
values -
Returns:
Object of same type representing the product of all values
Throws:
JasmineCollectorException

multiplyValues

protected Number multiplyValues(Collection<Number> values)
                         throws JasmineCollectorException
Multiply a list of values of one of the following types: short, integer, long, float or doubles

Parameters:
values - to multiply
Returns:
Object object representing the product of all values
Throws:
JasmineCollectorException

multiplyJsr

protected Number multiplyJsr(Collection<JasmineSingleResult> jsrs)
                      throws JasmineCollectorException
Multiply the values of a list of JSRs.

Parameters:
jsrs - the list of JSRs
Returns:
Object of same type representing the product of all the JSR values.
Throws:
JasmineCollectorException

longValue

protected long longValue(Number nb)
                  throws JasmineCollectorException
Try to cast a Number into a long value

Parameters:
nb -
Returns:
Throws:
JasmineCollectorException

jsrProps

protected HashMap<String,String> jsrProps(Collection<JasmineSingleResult> jsrs)
Construct properties for a JSR by aggregating the properties of a collection of JSRs.

Parameters:
jsrs -
Returns:


Copyright © 2013 OW2 Consortium. All Rights Reserved.