com.jamonapi.proxy
Class MonProxyFactoryImp

java.lang.Object
  extended by com.jamonapi.proxy.MonProxyFactoryImp

public class MonProxyFactoryImp
extends java.lang.Object

MonProxyFactory allows developers to monitor ANY interface by simply passing the Object implementing the interface to the monitor method. (note the object passed MUST implement an interface or it will be a runtime error). A great use of this is to monitor jdbc interfaces and to aid in this there are overloaded methods that take Connections, Statements, PreparedStatements, CallableStatements, and ResultSets. These overloaded methods take advantage of knowledege of SQL and track additional statistics. The following capabilities can be acquired by using MonProxyFactory. All can individually be enabled/disabled.

This is a nonstatic version and is the primary implementation. The static version MonProxyFactory simply calls this version

  1. Overall monitoring can be enabled/disabled by calling MonProxyFactory.enable(...). This will enable/disable monitors. You can start out by enabling all monitors and disabling the ones you wish or vice versa.
  2. All methods of a given interface will have a jamon rows. Any jamon row will have the label (in this case the method signature), hits, avg/min/max execution time, active/avg active/max active, last value and more. By default interface monitoring is on. It can be enabled/disabled by calling MonProxyFactory.enableInterfaceM(...). JDBC classes such as Connections, Statements, PreparedStatemetns, CallableStatements, and ResultsSets will also automatically be monitored if the class returning them was monitored. If you don't wish this to occur then you can use the monitor method that takes an Object.
  3. ResultSet interfaces can be monitored however methods like getObject and next are called so much and typically don't cause performance problems, so there is a seperate enable/disable capability for them. Note for ResultSet monitoring to occur interface monitoring must also be enabled. However it can be enabled if interface monitoring is enabled and MonProxyFactory.enabledResultSets(true) is called. ResultSet's are by default not monitored.
  4. SQLSummary will add a jamon row for all sql text issued against a PreparedStatement, CallableStatement, or Statement. Argument values are replaced with ? for Statements to ensure the logical queries are matched. PreparedStatements need not be changed to do this, but Statements may look a little different For example: select * from table where name='jeff beck' would become select * from table where name=? This is a powerful monitor as it allows you to see hits, avg/min/max query times for all queries in your application. This is enabled/disabled by calling MonProxyFactory.enableSQLSummary(...).
  5. SQLDetail puts the last N (configurable) queries that have been run into a rolling buffer. The SQL buffer will have the actual query in the case of a Statement and the version with ? for PreparedStatements. In addition other stats will be in this buffer such as how long the query took to execute, how many times has the PreparedStatement been reused, the jdbc method that executed the sql, and the exception stack trace if it occured. This can be enabled/disabled by calling MonProxyFactory.enableSQLDetail(...)
  6. Exception Summary will add several jamon rows when an exception occurs. Note the Exception buffer is used for any kind of Exception including SQLExceptions. The exceptions added are 1. One containing the method that through the exception as well as the exception. 2. One indicating how many exceptions total have been thrown through proxies, 3) One containing the exception type that was thrown. This can be enabled/disabled by calling MonProxyFactory.enableExceptionSummary(...)
  7. ExceptionDetail puts the last N (configurable) exceptions that have occured to any interface that is being monitored into a buffer. The stack trace is in the row as well as when it was thrown and what method threw it. This can be enabled/disabled by calling MonProxyFactory.enableExceptionDetail(...).

Sample code:

ResultSet rs= MonProxyFactory.monitor(resultSet);
   Connection conn=MonProxyFactory.monitor(connection);
   MyInterface my=(MyInterface) MonProxyFactory.monitor(myObject);//myObject implements MyInterface
   YourInterface your=(YourInterface) MonProxyFactory.monitor(yourObject);//myObject implements MyInterface
   


