org.javasimon
Class NullSimon

java.lang.Object
  extended by org.javasimon.NullSimon
All Implemented Interfaces:
HasAttributes, Simon
Direct Known Subclasses:
NullCounter, NullStopwatch

 class NullSimon
extends Object
implements Simon

Null Simon implements Simon returned by the disabled Manager.getSimon(String) or Manager.getRootSimon(). Null Simon does nothing, returns null or zeroes wherever return value is expected and has minimal performance impact on the system.

Author:
Richard "Virgo" Richter

Field Summary
(package private) static NullSimon INSTANCE
          Internal singleton value of the null Simon.
 
Constructor Summary
NullSimon()
          Used only by the subclasses, otherwise should not be used at all except for a single INSTANCE.
 
Method Summary
 Object getAttribute(String name)
          Returns null.
<T> T
getAttribute(String name, Class<T> clazz)
          Returns null.
 Iterator<String> getAttributeNames()
          Returns empty iterator.
 Map<String,Object> getCopyAsSortedMap()
          Returns empty set.
 long getFirstUsage()
          Returns ms timestamp of the first usage of this Simon.
 List<Simon> getChildren()
          Returns list of children - direct sub-simons.
 long getLastReset()
          Returns ms timestamp of the last recent usage of the Simon.reset() method on the Simon.
 long getLastUsage()
          Returns ms timestamp of the last usage of this Simon.
 String getName()
          Returns Simon name.
 String getNote()
          Returns note for the Simon.
 Simon getParent()
          Returns parent Simon.
 SimonState getState()
          Returns state of the Simon that can be enabled, disabled or ihnerited.
 boolean isEnabled()
          Returns true, if the Simon is enabled or if the enabled state is inherited.
 void removeAttribute(String name)
          Does nothing.
 NullSimon reset()
          Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected.
 Sample sample()
          Samples Simon values and returns them in a Java Bean derived from Sample interface.
 Sample sampleAndReset()
          Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon.
 void setAttribute(String name, Object value)
          Does nothing.
 void setNote(String note)
          Sets note for the Simon.
 void setState(SimonState state, boolean overrule)
          Sets the state of the Simon.
 String toString()
          Returns string Null Simon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INSTANCE

static final NullSimon INSTANCE
Internal singleton value of the null Simon. Null Simon is never directly used in the client code, it is always hidden behind the Simon interface - only its behavior manifests to the client.

Constructor Detail

NullSimon

NullSimon()
Used only by the subclasses, otherwise should not be used at all except for a single INSTANCE.

Method Detail

getParent

public Simon getParent()
Description copied from interface: Simon
Returns parent Simon.

Specified by:
getParent in interface Simon
Returns:
parent Simon

getChildren

public final List<Simon> getChildren()
Description copied from interface: Simon
Returns list of children - direct sub-simons.

Specified by:
getChildren in interface Simon
Returns:
list of children

getName

public String getName()
Description copied from interface: Simon
Returns Simon name. Simon name is always fully qualified and determines also position of the Simon in the monitor hierarchy. Simon name can be null for anonymous Simons.

Specified by:
getName in interface Simon
Returns:
name of the Simon

getState

public SimonState getState()
Description copied from interface: Simon
Returns state of the Simon that can be enabled, disabled or ihnerited.

Specified by:
getState in interface Simon
Returns:
state of the Simon

setState

public void setState(SimonState state,
                     boolean overrule)
Description copied from interface: Simon
Sets the state of the Simon. It must be specified whether to propagate the change and overrule states of all sub-simons which effectively sets the same state to the whole subtree. If subtree is not overruled, some Simons (with their subtrees) may not be affected by this change.

Specified by:
setState in interface Simon
Parameters:
state - a new state.
overrule - specifies whether this change is forced to the whole subtree.

isEnabled

public boolean isEnabled()
Description copied from interface: Simon
Returns true, if the Simon is enabled or if the enabled state is inherited.

Specified by:
isEnabled in interface Simon
Returns:
true, if the Simon is effectively enabled

reset

public NullSimon reset()
Description copied from interface: Simon
Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected. Timestamp of the last reset can be obtained by the method Simon.getLastReset(). Reset is perfomed even for disabled Simons.

Specified by:
reset in interface Simon
Returns:
returns this

getLastReset

public long getLastReset()
Description copied from interface: Simon
Returns ms timestamp of the last recent usage of the Simon.reset() method on the Simon. Returns 0 if reset was not called yet. This timestamp is useful for rate measuring when reset is called on a regular basis - likely via Simon.sampleAndReset(). While client code could store the timestamp too it is not necessary with this method.

Specified by:
getLastReset in interface Simon
Returns:
ms timestamp of the last reset or 0 if reset was not called yet

getFirstUsage

public long getFirstUsage()
Description copied from interface: Simon
Returns ms timestamp of the first usage of this Simon. First and last usage are updated when monitor performs the measuring (start/stop/count/etc). They are not updated when values are obtained from the monitor.

Specified by:
getFirstUsage in interface Simon
Returns:
ms timestamp of the first usage

getLastUsage

public long getLastUsage()
Description copied from interface: Simon
Returns ms timestamp of the last usage of this Simon. First and last usage are updated when monitor performs the measuring (start/stop/count/etc). They are not updated when values are obtained from the monitor.

Specified by:
getLastUsage in interface Simon
Returns:
ms timestamp of the last usage

getNote

public String getNote()
Returns note for the Simon.

Specified by:
getNote in interface Simon
Returns:
note for the Simon.

setNote

public void setNote(String note)
Sets note for the Simon.

Specified by:
setNote in interface Simon
Parameters:
note - note for the Simon.

sample

public Sample sample()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface.

Specified by:
sample in interface Simon
Returns:
sample containing all Simon values

sampleAndReset

public Sample sampleAndReset()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon. Operation is synchronized to assure atomicity.

Specified by:
sampleAndReset in interface Simon
Returns:
sample containing all Simon values

setAttribute

public void setAttribute(String name,
                         Object value)
Does nothing.

Specified by:
setAttribute in interface HasAttributes
Parameters:
name - ignored
value - ignored

getAttribute

public Object getAttribute(String name)
Returns null.

Specified by:
getAttribute in interface HasAttributes
Parameters:
name - ignored
Returns:
null

getAttribute

public <T> T getAttribute(String name,
                          Class<T> clazz)
Returns null.

Specified by:
getAttribute in interface HasAttributes
Parameters:
name - ignored
clazz - ignored
Returns:
null

removeAttribute

public void removeAttribute(String name)
Does nothing.

Specified by:
removeAttribute in interface HasAttributes
Parameters:
name - ignored

getAttributeNames

public Iterator<String> getAttributeNames()
Returns empty iterator.

Specified by:
getAttributeNames in interface HasAttributes
Returns:
empty iterator

getCopyAsSortedMap

public Map<String,Object> getCopyAsSortedMap()
Returns empty set.

Specified by:
getCopyAsSortedMap in interface HasAttributes
Returns:
empty set

toString

public String toString()
Returns string Null Simon.

Overrides:
toString in class Object
Returns:
string Null Simon


Copyright © 2013. All Rights Reserved.