FELIX-2199 Extract built-in ConfigurationPrinter classes as top level classes
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@922604 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
index e2fcebb..606c20d 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
@@ -245,11 +245,6 @@
if ( cfgPrinterTrackerCount != cfgPrinterTracker.getTrackingCount() )
{
SortedMap cp = new TreeMap();
-
- // add provided printers
- addConfigurationPrinter( cp, new SystemPropertiesPrinter(), SystemPropertiesPrinter.LABEL, null );
- addConfigurationPrinter( cp, new ThreadPrinter(), ThreadPrinter.LABEL, null );
-
ServiceReference[] refs = cfgPrinterTracker.getServiceReferences();
if ( refs != null )
{
@@ -409,125 +404,6 @@
return title;
}
- private static class SystemPropertiesPrinter implements ConfigurationPrinter
- {
-
- private static final String TITLE = "System Properties";
-
- static final String LABEL = "_systemproperties";
-
-
- public String getTitle()
- {
- return TITLE;
- }
-
-
- public void printConfiguration( PrintWriter printWriter )
- {
- Properties props = System.getProperties();
- SortedSet keys = new TreeSet( props.keySet() );
- for ( Iterator ki = keys.iterator(); ki.hasNext(); )
- {
- Object key = ki.next();
- infoLine( printWriter, null, ( String ) key, props.get( key ) );
- }
-
- }
-
- }
-
- private static class ThreadPrinter implements ConfigurationPrinter
- {
-
- private static final String TITLE = "Threads";
-
- static final String LABEL = "_threads";
-
-
- public String getTitle()
- {
- return TITLE;
- }
-
-
- public void printConfiguration( PrintWriter pw )
- {
- // first get the root thread group
- ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
- while ( rootGroup.getParent() != null )
- {
- rootGroup = rootGroup.getParent();
- }
-
- printThreadGroup( pw, rootGroup );
-
- int numGroups = rootGroup.activeGroupCount();
- ThreadGroup[] groups = new ThreadGroup[2 * numGroups];
- rootGroup.enumerate( groups );
- for ( int i = 0; i < groups.length; i++ )
- {
- printThreadGroup( pw, groups[i] );
- }
- }
-
- private static final void printThreadGroup( PrintWriter pw, ThreadGroup group )
- {
- if ( group != null )
- {
- StringBuffer info = new StringBuffer();
- info.append( "ThreadGroup " ).append( group.getName() );
- info.append( " [" );
- info.append( "maxprio=" ).append( group.getMaxPriority() );
-
- info.append( ", parent=" );
- if ( group.getParent() != null )
- {
- info.append( group.getParent().getName() );
- }
- else
- {
- info.append( '-' );
- }
-
- info.append( ", isDaemon=" ).append( group.isDaemon() );
- info.append( ", isDestroyed=" ).append( group.isDestroyed() );
- info.append( ']' );
-
- infoLine( pw, null, null, info.toString() );
-
- int numThreads = group.activeCount();
- Thread[] threads = new Thread[numThreads * 2];
- group.enumerate( threads, false );
- for ( int i = 0; i < threads.length; i++ )
- {
- printThread( pw, threads[i] );
- }
-
- pw.println();
- }
- }
-
-
- private static final void printThread( PrintWriter pw, Thread thread )
- {
- if ( thread != null )
- {
- StringBuffer info = new StringBuffer();
- info.append( "Thread " ).append( thread.getName() );
- info.append( " [" );
- info.append( "priority=" ).append( thread.getPriority() );
- info.append( ", alive=" ).append( thread.isAlive() );
- info.append( ", daemon=" ).append( thread.isDaemon() );
- info.append( ", interrupted=" ).append( thread.isInterrupted() );
- info.append( ", loader=" ).append( thread.getContextClassLoader() );
- info.append( ']' );
-
- infoLine( pw, " ", null, info.toString() );
- }
- }
- }
-
private abstract static class ConfigurationWriter extends PrintWriter
{
@@ -542,10 +418,11 @@
abstract void end();
- public void handleAttachments(final String title, final URL[] urls)
- throws IOException
+
+ public void handleAttachments( final String title, final URL[] urls ) throws IOException
{
- throw new UnsupportedOperationException("handleAttachments not supported by this configuration writer: " + this);
+ throw new UnsupportedOperationException( "handleAttachments not supported by this configuration writer: "
+ + this );
}
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java
new file mode 100644
index 0000000..dbd71c6
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.internal.misc;
+
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
+
+
+public class SystemPropertiesPrinter extends AbstractConfigurationPrinter
+{
+
+ private static final String TITLE = "System Properties";
+
+ private static final String LABEL = "_systemproperties";
+
+
+ public String getTitle()
+ {
+ return TITLE;
+ }
+
+
+ public void printConfiguration( PrintWriter printWriter )
+ {
+ Properties props = System.getProperties();
+ SortedSet keys = new TreeSet( props.keySet() );
+ for ( Iterator ki = keys.iterator(); ki.hasNext(); )
+ {
+ Object key = ki.next();
+ ConfigurationRender.infoLine( printWriter, null, ( String ) key, props.get( key ) );
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ThreadPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ThreadPrinter.java
new file mode 100644
index 0000000..2ea8f35
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ThreadPrinter.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.internal.misc;
+
+
+import java.io.PrintWriter;
+
+import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
+
+
+public class ThreadPrinter extends AbstractConfigurationPrinter
+{
+
+ private static final String TITLE = "Threads";
+
+ private static final String LABEL = "_threads";
+
+
+ public String getTitle()
+ {
+ return TITLE;
+ }
+
+
+ public void printConfiguration( PrintWriter pw )
+ {
+ // first get the root thread group
+ ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
+ while ( rootGroup.getParent() != null )
+ {
+ rootGroup = rootGroup.getParent();
+ }
+
+ printThreadGroup( pw, rootGroup );
+
+ int numGroups = rootGroup.activeGroupCount();
+ ThreadGroup[] groups = new ThreadGroup[2 * numGroups];
+ rootGroup.enumerate( groups );
+ for ( int i = 0; i < groups.length; i++ )
+ {
+ printThreadGroup( pw, groups[i] );
+ }
+ }
+
+
+ private static final void printThreadGroup( PrintWriter pw, ThreadGroup group )
+ {
+ if ( group != null )
+ {
+ StringBuffer info = new StringBuffer();
+ info.append( "ThreadGroup " ).append( group.getName() );
+ info.append( " [" );
+ info.append( "maxprio=" ).append( group.getMaxPriority() );
+
+ info.append( ", parent=" );
+ if ( group.getParent() != null )
+ {
+ info.append( group.getParent().getName() );
+ }
+ else
+ {
+ info.append( '-' );
+ }
+
+ info.append( ", isDaemon=" ).append( group.isDaemon() );
+ info.append( ", isDestroyed=" ).append( group.isDestroyed() );
+ info.append( ']' );
+
+ ConfigurationRender.infoLine( pw, null, null, info.toString() );
+
+ int numThreads = group.activeCount();
+ Thread[] threads = new Thread[numThreads * 2];
+ group.enumerate( threads, false );
+ for ( int i = 0; i < threads.length; i++ )
+ {
+ printThread( pw, threads[i] );
+ }
+
+ pw.println();
+ }
+ }
+
+
+ private static final void printThread( PrintWriter pw, Thread thread )
+ {
+ if ( thread != null )
+ {
+ StringBuffer info = new StringBuffer();
+ info.append( "Thread " ).append( thread.getName() );
+ info.append( " [" );
+ info.append( "priority=" ).append( thread.getPriority() );
+ info.append( ", alive=" ).append( thread.isAlive() );
+ info.append( ", daemon=" ).append( thread.isDaemon() );
+ info.append( ", interrupted=" ).append( thread.isInterrupted() );
+ info.append( ", loader=" ).append( thread.getContextClassLoader() );
+ info.append( ']' );
+
+ ConfigurationRender.infoLine( pw, " ", null, info.toString() );
+ }
+ }
+}
\ No newline at end of file