Author: manik.surtani(a)jboss.com
Date: 2008-01-04 12:49:20 -0500 (Fri, 04 Jan 2008)
New Revision: 4989
Modified:
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java
Log:
Optional toString() verbosity if trace is enabled.
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-01-04 17:32:54 UTC
(rev 4988)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-01-04 17:49:20 UTC
(rev 4989)
@@ -42,6 +42,7 @@
* Debug log.
*/
protected static Log log = LogFactory.getLog(UnversionedNode.class);
+ protected static boolean trace = log.isTraceEnabled();
/**
* True if all children have been loaded. This is set when
CacheImpl.getChildrenNames() is called.
@@ -298,7 +299,7 @@
// notify if we actually created a new child
if (newChild == child)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("created child: fqn=" + child_fqn);
}
@@ -348,17 +349,59 @@
{
synchronized (data)
{
- sb.append(" data=[");
- Set keys = data.keySet();
+ if (trace)
+ {
+ sb.append(" data=").append(data.keySet());
+ }
+ else
+ {
+ sb.append(" data=[");
+ Set keys = data.keySet();
+ int i = 0;
+ for (Object o : keys)
+ {
+ i++;
+ sb.append(o);
+
+ if (i == 5)
+ {
+ int more = keys.size() - 5;
+ if (more > 1)
+ {
+ sb.append(", and ");
+ sb.append(more);
+ sb.append(" more");
+ break;
+ }
+ }
+ else
+ {
+ sb.append(", ");
+ }
+ }
+ sb.append("]");
+ }
+ }
+ }
+ if (children != null && !children.isEmpty())
+ {
+ if (trace)
+ {
+ sb.append(" children=").append(getChildrenNamesDirect());
+ }
+ else
+ {
+ sb.append(" children=[");
+ Set names = getChildrenNamesDirect();
int i = 0;
- for (Object o : keys)
+ for (Object o : names)
{
i++;
sb.append(o);
if (i == 5)
{
- int more = keys.size() - 5;
+ int more = names.size() - 5;
if (more > 1)
{
sb.append(", and ");
@@ -375,35 +418,6 @@
sb.append("]");
}
}
- if (children != null && !children.isEmpty())
- {
- sb.append(" children=[");
- Set names = getChildrenNamesDirect();
- int i = 0;
- for (Object o : names)
- {
- i++;
- sb.append(o);
-
- if (i == 5)
- {
- int more = names.size() - 5;
- if (more > 1)
- {
- sb.append(", and ");
- sb.append(more);
- sb.append(" more");
- break;
- }
- }
- else
- {
- sb.append(", ");
- }
- }
- sb.append("]");
-
- }
if (lock_ != null)
{
if (isReadLocked())
@@ -728,7 +742,7 @@
public void setFqn(Fqn fqn)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(getFqn() + " set FQN " + fqn);
}
@@ -864,7 +878,7 @@
public void setValid(boolean valid, boolean recursive)
{
this.valid = valid;
- if (log.isTraceEnabled()) log.trace("Marking node " + getFqn() + "
as " + (valid ? "" : "in") + "valid");
+ if (trace) log.trace("Marking node " + getFqn() + " as " +
(valid ? "" : "in") + "valid");
if (recursive)
{
for (Node child : children().values())
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java 2008-01-04 17:32:54
UTC (rev 4988)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodCall.java 2008-01-04 17:49:20
UTC (rev 4989)
@@ -6,6 +6,8 @@
*/
package org.jboss.cache.marshall;
+import org.apache.commons.logging.LogFactory;
+
import java.lang.reflect.Method;
/**
@@ -25,6 +27,7 @@
*/
public class MethodCall extends org.jgroups.blocks.MethodCall
{
+ private static boolean trace = LogFactory.getLog(MethodCall.class).isTraceEnabled();
/**
* It's unclear why this class would be serialized.
*/
@@ -84,7 +87,6 @@
public String toString()
{
StringBuffer ret = new StringBuffer();
- boolean first = true;
ret.append("MethodName: ");
ret.append(method_name);
ret.append("; MethodIdInteger: ");
@@ -92,10 +94,25 @@
ret.append("; Args: (");
if (args != null && args.length > 0)
{
- ret.append(" arg[0] = ");
- ret.append(args[0]);
- if (args.length > 1) ret.append(" ...");
+ if (trace)
+ {
+ boolean first = true;
+ for (Object arg : args)
+ {
+ if (first) first = false;
+ else ret.append(", ");
+
+ ret.append(arg);
+ }
+ }
+ else
+ {
+ ret.append(" arg[0] = ");
+ ret.append(args[0]);
+ if (args.length > 1) ret.append(" ...");
+ }
}
+
ret.append(')');
return ret.toString();
}