You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2009/09/24 15:25:26 UTC

svn commit: r818477 - in /felix/trunk/webconsole-plugins/event/src/main: java/org/apache/felix/webconsole/plugins/event/internal/ java/org/apache/felix/webconsole/plugins/event/internal/converter/ resources/res/ui/

Author: cziegeler
Date: Thu Sep 24 13:25:25 2009
New Revision: 818477

URL: http://svn.apache.org/viewvc?rev=818477&view=rev
Log:
FELIX-1607 - Start implementing timeline.

Modified:
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
    felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
    felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java Thu Sep 24 13:25:25 2009
@@ -27,20 +27,23 @@
     private static final String PROPERTY_MAX_SIZE = "max.size";
     private static final int DEFAULT_MAX_SIZE = 250;
 
-    private List eventInfos = new ArrayList();
+    private List eventInfos;
+
+    private long startTime;
 
     private int maxSize;
 
     public EventCollector(final Dictionary props)
     {
-        updateConfiguration(props);
+        this.clear();
+        this.updateConfiguration(props);
     }
 
     public void add(final EventInfo info)
     {
         if ( info != null )
         {
-            synchronized ( this.eventInfos )
+            synchronized ( this )
             {
                 this.eventInfos.add( info );
                 if ( eventInfos.size() > this.maxSize )
@@ -53,9 +56,10 @@
 
     public void clear()
     {
-        synchronized ( this.eventInfos )
+        synchronized ( this )
         {
             this.eventInfos = new ArrayList();
+            this.startTime = System.currentTimeMillis();
         }
     }
 
@@ -64,7 +68,7 @@
      */
     public List getEvents()
     {
-        synchronized ( this.eventInfos )
+        synchronized ( this )
         {
             return new ArrayList(eventInfos);
         }
@@ -73,7 +77,8 @@
     public void updateConfiguration( final Dictionary props)
     {
         this.maxSize = OsgiUtil.toInteger(props, PROPERTY_MAX_SIZE, DEFAULT_MAX_SIZE);
-        synchronized ( this.eventInfos ) {
+        synchronized ( this )
+        {
             while ( eventInfos.size() > this.maxSize )
             {
                 eventInfos.remove( 0 );
@@ -81,4 +86,9 @@
 
         }
     }
+
+    public long getStartTime()
+    {
+        return this.startTime;
+    }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java Thu Sep 24 13:25:25 2009
@@ -72,7 +72,7 @@
                     props.put(names[i], event.getProperty(names[i]));
                 }
             }
-            collector.add(new EventInfo(event.getTopic(), null, props));
+            collector.add(new EventInfo(event.getTopic(), null, null, props));
         }
     }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java Thu Sep 24 13:25:25 2009
@@ -39,19 +39,24 @@
     /** Properties. */
     public final Map properties;
 
-    public EventInfo( final String topic, final String info )
+    /** The event class. */
+    public final String category;
+
+    public EventInfo( final String topic, final String info, final String category )
     {
         this.topic = topic;
         this.info = info;
         this.received = System.currentTimeMillis();
         this.properties = null;
+        this.category = category;
     }
 
-    public EventInfo( final String topic, final String info, final Map props )
+    public EventInfo( final String topic, final String info, final String category, final Map props )
     {
         this.topic = topic;
         this.info = info;
         this.received = System.currentTimeMillis();
         this.properties = props;
+        this.category = category;
     }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java Thu Sep 24 13:25:25 2009
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URL;
 import java.util.*;
 import java.util.Map.Entry;
 
@@ -99,6 +100,15 @@
         }
         statusLine.append( "." );
 
+        // Compute scale: startTime is 0, lastTimestamp is 100%
+        final long startTime = this.collector.getStartTime();
+        long endTime = (events.size() == 0 ? startTime : ((EventInfo)events.get(events.size() - 1)).received);
+        if ( endTime == startTime )
+        {
+            endTime = startTime + 10;
+        }
+        final float scale = 100.0f / (endTime - startTime);
+
         JSONWriter jw = new JSONWriter( pw );
         try
         {
@@ -114,7 +124,7 @@
             // display list in reverse order
             for ( int index = events.size() - 1; index >= 0; index-- )
             {
-                eventJson( jw, ( EventInfo ) events.get( index ), index );
+                eventJson( jw, ( EventInfo ) events.get( index ), index, startTime, scale );
             }
 
             jw.endArray();
@@ -157,7 +167,7 @@
         final PrintWriter pw = response.getWriter();
 
         final String appRoot = ( String ) request.getAttribute( "felix.webconsole.appRoot" );
-        pw.println( "<script src='" + appRoot + "/res/ui/" + "events.js" + "' language='JavaScript'></script>" );
+        pw.println( "<script src='" + appRoot + "/events/res/ui/" + "events.js" + "' language='JavaScript'></script>" );
 
         pw.println( "<div id='plugin_content'/>");
 
@@ -168,12 +178,30 @@
         pw.println( "</script>" );
     }
 
+    public URL getResource(String path)
+    {
+        if ( "/events/res/ui/events.js".equals(path) )
+        {
+            return this.getClass().getResource("/res/ui/events.js");
+        }
+        return null;
+    }
 
-    private void eventJson( JSONWriter jw, EventInfo info, int index ) throws JSONException
+    private void eventJson( JSONWriter jw, EventInfo info, int index, final long start, final float scale )
+    throws JSONException
     {
+        final long msec = info.received - start;
+
+        // Compute color bar size and make sure the bar is visible
+        final int percent = Math.max((int)((msec) * scale), 2);
+
         jw.object();
         jw.key( "id" );
         jw.value( String.valueOf( index ) );
+        jw.key( "width" );
+        jw.value( percent );
+        jw.key( "category" );
+        jw.value( info.category == null ? "" : info.category );
         jw.key( "received" );
         jw.value( info.received );
         jw.key( "topic" );

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java Thu Sep 24 13:25:25 2009
@@ -75,6 +75,6 @@
                 return null; // IGNORE
         }
 
-        return new EventInfo(topic.toString(), buffer.toString());
+        return new EventInfo(topic.toString(), buffer.toString(), "bundle");
     }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java Thu Sep 24 13:25:25 2009
