com.commsen.stopwatch.engines
Class DefaultStopwatchEngine

java.lang.Object
  extended by com.commsen.stopwatch.engines.DefaultStopwatchEngine
All Implemented Interfaces:
StopwatchEngine
Direct Known Subclasses:
MemoryStopwatchEngine

public class DefaultStopwatchEngine
extends java.lang.Object
implements StopwatchEngine

Default stopwatch engine. This engine simply measures how many times measured code was executed and how long it take.

Author:
Milen Dyankov

Constructor Summary
DefaultStopwatchEngine()
           
 
Method Summary
 long begin(java.lang.String group, java.lang.String label)
          Method called when mensuration is started.
 void end(long id)
          Method called when mensuration is stopped.
protected  org.apache.log4j.Logger getLogger()
           
 int getPersistenceMode()
           
 java.util.Properties getProperties()
          Returns engine properties.
 StopwatchStorage getStorage()
          Allows clients to get reference to the stopwatch's storage.
 java.lang.String getStorageClass()
          Method called to obtain the current storage class
 StorageManager getStorageManager()
           
protected  boolean isDebug()
           
 boolean isDebugEnabled()
           
 void pause()
          Called when Stopwatch is disabled or for any other reason it will not use this engine for some time.
 void resume()
          Called when Stopwatch is enabled and before attepting to use paused engine.
 void setDebugEnabled(boolean debugEnabled)
          Instructs engine to disable/enable debug information.
 void setPersistenceMode(int persistenceMode)
          Method called to instruct engine in what mode persistence manager should work in.
 void setProperties(java.util.Properties properties)
          Called by Stopwatch to set engine properties .
 void setStorage(StopwatchStorage storage)
          Method called to instruct engine to use user defined storage
 void skip(long id)
          Method called when mensuration with id id is to be skipped.
 void start()
          Method called by Stopwatch when initilializing Stopwatch engine.
 void stop()
          Called when Stopwatch's engine is changed or for any other reason Stopwatch will no longer use this engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultStopwatchEngine

public DefaultStopwatchEngine()
Method Detail

start

public void start()
Description copied from interface: StopwatchEngine
Method called by Stopwatch when initilializing Stopwatch engine.

Specified by:
start in interface StopwatchEngine
See Also:
StopwatchEngine.start()

pause

public void pause()
Description copied from interface: StopwatchEngine
Called when Stopwatch is disabled or for any other reason it will not use this engine for some time. This gives engine a chance to force-close all pending measurments, invalidate caches, close database connections, etc.

Specified by:
pause in interface StopwatchEngine
See Also:
StopwatchEngine.pause()

resume

public void resume()
Description copied from interface: StopwatchEngine
Called when Stopwatch is enabled and before attepting to use paused engine. This gives engine a chance to re-initialize caches, open database connections, etc.

Specified by:
resume in interface StopwatchEngine
See Also:
StopwatchEngine.resume()

stop

public void stop()
Description copied from interface: StopwatchEngine
Called when Stopwatch's engine is changed or for any other reason Stopwatch will no longer use this engine. This gives engine a chance to free all used resources.

Specified by:
stop in interface StopwatchEngine
See Also:
StopwatchEngine.stop()

begin

public long begin(java.lang.String group,
                  java.lang.String label)
Description copied from interface: StopwatchEngine
Method called when mensuration is started.

Specified by:
begin in interface StopwatchEngine
Parameters:
group - the name of the group this measurment should be placed in
label - how this measurment should be labeled
Returns:
Unique ID representing current measurment.
See Also:
StopwatchEngine.begin(java.lang.String, java.lang.String)

end

public void end(long id)
Description copied from interface: StopwatchEngine
Method called when mensuration is stopped. It is possible to call this method multiple times with the same id, however the engine should process only the first call.

Specified by:
end in interface StopwatchEngine
Parameters:
id - Unique ID representing the actual measurment that need to be stopped.
See Also:
StopwatchEngine.end(long)

skip

public void skip(long id)
Description copied from interface: StopwatchEngine
Method called when mensuration with id id is to be skipped. It is possible to call this method multiple times with the same id, however the engine should process only the first call.

Specified by:
skip in interface StopwatchEngine
Parameters:
id - Unique ID representing the actual measurment that need to be stopped.
See Also:
StopwatchEngine.skip(long)

isDebugEnabled

public boolean isDebugEnabled()
Returns:
Returns the debugEnabled.

setDebugEnabled

public void setDebugEnabled(boolean debugEnabled)
Description copied from interface: StopwatchEngine
Instructs engine to disable/enable debug information. The reason for this exist is to be able to minimize the performance impact Stopwatch may have on the measured application. Generating debug info consumes additional CPU units, which may become a problem if Stopwatch is heavily used. Setting this to false (it is false by default) should cause no debug info being generated even when log4j's level is set to DEBUG.

Specified by:
setDebugEnabled in interface StopwatchEngine
Parameters:
debugEnabled - should debug information be generated
See Also:
StopwatchEngine.setDebugEnabled(boolean)

getLogger

protected org.apache.log4j.Logger getLogger()

isDebug

protected boolean isDebug()

getStorage

public StopwatchStorage getStorage()
Description copied from interface: StopwatchEngine
Allows clients to get reference to the stopwatch's storage. Storage is normaly used by clients to generate reports.

Specified by:
getStorage in interface StopwatchEngine
Returns:
reference to the storage
See Also:
StopwatchEngine.getStorage()

setStorage

public void setStorage(StopwatchStorage storage)
Description copied from interface: StopwatchEngine
Method called to instruct engine to use user defined storage

Specified by:
setStorage in interface StopwatchEngine
Parameters:
storage - The storage to set.

getStorageClass

public java.lang.String getStorageClass()
Description copied from interface: StopwatchEngine
Method called to obtain the current storage class

Specified by:
getStorageClass in interface StopwatchEngine
Returns:
the class name of the current storage

getStorageManager

public StorageManager getStorageManager()
Returns:
Returns the storageManager.

getPersistenceMode

public int getPersistenceMode()
Returns:
Returns the persistenceMode.

setPersistenceMode

public void setPersistenceMode(int persistenceMode)
Description copied from interface: StopwatchEngine
Method called to instruct engine in what mode persistence manager should work in.

Specified by:
setPersistenceMode in interface StopwatchEngine
Parameters:
persistenceMode - The persistenceMode to set.
See Also:
StorageManager.NORMAL_MODE, StorageManager.THREAD_MODE, StorageManager.DELAYED_MODE

getProperties

public java.util.Properties getProperties()
Description copied from interface: StopwatchEngine
Returns engine properties.

Specified by:
getProperties in interface StopwatchEngine
Returns:
engine properties

setProperties

public void setProperties(java.util.Properties properties)
Description copied from interface: StopwatchEngine
Called by Stopwatch to set engine properties .

Specified by:
setProperties in interface StopwatchEngine
Parameters:
properties - the properties


Copyright © 2006-2008 Commsen International. All Rights Reserved.