FELIX-1607 - Start implementing timeline.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818477 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
index 3d81fd4..2ff7402 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventCollector.java
@@ -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;
+ }
}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
index ec611bf..07d9e52 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventHandler.java
@@ -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));
}
}
}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
index 8eb75ef..3e1405a 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/EventInfo.java
@@ -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;
}
}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
index 220d0b4..422afab 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
@@ -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>" );
}
-
- private void eventJson( JSONWriter jw, EventInfo info, int index ) throws JSONException
+ 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, 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" );
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
index ac2eb80..f2a5a80 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/BundleEventConverter.java
@@ -75,6 +75,6 @@
return null; // IGNORE
}
- return new EventInfo(topic.toString(), buffer.toString());
+ return new EventInfo(topic.toString(), buffer.toString(), "bundle");
}
}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
index 52f99b4..0481441 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/FrameworkEventConverter.java
@@ -62,6 +62,6 @@
return null; // IGNORE
}
- return new EventInfo(topic.toString(), buffer.toString());
+ return new EventInfo(topic.toString(), buffer.toString(), "framework");
}
}
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
index 5b40b0a..04230c5 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ServiceEventConverter.java
@@ -84,6 +84,6 @@
return null; // IGNORE
}
- return new EventInfo(topic.toString(), buffer.toString());
+ return new EventInfo(topic.toString(), buffer.toString(), "service");
}
}
diff --git a/webconsole-plugins/event/src/main/resources/res/ui/events.js b/webconsole-plugins/event/src/main/resources/res/ui/events.js
index 2d043af..e3b8ef2 100644
--- a/webconsole-plugins/event/src/main/resources/res/ui/events.js
+++ b/webconsole-plugins/event/src/main/resources/res/ui/events.js
@@ -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 */