@@ -62,6 +62,6 @@
                 return null; // IGNORE
         }
 
-        return new EventInfo(topic.toString(), buffer.toString());
+        return new EventInfo(topic.toString(), buffer.toString(), "framework");
     }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java (original)
+++ felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java Thu Sep 24 13:25:25 2009
@@ -84,6 +84,6 @@
                 return null; // IGNORE
         }
 
-        return new EventInfo(topic.toString(), buffer.toString());
+        return new EventInfo(topic.toString(), buffer.toString(), "service");
     }
 }

Modified: felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js?rev=818477&r1=818476&r2=818477&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js (original)
+++ felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js Thu Sep 24 13:25:25 2009
@@ -56,9 +56,11 @@
     var id = dataEntry.id;
     var topic = dataEntry.topic;
     var properties = dataEntry.properties;
-
-    parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
-    parent.appendChild( td( null, null, [ text( topic ) ] ) );
+    var styleClass = dataEntry.category;
+    if ( styleClass.length == 0 ) styleClass = null; else styleClass = "event" + styleClass;
+    
+    parent.appendChild( td( styleClass, null, [ text( printDate(dataEntry.received) ) ] ) );
+    parent.appendChild( td( styleClass, null, [ text( topic ) ] ) );
 
     var propE;
     if ( dataEntry.info ) {
@@ -69,10 +71,10 @@
 	    tableE.appendChild(bodyE);
 	
 	    for( var p in dataEntry.properties ) {
-	    	var c1 = td(null, null, [text(p)]);
+	    	var c1 = td(styleClass, null, [text(p)]);
 	    	$(c1).css("border", "0px none");
             $(c1).css("padding", "0 4px 0 0");
-	    	var c2 = td(null, null, [text(dataEntry.properties[p])]);
+	    	var c2 = td(styleClass, null, [text(dataEntry.properties[p])]);
 	    	$(c2).css("border", "0px none");
             $(c2).css("padding", "0 0 0 4px");
 	    	bodyE.appendChild(tr(null, null, [ c1, c2 ]));
@@ -80,7 +82,7 @@
 	    propE = tableE;
     }
     
-    parent.appendChild( td( null, null, [propE] ) );
+    parent.appendChild( td( styleClass, null, [propE] ) );
 }
 
 /* displays a date in the user's local timezone */