From 68323125b6d091f3c0e389c8c04d7884645957b1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 4 Jan 2011 17:44:11 +0000 Subject: [PATCH] improved debugging dumps git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2625 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../org/eclipse/jetty/jmx/MBeanContainer.java | 7 +++- .../component/jmx/Dumpable-mbean.properties | 2 + .../Derived-mbean.properties | 0 .../jetty/server/handler/ContextHandler.java | 42 ++++++++++++++++++- .../handler/ConnectHandlerConnectTest.java | 3 +- .../eclipse/jetty/servlet/FilterMapping.java | 6 +++ .../org/eclipse/jetty/servlet/Holder.java | 6 +++ .../util/component/AggregateLifeCycle.java | 10 +++-- .../jetty/util/component/Dumpable.java | 1 + .../jetty/webapp/WebAppClassLoader.java | 6 ++- 10 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 jetty-jmx/src/main/resources/org/eclipse/jetty/util/component/jmx/Dumpable-mbean.properties rename jetty-jmx/src/test/resources/com/acme/{management => jmx}/Derived-mbean.properties (100%) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 7c4b4b30137..b55d49baf53 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -320,6 +320,11 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste { out.append(toString()).append("\n"); AggregateLifeCycle.dump(out,indent,_beans.entrySet()); - } + + /* ------------------------------------------------------------ */ + public String dump() + { + return AggregateLifeCycle.dump(this); + } } diff --git a/jetty-jmx/src/main/resources/org/eclipse/jetty/util/component/jmx/Dumpable-mbean.properties b/jetty-jmx/src/main/resources/org/eclipse/jetty/util/component/jmx/Dumpable-mbean.properties new file mode 100644 index 00000000000..6015f732da6 --- /dev/null +++ b/jetty-jmx/src/main/resources/org/eclipse/jetty/util/component/jmx/Dumpable-mbean.properties @@ -0,0 +1,2 @@ +Dumpable: Dumpable Object +dump():Object:INFO:Dump the nested Object state as a String \ No newline at end of file diff --git a/jetty-jmx/src/test/resources/com/acme/management/Derived-mbean.properties b/jetty-jmx/src/test/resources/com/acme/jmx/Derived-mbean.properties similarity index 100% rename from jetty-jmx/src/test/resources/com/acme/management/Derived-mbean.properties rename to jetty-jmx/src/test/resources/com/acme/jmx/Derived-mbean.properties diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index c15c842a336..3251a18267b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -21,6 +21,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.EventListener; @@ -61,6 +62,8 @@ import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.URIUtil; +import org.eclipse.jetty.util.component.AggregateLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; @@ -191,9 +194,11 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. public void dump(Appendable out,String indent) throws IOException { dumpThis(out); - dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),_initParams.entrySet(), _attributes.getAttributeEntrySet(),_contextAttributes.getAttributeEntrySet()); + dump(out,indent,Collections.singletonList(new CLDump(getClassLoader())),TypeUtil.asList(getHandlers()),getBeans(),_initParams.entrySet(), _attributes.getAttributeEntrySet(),_contextAttributes.getAttributeEntrySet()); } + + /* ------------------------------------------------------------ */ public Context getServletContext() { @@ -1913,4 +1918,39 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. } + + private static class CLDump implements Dumpable + { + final ClassLoader _loader; + CLDump(ClassLoader loader) + { + _loader=loader; + } + + public String dump() + { + return AggregateLifeCycle.dump(this); + } + + public void dump(Appendable out, String indent) throws IOException + { + out.append(String.valueOf(_loader)).append("\n"); + + if (_loader!=null) + { + Object parent = _loader.getParent(); + if (parent!=null) + { + if (!(parent instanceof Dumpable)) + parent=new CLDump((ClassLoader)parent); + + if (_loader instanceof URLClassLoader) + AggregateLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent)); + else + AggregateLifeCycle.dump(out,indent,Collections.singleton(parent)); + } + } + } + + } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java index 5c8229ae4e9..1f3a132c2af 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java @@ -71,6 +71,7 @@ public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest "Host: " + hostPort + "\r\n" + "\r\n"; Socket socket = newSocket(); + socket.setSoTimeout(30000); try { OutputStream output = socket.getOutputStream(); @@ -499,7 +500,7 @@ public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest while ((read = input.read()) >= 0) baos.write(read); baos.close(); - + ServletOutputStream output = httpResponse.getOutputStream(); output.println(builder.toString()); output.write(baos.toByteArray()); diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java index 0d6bdde6724..bef03e29e15 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java @@ -22,6 +22,7 @@ import org.eclipse.jetty.server.DispatcherType; import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; @@ -267,4 +268,9 @@ public class FilterMapping implements Dumpable out.append(String.valueOf(this)).append("\n"); } + /* ------------------------------------------------------------ */ + public String dump() + { + return AggregateLifeCycle.dump(this); + } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java index 3bd3d9f4557..7a92894b5d8 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java @@ -259,6 +259,12 @@ public class Holder extends AbstractLifeCycle implements Dumpable out.append(_name).append("==").append(_className).append("\n"); AggregateLifeCycle.dump(out,indent,_initParams.entrySet()); } + + /* ------------------------------------------------------------ */ + public String dump() + { + return AggregateLifeCycle.dump(this); + } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java index 3b211c9cb55..44b5cd0315f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java @@ -8,8 +8,6 @@ import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import javax.naming.Binding; -import javax.naming.Reference; import org.eclipse.jetty.util.log.Log; @@ -182,11 +180,17 @@ public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable /* ------------------------------------------------------------ */ public String dump() + { + return dump(this); + } + + /* ------------------------------------------------------------ */ + public static String dump(Dumpable dumpable) { StringBuilder b = new StringBuilder(); try { - dump(b,""); + dumpable.dump(b,""); } catch (IOException e) { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Dumpable.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Dumpable.java index 1fdd5740dc8..061d29225ca 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Dumpable.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Dumpable.java @@ -4,5 +4,6 @@ import java.io.IOException; public interface Dumpable { + String dump(); void dump(Appendable out,String indent) throws IOException; } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index b0e9879a3aa..0b0821656c8 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -31,6 +31,9 @@ import java.util.StringTokenizer; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.component.AggregateLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; @@ -54,7 +57,7 @@ import org.eclipse.jetty.util.resource.ResourceCollection; * classloader that loaded this class is used as the parent. * */ -public class WebAppClassLoader extends URLClassLoader +public class WebAppClassLoader extends URLClassLoader { private final Context _context; private final ClassLoader _parent; @@ -433,4 +436,5 @@ public class WebAppClassLoader extends URLClassLoader { return "WebAppClassLoader=" + _name+"@"+Long.toHexString(hashCode()); } + }