Constructor Summary
MonProxyFactoryImp()
           
 
Method Summary
 void enable(boolean enable)
          Enables all monitors except ResultSet monitoring.
 void enableAll(boolean enable)
          Enables all monitors.
 void enableExceptionDetail(boolean enable)
          Enables/Disables whether exceptions are tracked in a rolling buffer
 void enableExceptionSummary(boolean enable)
          Enables/disables jamon summary stats for exceptions
 void enableInterface(boolean enable)
          Enables/disables whether methods of the interface are monitored or not
 void enableResultSet(boolean enable)
          Enables/disables whether ResultSet methods are monitored.
 void enableSQLDetail(boolean enable)
          Enables/disables whether sql command details (time, sql, stack trace, ...) are kept in a rolling buffer
 void enableSQLSummary(boolean enable)
          Enables/Disables jamon summary stats for SQL
 int getExceptionBufferSize()
          Get the number of Exceptions that can be stored in the buffer before the oldest entries must be removed.
 java.lang.Object[][] getExceptionDetail()
          Get the exception buffer as an array, so it can be displayed
 java.lang.String[] getExceptionDetailHeader()
          Get the header that can be used to display the Exceptions buffer
 java.lang.Class[] getInterfaces(java.lang.Class cls)
          For every class in the Object/Interface heirarchy find its implemented interfaces.
 MonProxyLabelerInt getLabelFactory()
           
 java.util.List getMatchStrings()
          Get a list of the strings to match in the parsed query.
 MonProxy getMonProxy(java.lang.reflect.Proxy proxy)
          Returns the MonProxy invocation handler should you need access to its methods like setLabeler(...) etc.
 int getSQLBufferSize()
          Get the number of SQL statements that can be stored in the buffer before the oldest entries must be removed.
 java.lang.Object[][] getSQLDetail()
          Get the sql buffer as an array, so it can be displayed
 java.lang.String[] getSQLDetailHeader()
          Get the header that can be used to display the SQL buffer
 boolean isAllEnabled()
           
 boolean isEnabled()
          Returns true if MonProxyFactory is enabled.
 boolean isExceptionDetailEnabled()
          Indicates whether exceptions are tracked in a rolling buffer
 boolean isExceptionSummaryEnabled()
          Indicates whether jamon summary stats are kept for exceptions
 boolean isInterfaceEnabled()
          Inidicates whether methods of the interface are monitored or not
 boolean isResultSetEnabled()
          Indicates whether ResultSet methods are monitored.
 boolean isSQLDetailEnabled()
          Indicates whether sql command details (time, sql, stack trace, ...) are kept in a rolling buffer
 boolean isSQLSummaryEnabled()
          Indicates whether jamon summary stats are kept for SQL
 java.sql.CallableStatement monitor(java.sql.CallableStatement statement)
          Monitor a CallableStatements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)
 java.sql.Connection monitor(java.sql.Connection conn)
          Note if a connection object is monitored any Statements, PreparedStatements, CallableStatements, and optionally ResultSets that it creates will automatically be monitored.
 java.lang.Object monitor(java.lang.Object object)
          By passing any interface to the monitor method, all public method calls and exceptions will be monitored.
 java.lang.Object monitor(java.lang.Object object, java.lang.Class iface)
          By passing any interface to the monitor method, and an interface to implement then all public method calls and exceptions will be monitored.
 java.lang.Object monitor(java.lang.Object object, java.lang.Class[] interfaces)
          By passing any interface to the monitor method, and an array of interfaces to implement then all public method calls and exceptions will be monitored.
 java.sql.PreparedStatement monitor(java.sql.PreparedStatement statement)
          Monitor a PreparedStatements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)
 java.sql.ResultSet monitor(java.sql.ResultSet rs)
          Monitor a resultSets methods.
 java.sql.Statement monitor(java.sql.Statement statement)
          Monitor a Statements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)
 void resetExceptionDetail()
          Remove all Exceptions from the buffer.
 void resetSQLDetail()
          Remove all SQL from the buffer.
 void setExceptionBufferSize(int exceptionBufferSize)
          Set the number of Exceptions that can be stored in the buffer before the oldest entries must be removed.
 void setLabelFactory(MonProxyLabelerInt factory)
          This class will be called when creating the jamon labels for both standard summary as well as exceptions.
 void setMatchStrings(java.util.List ms)
          Set the strings to match
 void setSQLBufferSize(int sqlBufferSize)
          Set the number of SQL Statements that can be stored in the buffer before the oldest entries must be removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonProxyFactoryImp

