public class ConnectionTracker
extends java.lang.Object
The concept of a connection is very abstract - no specific interface must be implemented for a connection object; the tracker simply keeps track of it from when client code marks it as open and then removes it when client code marks it as closed. Anything not closed is then reported at system shutdown time in the log.
You don't generally need to instantiate this class; a global instance is available in
SystemServices.connectionTracker().
This class is thread safe.
Copyright 2011-2013 Partner Software, Inc.
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectionTracker.ConnectionEntry
This class models a single entry in the ConnectionTracker.
|
| Constructor and Description |
|---|
ConnectionTracker()
Creates a new ConnectionTracker, with generatingStackTraces set to false.
|
ConnectionTracker(boolean generatingStackTraces)
Creates a new ConnectionTracker, with specified value for generatingStackTraces.
|
| Modifier and Type | Method and Description |
|---|---|
void |
closeConnection(java.lang.String mode,
java.lang.String url,
java.lang.Object connectionObject)
Stop tracking a connection.
|
boolean |
isGeneratingStackTraces()
If true, this ConnectionTracker generates a stack trace
when any connection is opened, and stores it for later.
|
java.util.List<ConnectionTracker.ConnectionEntry> |
listOpenConnections()
Returns a copy of the current list of open connections.
|
void |
logOpenConnections()
Logs open connections to the system log.
|
void |
onShutdown()
This must be called when you are ready to shutdown this tracker.
|
void |
openConnection(java.lang.String mode,
java.lang.String url,
java.lang.Object connectionObject)
Start tracking a connection.
|
void |
reportOpenConnections()
Writes an open connection report to logs/reports/OpenConnections.txt.
|
java.lang.String |
reportOpenConnectionsAsHtml()
Returns an open connection report as an HTML string.
|
void |
reportOpenConnectionsAsHtmlTo(VfsFile file)
Writes an open connection report in HTML format to the given VfsFile.
|
java.lang.String |
reportOpenConnectionsAsText()
Returns an open connection report in text format as a String.
|
public ConnectionTracker()
Equivalent to ConnectionTracker(false).
public ConnectionTracker(boolean generatingStackTraces)
generatingStackTraces - if true, generates stack traces for detailed loggingpublic void openConnection(java.lang.String mode,
java.lang.String url,
java.lang.Object connectionObject)
closeConnection(String, String, Object)
then the object will be logged at shutdown.
mode - file access or similar mode - can be anything, but usually read, write, or random.url - URL accessed, if applicable. Does not have to be a URL if there is a more appropriate locator stringconnectionObject - object trackedpublic void closeConnection(java.lang.String mode,
java.lang.String url,
java.lang.Object connectionObject)
openConnection(String, String, Object)
then the object will be logged at shutdown.mode - file access or similar mode - can be anything, but usually read, write, or random.url - URL accessed, if applicable. Does not have to be a URL if there is a more appropriate locator stringconnectionObject - object trackedpublic void logOpenConnections()
public void reportOpenConnections()
public java.lang.String reportOpenConnectionsAsText()
public java.lang.String reportOpenConnectionsAsHtml()
public void reportOpenConnectionsAsHtmlTo(VfsFile file)
file - file to write report topublic void onShutdown()
public boolean isGeneratingStackTraces()
openConnection(String, String, Object).
Note that since the stack trace generation does take time and that stored
stack traces take memory, having this enabled will exact some degree of
performance penalty on the system. Thus, it is disabled by default and
in the standard SystemServices.connectionTracker().
public java.util.List<ConnectionTracker.ConnectionEntry> listOpenConnections()