Class Stats
- java.lang.Object
-
- com.sun.identity.shared.stats.Stats
-
- All Implemented Interfaces:
ShutdownListener
@SupportedAll public class Stats extends Object implements ShutdownListener
Allows a uniform interface to statistics information in a uniform format.
Stats
supports different states of filing stats information:OFF
,FILE
andCONSOLE
.
-
OFF
statistics is turned off. -
FILE
statistics information is written to a file -
CONSOLE
statistics information is written on console
Stats service uses the property file,
AMConfig.properties
, to set the default stats level and the output directory where the stats files will be placed. The properties file is located (usingResourceBundle
semantics) from one of the directories in the CLASSPATH.The following keys are used to configure the Stats service. Possible values for the key 'state' are: off | off | file | console The key 'directory' specifies the output directory where the stats files will be created.
com.iplanet.services.stats.state com.iplanet.services.stats.directory
System.out
If these properties are changed, the server must be restarted for the changes to take effect.NOTE: Printing Statistics is an IO intensive operation and may hurt application performance when abused. Particularly, note that Java evaluates the arguments to
message()
andwarning()
even when statistics is turned off. It is recommended that the stats state be checked before invoking anymessage()
orwarning()
methods to avoid unnecessary argument evaluation and to maximize application performance.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStatsListener(com.sun.identity.shared.stats.StatsListener listener)
void
destroy()
Destroys the stats object, closes the stats file and releases any system resources.protected void
finalize()
Flushes and then closes the stats file.static Stats
getInstance(String statsName)
Returns an existing instance of Stats for the specified stats file or a new one if no such instance already exists.int
getState()
Returns one of the 3 possible values.boolean
isEnabled()
Checks if statistics is enabled.void
record(String msg)
Prints messages only when the stats state is eitherStats.FILE
orStats.CONSOLE
.void
setStats(int statsType)
Sets the stats capabilities based on the values of thestatsType
argument.void
setStats(String statsType)
Sets thestats
capabilities based on the values of thestatsType
argument.void
shutdown()
The function to run when the system shutdown.
-
-
-
Field Detail
-
OFF
public static final int OFF
flags the disabled stats state.- See Also:
- Constant Field Values
-
FILE
public static final int FILE
Flags the state where all the statistic information is printed to a file- See Also:
- Constant Field Values
-
CONSOLE
public static final int CONSOLE
Flags the state where printing to a file is disabled. All printing is done on System.out.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static Stats getInstance(String statsName)
Returns an existing instance of Stats for the specified stats file or a new one if no such instance already exists. If a Stats object has to be created, its level is set to the level defined in theAMConfig.properties
file. The level can be changed later by usingsetStats(int)
orsetStats(String)
- Parameters:
statsName
- name of statistic instance.- Returns:
- an existing instance of Stats for the specified stats file.
-
isEnabled
public boolean isEnabled()
Checks if statistics is enabled.NOTE: It is recommended that
isEnabled()
be used instead ofisEnabled()
as the former is more intuitive.- Returns:
true
if statistics is enabledfalse
if statistics is disabled
-
getState
public int getState()
Returns one of the 3 possible values.Stats.OFF
Stats.FILE
Stats.CONSOLE
- Returns:
- state of Stats.
-
record
public void record(String msg)
Prints messages only when the stats state is eitherStats.FILE
orStats.CONSOLE
.NOTE: Printing Statistics is an IO intensive operation and may hurt application performance when abused. Particularly, note that Java evaluates arguments to
message()
even when statistics is turned off. So when the argument to this method involves the String concatenation operator '+' or any other method invocation,isEnabled
MUST be used. It is recommended that the stats state be checked by invokingisEnabled()
before invoking anymessage()
methods to avoid unnecessary argument evaluation and maximize application performance.- Parameters:
msg
- message to be recorded.
-
setStats
public void setStats(int statsType)
Sets the stats capabilities based on the values of thestatsType
argument.- Parameters:
statsType
- is any one of five possible values:Stats.OFF
Stats.FILE
Stats.CONSOLE
-
setStats
public void setStats(String statsType)
Sets thestats
capabilities based on the values of thestatsType
argument.- Parameters:
statsType
- is any one of the following possible values:off - statistics is disabled
file - statistics are written to the stats file
System.out
console - statistics are written to the stats to the console
-
destroy
public void destroy()
Destroys the stats object, closes the stats file and releases any system resources. Note that the stats file will remain open untildestroy()
is invoked. To conserve file resources, you should invokedestroy()
explicitly rather than wait for the garbage collector to clean up.If this object is accessed after
destroy()
has been invoked, the results are undefined.
-
shutdown
public void shutdown()
Description copied from interface:ShutdownListener
The function to run when the system shutdown.- Specified by:
shutdown
in interfaceShutdownListener
-
finalize
protected void finalize()
Flushes and then closes the stats file.
-
addStatsListener
public void addStatsListener(com.sun.identity.shared.stats.StatsListener listener)
-
-