FELIX-790 - Start support for condensed event reporting.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@708233 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/EventAdminServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/EventAdminServlet.java
index 14676eb..2a3a975 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/EventAdminServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/EventAdminServlet.java
@@ -30,6 +30,7 @@
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.json.JSONException;
import org.json.JSONWriter;
+import org.osgi.framework.*;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.*;
@@ -53,7 +54,16 @@
/** Number of events to be displayed. */
private int maxSize = 50;
- protected final List events = new ArrayList();
+ private final List events = new ArrayList();
+
+ /** Custom event renderers hashed by topic. */
+ private final Map eventRenderers = new HashMap();
+
+ public EventAdminServlet()
+ {
+ eventRenderers.put(ServiceEvent.class.getName().replace('.', '/') + "/", new ServiceEventInfoProvider());
+ eventRenderers.put(BundleEvent.class.getName().replace('.', '/') + "/", new BundleEventInfoProvider());
+ }
public String getLabel()
{
@@ -221,6 +231,19 @@
throws JSONException
{
final Event e = info.event;
+
+ // check if we have an info provider
+ final Iterator iter = this.eventRenderers.entrySet().iterator();
+ String infoText = null;
+ while ( infoText == null && iter.hasNext() )
+ {
+ final Map.Entry entry = (Map.Entry) iter.next();
+ if ( e.getTopic().startsWith(entry.getKey().toString()) )
+ {
+ infoText = ((EventInfoProvider)entry.getValue()).getInfo(e);
+ }
+ }
+
jw.object();
jw.key( "id" );
jw.value( String.valueOf(index) );
@@ -228,6 +251,11 @@
jw.value( info.received );
jw.key( "topic" );
jw.value( e.getTopic());
+ if ( infoText != null )
+ {
+ jw.key( "info" );
+ jw.value( infoText );
+ }
jw.key( "properties" );
jw.object();
final String[] names = e.getPropertyNames();
@@ -256,4 +284,97 @@
this.received = System.currentTimeMillis();
}
}
+
+ private static interface EventInfoProvider
+ {
+ String getInfo(Event event);
+ }
+
+ private static final class ServiceEventInfoProvider implements EventInfoProvider
+ {
+
+ /**
+ * @see org.apache.felix.webconsole.internal.misc.EventAdminServlet.EventInfoProvider#getInfo(org.osgi.service.event.Event)
+ */
+ public String getInfo(Event event)
+ {
+ final ServiceEvent serviceEvent = (ServiceEvent) event.getProperty(EventConstants.EVENT);
+ if ( serviceEvent == null )
+ {
+ return null;
+ }
+ final StringBuffer buffer = new StringBuffer("Service ");
+ buffer.append(serviceEvent.getServiceReference().getProperty(Constants.SERVICE_ID));
+ buffer.append(' ');
+ switch (serviceEvent.getType())
+ {
+ case ServiceEvent.REGISTERED:
+ buffer.append("registered");
+ break;
+ case ServiceEvent.MODIFIED:
+ buffer.append("modified");
+ break;
+ case ServiceEvent.UNREGISTERING:
+ buffer.append("unregistering");
+ break;
+ default:
+ return null; // IGNOREE
+ }
+
+ return buffer.toString();
+ }
+ }
+
+ private static final class BundleEventInfoProvider implements EventInfoProvider
+ {
+
+ /**
+ * @see org.apache.felix.webconsole.internal.misc.EventAdminServlet.EventInfoProvider#getInfo(org.osgi.service.event.Event)
+ */
+ public String getInfo(Event event)
+ {
+ final BundleEvent bundleEvent = (BundleEvent) event.getProperty(EventConstants.EVENT);
+ if ( bundleEvent == null )
+ {
+ return null;
+ }
+ final StringBuffer buffer = new StringBuffer("Bundle ");
+ buffer.append(bundleEvent.getBundle().getSymbolicName());
+ buffer.append(' ');
+ switch (bundleEvent.getType())
+ {
+ case BundleEvent.INSTALLED:
+ buffer.append("installed");
+ break;
+ case BundleEvent.RESOLVED:
+ buffer.append("resolved");
+ break;
+ case BundleEvent.STARTED:
+ buffer.append("started");
+ break;
+ case BundleEvent.STARTING:
+ buffer.append("starting");
+ break;
+ case BundleEvent.STOPPED:
+ buffer.append("stopped");
+ break;
+ case BundleEvent.STOPPING:
+ buffer.append("stopping");
+ break;
+ case BundleEvent.UNINSTALLED:
+ buffer.append("uninstalled");
+ break;
+ case BundleEvent.UNRESOLVED:
+ buffer.append("unresolved");
+ break;
+ case BundleEvent.UPDATED:
+ buffer.append("updated");
+ break;
+ default:
+ return null; // IGNOREE
+ }
+
+ return buffer.toString();
+ }
+ }
}
diff --git a/webconsole/src/main/resources/res/ui/events.js b/webconsole/src/main/resources/res/ui/events.js
index b2dd3f2..0941314 100644
--- a/webconsole/src/main/resources/res/ui/events.js
+++ b/webconsole/src/main/resources/res/ui/events.js
@@ -75,16 +75,22 @@
parent.appendChild( td( null, null, [ text( new Date(dataEntry.received) ) ] ) );
parent.appendChild( td( null, null, [ text( topic ) ] ) );
- var tableE = createElement("table");
- var bodyE = createElement("tbody");
- tableE.appendChild(bodyE);
-
- for( var p in dataEntry.properties ) {
- bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
- td(null, null, [text(dataEntry.properties[p])])]));
+ var propE;
+ if ( dataEntry.info ) {
+ propE = text(dataEntry.info);
+ } else {
+ var tableE = createElement("table");
+ var bodyE = createElement("tbody");
+ tableE.appendChild(bodyE);
+
+ for( var p in dataEntry.properties ) {
+ bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
+ td(null, null, [text(dataEntry.properties[p])])]));
+ }
+ propE = tableE;
}
- parent.appendChild( td( null, null, [tableE] ) );
+ parent.appendChild( td( null, null, [propE] ) );
}
function loadData() {