public MonProxyFactoryImp()
Method Detail

setLabelFactory

public void setLabelFactory(MonProxyLabelerInt factory)
This class will be called when creating the jamon labels for both standard summary as well as exceptions.

Parameters:
factory -

getLabelFactory

public MonProxyLabelerInt getLabelFactory()

getMonProxy

public MonProxy getMonProxy(java.lang.reflect.Proxy proxy)
Returns the MonProxy invocation handler should you need access to its methods like setLabeler(...) etc. Note if the handler is not a MonProxy handler than a class cast exception will be thrown. This is possible as the method takes a generic Proxy as an argument. being as the monitor methods return an Object, ResultSet etc. these must be cast to a Proxy before calling this method. For example.
ResultSet rsc=MonProxyFactory.monitor(resultSet);
 MonProxy monProxy=MonProxyFactory.getMonProxy((Proxy)rsc);
 

Parameters:
proxy -
Returns:
MonProxy

monitor

public java.lang.Object monitor(java.lang.Object object)
By passing any interface to the monitor method, all public method calls and exceptions will be monitored. It will be a runtime error if the Object passed does not implement an interface. Note that only interfaces implemented directly by the passed in Object are monitored. Should you want to cast to an interface implemented by a base class to the passed in Object you should call one of the more explicit monitor(..) methods

Sample call:

MyInterface myProxyObject=(MyInterface) MonProxyFactory.monitor(myObject);


monitor

public java.lang.Object monitor(java.lang.Object object,
                                java.lang.Class[] interfaces)
By passing any interface to the monitor method, and an array of interfaces to implement then all public method calls and exceptions will be monitored. It will be a runtime error if the Object passed does not implement an interface.

Sample call:

MyInterface myProxyObject=(MyInterface) MonProxyFactory.monitor(myObject, ineterfaces);


monitor

public java.lang.Object monitor(java.lang.Object object,
                                java.lang.Class iface)
By passing any interface to the monitor method, and an interface to implement then all public method calls and exceptions will be monitored. It will be a runtime error if the Object passed does not implement an interface.

Sample call:

MyInterface myProxyObject=(MyInterface) MonProxyFactory.monitor(myObject, com.mypackage.MyInterface.class);


monitor

public java.sql.Connection monitor(java.sql.Connection conn)
Note if a connection object is monitored any Statements, PreparedStatements, CallableStatements, and optionally ResultSets that it creates will automatically be monitored. So for jdbc interfaces usually it will be sufficient to simply monitor the connection. You could also call MonProxyFactory.monitor((Object)conn); and the connection would be monitored however other child objects wouldn't be and recently executed sql would not be put in a buffer. The same applies to the other overloaded sql monitor(...) method calls below. For sql monitored objects to be monitored both the overall monitoring must be enabled. Monitoring rules apply as discussed in the top of this document.


monitor

public java.sql.ResultSet monitor(java.sql.ResultSet rs)
Monitor a resultSets methods. Note the version that takes an explicit class is used for when the class is a proxy


monitor

public java.sql.Statement monitor(java.sql.Statement statement)
Monitor a Statements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)


monitor

public java.sql.PreparedStatement monitor(java.sql.PreparedStatement statement)
Monitor a PreparedStatements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)


monitor

public java.sql.CallableStatement monitor(java.sql.CallableStatement statement)
Monitor a CallableStatements methods, as well as any ResultSets it returns (assuming the proper monitoring options are enabled)


getInterfaces

public java.lang.Class[] getInterfaces(java.lang.Class cls)
For every class in the Object/Interface heirarchy find its implemented interfaces. All interfaces this class implements are returned. Either the Class of an Object or interfaces Class may be passed to this method. The difference between this method and the method 'Class.getInterfaces()' is that this one returns ALL implemented interfaces whereas that one only returns interfaces that are directly implemented by the Class.


getExceptionBufferSize

