|
Protomatter Software v1.1.8 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.protomatter.util.Debug
A simple hierarchical namespace utility. Maintains a static list of names and/or patterns to match names. Dots (".") provide hierarchy markers. For instance, if you add the following patterns:
Then the following names would "match" the patterns if the "scanning" feature is turned on:
If you have "scanning" turned off, then only the following names would match:
And the following names would not "match" the patterns:
This class is useful in debugging:
import com.protomatter.util.Debug; import com.protomatter.util.StackTraceUtil; import com.protomatter.syslog.Channel; ... private final static Debug debug = Debug.forPackage(ThisClass.class); private final static Channel channel = Channel.forPackage(ThisClass.class); ... // three levels... trace, debug and info if (debug.trace()) channel.debug(this, "Really detailed tracing statements"); if (debug.debug()) channel.debug(this, "Debugging statements: I'm here -> " + StackTraceUtil.whereAm()); if (debug.info()) channel.info(this, "Information messages"); |
This can prevent expensive operations involved in debugging to be quickly bypassed in production environments by changing a configuration file instead of re-compiling.
All the work is done in the constructor, which calls the match() method. Calling the trace(), debug() or info() methods takes almost no time (return values are cached).
I've tested this operation on a 650MHz PIII Coppermine Sony Vaio laptop running RedHat Linux 7.2, kernel 2.4.9, I saw these results for timing "Debug.forName(name)":
Virtual Machine | Best Case | Middle Case | Worst Case |
---|---|---|---|
Classic VM (build JDK-1.2.2_012, green threads, nojit) |
0.018627ms | 0.076707ms | 0.625373ms |
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_03-b03) |
0.001347ms | 0.008267ms | 0.08128ms |
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) |
0.00184ms | 0.008067ms | 0.07928ms |
JRockit Virtual Machine (build 3.1.4-dax.appeal.se-20020319-1000) Native Threads, Generational Concurrent Garbage Collector |
0.00092ms | 0.006453ms | 0.065147ms |
Classic VM (build 1.3.1, J2RE 1.3.1 IBM build cxia32131-20020410 (JIT enabled: jitc)) |
0.00204ms | 0.00488ms | 0.039253ms |
"Best Case" above is a direct match, where the name being matched is the same as one of the patterns. "Middle Case" is a search only one or two checks away from success, like matching "foo.bar.baz" against "foo.bar.*". "Worst Case" is a match that's 13 checks away. All cases had around 125 patterns in the search group. Your mileage may vary.
If you call setScan(false), then all matches will be "Best Case" but only exact matches will return true.
If disable() has been called, this method will return false immediately. If there are no patterns set, it has the same effect.
Channel
,
Syslog
,
StackTraceUtil
,
SyslogXML.configure(org.jdom.Element)
, Serialized FormMethod Summary | |
static void |
addDebugName(java.lang.String name)
Add a name or pattern to the matching set at the "debug" level. |
static void |
addInfoName(java.lang.String name)
Add a name or pattern to the matching set at the "info" level. |
static void |
addTraceName(java.lang.String name)
Add a name or pattern to the matching set at the "trace" level. |
static void |
clear()
Clear the sets of patterns and names. |
boolean |
debug()
Does our name match anything in the list of names and patterns. |
static void |
disable()
Disable all checks. |
static void |
enable()
Enable checks. |
static Debug |
forClass(java.lang.Class someClass)
Get a debug object with name of the given class. |
static Debug |
forName(java.lang.String name)
Get a debug object with the given name. |
static Debug |
forPackage(java.lang.Class someClass)
Get a debug object with name of the given class's package. |
static java.util.Iterator |
getDebugNames()
Get the names and/or patterns to match at the "debug" severity. |
static java.util.Iterator |
getInfoNames()
Get the names and/or patterns to match at the "info" severity. |
java.lang.String |
getName()
Get the name this instance uses. |
static boolean |
getScan()
Should we scan for matches? Default is false. |
static java.util.Iterator |
getTraceNames()
Get the names and/or patterns to match at the "trace" severity. |
boolean |
info()
Does our name match anything in the list of names and patterns. |
void |
init()
Initialize this Debug instance. |
static boolean |
isEnabled()
Determine if checks are enabled or disabled. |
static void |
main(java.lang.String[] args)
Performance testing rig. |
static void |
setScan(boolean setting)
Set if we scan for matches. |
java.lang.String |
toString()
Return a human-readable representation of this object. |
boolean |
trace()
Does our name match anything in the list of names and patterns. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
public final void init()
public static final Debug forClass(java.lang.Class someClass)
public static final Debug forPackage(java.lang.Class someClass)
public static final Debug forName(java.lang.String name)
public static final void disable()
public static final void enable()
public static final boolean isEnabled()
public final boolean trace()
public final boolean debug()
public final boolean info()
public static final void setScan(boolean setting)
public static final boolean getScan()
public static final java.util.Iterator getTraceNames()
public static final java.util.Iterator getDebugNames()
public static final java.util.Iterator getInfoNames()
public static final void addTraceName(java.lang.String name)
public static final void addDebugName(java.lang.String name)
public static final void addInfoName(java.lang.String name)
public static final void clear()
public final java.lang.String getName()
public final java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
|
Protomatter Software v1.1.8 Copyright 1998-2002 Nate Sammons |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Protomatter Software v1.1.8 | http://protomatter.sourceforge.net/1.1.8 |