org.javasimon
Class SimonManager

java.lang.Object
  extended by org.javasimon.SimonManager

public final class SimonManager
extends Object

SimonManager is static utility class providing so called "default Manager. It is possible to create separate Manager, but it cannot be accessed via this convenient utility-like class. This option may be useful in Java EE environmant when it's required to separate Simon trees accross different applications. For majority of Java SE applications this class is recommended.

SimonManager also provides configuration initialization via properties. To initialize configuration with the configuration file following option can be added to JVM executable:

-Djavasimon.config.file=some-path/simon.config.xml
To configure the SimonManager via resource that can be found on classpath:
-Djavasimon.config.resource=org/javasimon/example/wannabe-config.xml

Author:
Richard "Virgo" Richter

Field Summary
private static Manager manager
           
static String PROPERTY_CONFIG_FILE_NAME
          Property name for the Simon configuration file is "javasimon.config.file".
static String PROPERTY_CONFIG_RESOURCE_NAME
          Property name for the Simon configuration resource is "javasimon.config.resource".
 
Constructor Summary
private SimonManager()
           
 
Method Summary
static CompositeCallback callback()
          Accesses Simon callback.
static void clear()
          Clears the SimonManager (ignored if manager is disabled).
static ManagerConfiguration configuration()
          Accesses configuration of this manager.
static void destroySimon(String name)
          Destroys Simon or replaces it with UnknownSimon if it's necessary to preserve the hierarchy.
static void disable()
          Disables the Simon Manager.
static void enable()
          Enables the Simon Manager.
static Counter getCounter(String name)
          Returns existing Counter or creates new if necessary.
static Simon getRootSimon()
          Returns root Simon.
static Simon getSimon(String name)
          Returns Simon by its name if it exists.
static Collection<String> getSimonNames()
          Returns unmodifiable collection containing names of all existing Simons.
static Collection<Simon> getSimons(SimonPattern pattern)
          Returns collection containing all existing Simons matching the pattern (can be null).
static Stopwatch getStopwatch(String name)
          Returns existing Stopwatch or creates new if necessary.
(package private) static void init()
          Initilizes the configuration facility for the default Simon Manager.
static boolean isEnabled()
          Returns true if the Simon Manager is enabled.
static Manager manager()
          Accesses default Simon Manager which is the switching manager.
static void message(String message)
          Method propagates message to manager's Callback.
static void warning(String warning, Exception cause)
          Method propagates warning to manager's Callback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_CONFIG_FILE_NAME

public static final String PROPERTY_CONFIG_FILE_NAME
Property name for the Simon configuration file is "javasimon.config.file".

See Also:
Constant Field Values

PROPERTY_CONFIG_RESOURCE_NAME

public static final String PROPERTY_CONFIG_RESOURCE_NAME
Property name for the Simon configuration resource is "javasimon.config.resource".

See Also:
Constant Field Values

manager

private static Manager manager
Constructor Detail

SimonManager

private SimonManager()
Method Detail

init

static void init()
Initilizes the configuration facility for the default Simon Manager. Fetches exception if configuration resource or file is not found. This method does NOT clear the manager itself, only the configuration is reloaded. Method also preserves Callback setup.


getSimon

public static Simon getSimon(String name)
Returns Simon by its name if it exists.

Parameters:
name - name of the Simon
Returns:
Simon object

destroySimon

public static void destroySimon(String name)
Destroys Simon or replaces it with UnknownSimon if it's necessary to preserve the hierarchy.

Parameters:
name - name of the Simon

getCounter

public static Counter getCounter(String name)
Returns existing Counter or creates new if necessary.

Parameters:
name - name of the Counter
Returns:
counter object

getStopwatch

public static Stopwatch getStopwatch(String name)
Returns existing Stopwatch or creates new if necessary.

Parameters:
name - name of the Stopwatch
Returns:
stopwatch object

enable

public static void enable()
Enables the Simon Manager. Enabled manager provides real Simons.


disable

public static void disable()
Disables the Simon Manager. Disabled manager provides null Simons that actually do nothing.


isEnabled

public static boolean isEnabled()
Returns true if the Simon Manager is enabled.

Returns:
true if the Simon Manager is enabled

getRootSimon

public static Simon getRootSimon()
Returns root Simon. Type of the Simon is unknown at the start but it can be replaced by the real Simon later. Specific get method with root Simon name constant can be used in that case.

Returns:
root Simon

getSimonNames

public static Collection<String> getSimonNames()
Returns unmodifiable collection containing names of all existing Simons.

Returns:
collection of all Simon names
Since:
3.1

getSimons

public static Collection<Simon> getSimons(SimonPattern pattern)
Returns collection containing all existing Simons matching the pattern (can be null). Collection is unmodifiable if null pattern is provided and all Simons are returned, otherwise new collection with matching Simons is returned.

Parameters:
pattern - Simon name pattern (see SimonPattern
Returns:
collection of all Simons matching the pattern
Since:
3.1
See Also:
to find out more about possible patterns

clear

public static void clear()
Clears the SimonManager (ignored if manager is disabled). All Simons are lost, but configuration is preserved.


callback

public static CompositeCallback callback()
Accesses Simon callback.

Returns:
Simon callback

configuration

public static ManagerConfiguration configuration()
Accesses configuration of this manager.

Returns:
configuration of this manager

manager

public static Manager manager()
Accesses default Simon Manager which is the switching manager.

Returns:
default Simon Manager

message

public static void message(String message)
Method propagates message to manager's Callback. This allows user to report any message if they implement Callback.onManagerMessage(String).

Parameters:
message - message text

warning

public static void warning(String warning,
                           Exception cause)
Method propagates warning to manager's Callback. This allows user to report any warning and/or exception if they implement Callback.onManagerWarning(String, Exception).

Parameters:
warning - arbitrary warning message
cause - exception causing this warning


Copyright © 2013. All Rights Reserved.