public int getExceptionBufferSize()
Get the number of Exceptions that can be stored in the buffer before the oldest entries must be removed.


setExceptionBufferSize

public void setExceptionBufferSize(int exceptionBufferSize)
Set the number of Exceptions that can be stored in the buffer before the oldest entries must be removed. A value of 0 will disable collecting of Exceptions in the buffer.


resetExceptionDetail

public void resetExceptionDetail()
Remove all Exceptions from the buffer.


isInterfaceEnabled

public boolean isInterfaceEnabled()
Inidicates whether methods of the interface are monitored or not


enableInterface

public void enableInterface(boolean enable)
Enables/disables whether methods of the interface are monitored or not


isExceptionSummaryEnabled

public boolean isExceptionSummaryEnabled()
Indicates whether jamon summary stats are kept for exceptions


enableExceptionSummary

public void enableExceptionSummary(boolean enable)
Enables/disables jamon summary stats for exceptions


isExceptionDetailEnabled

public boolean isExceptionDetailEnabled()
Indicates whether exceptions are tracked in a rolling buffer


enableExceptionDetail

public void enableExceptionDetail(boolean enable)
Enables/Disables whether exceptions are tracked in a rolling buffer


isSQLSummaryEnabled

public boolean isSQLSummaryEnabled()
Indicates whether jamon summary stats are kept for SQL


enableSQLSummary

public void enableSQLSummary(boolean enable)
Enables/Disables jamon summary stats for SQL


isSQLDetailEnabled

public boolean isSQLDetailEnabled()
Indicates whether sql command details (time, sql, stack trace, ...) are kept in a rolling buffer


enableSQLDetail

public void enableSQLDetail(boolean enable)
Enables/disables whether sql command details (time, sql, stack trace, ...) are kept in a rolling buffer


isResultSetEnabled

public boolean isResultSetEnabled()
Indicates whether ResultSet methods are monitored. Note interface monitoring must also be enabled for ResultSet monitoring to occur


enableResultSet

public void enableResultSet(boolean enable)
Enables/disables whether ResultSet methods are monitored. Note interface monitoring must also be enabled for ResultSet monitoring to occur


isEnabled

public boolean isEnabled()
Returns true if MonProxyFactory is enabled.


enableAll

public void enableAll(boolean enable)
Enables all monitors. This overrides all other monitor booleans. It never enables ResultSet monitoring That must be done as a separates step as that is not the enabled monitoring by default. All other monitors will be disabled/enabled when calling this method.


isAllEnabled

public boolean isAllEnabled()

enable

public void enable(boolean enable)
Enables all monitors except ResultSet monitoring. This overrides all other monitor booleans. It never enables ResultSet monitoring That must be done as a separates step as that is not the enabled monitoring by default. All other monitors will be disabled/enabled when calling this method.


getExceptionDetailHeader

public java.lang.String[] getExceptionDetailHeader()
Get the header that can be used to display the Exceptions buffer


getExceptionDetail

public java.lang.Object[][] getExceptionDetail()
Get the exception buffer as an array, so it can be displayed


getSQLBufferSize

public int getSQLBufferSize()
Get the number of SQL statements that can be stored in the buffer before the oldest entries must be removed.


setSQLBufferSize

public void setSQLBufferSize(int sqlBufferSize)
Set the number of SQL Statements that can be stored in the buffer before the oldest entries must be removed. A value of 0 will disable the collection of Exceptions in the buffer. Note if monitoring is disabled exceptions will also not be put in the buffer.


resetSQLDetail

public void resetSQLDetail()
Remove all SQL from the buffer.


getSQLDetailHeader

public java.lang.String[] getSQLDetailHeader()
Get the header that can be used to display the SQL buffer


getSQLDetail

public java.lang.Object[][] getSQLDetail()
Get the sql buffer as an array, so it can be displayed


getMatchStrings

public java.util.List getMatchStrings()
Get a list of the strings to match in the parsed query. This can be used to count tables hits and times of queries that hit them for example


setMatchStrings

public void setMatchStrings(java.util.List ms)
Set the strings to match