Holger's
Java API

com.antelmann.db
Class DBStoreProfiler

java.lang.Object
  extended by com.antelmann.db.DBStoreProfiler
All Implemented Interfaces:
DBStoreListener

public class DBStoreProfiler
extends Object
implements DBStoreListener

allows to easily profile a store. Note that for fetch-calls, only the fetch-command itself is profiled, not the time it takes to enumerate through the elements! Note also that database errors are currently not profiled.

Since:
05.03.2012, 22:12:49
Author:
Holger Antelmann

Nested Class Summary
static class DBStoreProfiler.ProfileModel
          the profile model is a read-only snapshot of the given profile.
 
Nested classes/interfaces inherited from interface com.antelmann.db.DBStoreListener
DBStoreListener.Adapter, DBStoreListener.StoreUpdateAdapter
 
Method Summary
static DBStoreProfiler addNewProfiler(Database<?> db)
           
 void clear()
           
 DBStoreProfiler.ProfileModel createTableModel()
          provides a read-only snapshot of the current profile
 void databaseAccessed(DBClassStore<?> dbstore, DBClassStore.DBMethod method, Object parameter, long timeTaken)
          called upon successfully reading from the database (guaranteed to be called from within the transaction).
 void databaseError(DBClassStore<?> dbstore, Throwable t, DBClassStore.DBMethod method, Object parameter)
          called when an error occurred while accessing the database (not guaranteed to be called from within the transaction)
 void databaseUpdated(DBUpdateEvent event, long timeTaken)
          called upon successful insert, delete or update; note that the update becomes permanent ONLY if the current transaction successfully commits.
 void fetchCall(DBClassStore<?> store, DBEnumeration<?> e, String method, long timeTaken)
          called when a method is called on a DBEnumeration that is returned by the store
 Class<?>[] getAvailableProfileClasses()
           
 DataMap<String> getProfile(Class<?> type)
          the returned profile contains DataPoints that represent the duration of each store call in milliseconds
static DBStoreProfiler getProfiler(Database<?> db)
           
 long getTotalTime(Class<?> type, String method)
          Note that - if the type is null - the returned time may be overestimating the time spent in database calls if one store calls another (nested call), since the time spent on the nested store is additionally counted for the outer store as well.
static DBStoreProfiler obtainProfiler(Database<?> db)
           
 void prepareDatabaseCall(DBClassStore<?> dbstore, DBClassStore.DBMethod method, Object parameter)
          called before the given method is delegated to the embedded store
protected  void profileCall(long timeTaken, DBClassStore<?> store, String method, Object parameter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

clear

public void clear()

getAvailableProfileClasses

public Class<?>[] getAvailableProfileClasses()

getProfile

public DataMap<String> getProfile(Class<?> type)
the returned profile contains DataPoints that represent the duration of each store call in milliseconds


profileCall

protected void profileCall(long timeTaken,
                           DBClassStore<?> store,
                           String method,
                           Object parameter)

databaseUpdated

public void databaseUpdated(DBUpdateEvent event,
                            long timeTaken)
                     throws DBVetoException
Description copied from interface: DBStoreListener
called upon successful insert, delete or update; note that the update becomes permanent ONLY if the current transaction successfully commits.

Specified by:
databaseUpdated in interface DBStoreListener
Throws:
DBVetoException - if the listener explicitly wants to prevent the update from occurring; this exception is then propagated
See Also:
TransactionListener, DatabaseChangeMonitor, DBVersionedUpdateEvent, Database.setVersioningEnabled(Class, boolean)

databaseAccessed

public void databaseAccessed(DBClassStore<?> dbstore,
                             DBClassStore.DBMethod method,
                             Object parameter,
                             long timeTaken)
Description copied from interface: DBStoreListener
called upon successfully reading from the database (guaranteed to be called from within the transaction). This method is not called when an update occurred - in which case only DBStoreListener.databaseUpdated(DBUpdateEvent, long) is called.

Specified by:
databaseAccessed in interface DBStoreListener

prepareDatabaseCall

public void prepareDatabaseCall(DBClassStore<?> dbstore,
                                DBClassStore.DBMethod method,
                                Object parameter)
                         throws DBVetoException
Description copied from interface: DBStoreListener
called before the given method is delegated to the embedded store

Specified by:
prepareDatabaseCall in interface DBStoreListener
Throws:
DBVetoException - if a listener seeks to prevent the call to the embedded store

databaseError

public void databaseError(DBClassStore<?> dbstore,
                          Throwable t,
                          DBClassStore.DBMethod method,
                          Object parameter)
Description copied from interface: DBStoreListener
called when an error occurred while accessing the database (not guaranteed to be called from within the transaction)

Specified by:
databaseError in interface DBStoreListener

fetchCall

public void fetchCall(DBClassStore<?> store,
                      DBEnumeration<?> e,
                      String method,
                      long timeTaken)
Description copied from interface: DBStoreListener
called when a method is called on a DBEnumeration that is returned by the store

Specified by:
fetchCall in interface DBStoreListener
See Also:
DBClassStore.fetch(com.antelmann.util.Filter), DBClassStore.fetchStubs(com.antelmann.util.Filter), DBEnumeration

getTotalTime

public long getTotalTime(Class<?> type,
                         String method)
Note that - if the type is null - the returned time may be overestimating the time spent in database calls if one store calls another (nested call), since the time spent on the nested store is additionally counted for the outer store as well.

Parameters:
type - if non-null, only calls of this type are considered
method - if non-null, only calls of the given method type are considered
Returns:
the total time for the given parameters

createTableModel

public DBStoreProfiler.ProfileModel createTableModel()
provides a read-only snapshot of the current profile


addNewProfiler

public static DBStoreProfiler addNewProfiler(Database<?> db)

getProfiler

public static DBStoreProfiler getProfiler(Database<?> db)

obtainProfiler

public static DBStoreProfiler obtainProfiler(Database<?> db)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads