Author: cziegeler
Date: Fri Jan 28 17:32:53 2011
New Revision: 1064788
URL: http://svn.apache.org/viewvc?rev=1064788&view=rev
Log:
SLING-1962 : Record time of action and display it in the web console
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1064788&r1=1064787&r2=1064788&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
Fri Jan 28 17:32:53 2011
@@ -46,7 +46,7 @@ public class RegisteredResourceImpl
private static final long serialVersionUID = 6L;
/** Serialization version. */
- private static final int VERSION = 1;
+ private static final int VERSION = 2;
/** The resource url. */
private final String url;
@@ -80,6 +80,9 @@ public class RegisteredResourceImpl
private boolean cleanedUp = false;
+ /** When was the last status change? */
+ private long lastChange = -1;
+
/**
* Serialize the object
* - write version id
@@ -100,6 +103,7 @@ public class RegisteredResourceImpl
out.writeObject(resourceType);
out.writeInt(priority);
out.writeObject(state.toString());
+ out.writeLong(this.lastChange);
}
/**
@@ -110,7 +114,7 @@ public class RegisteredResourceImpl
private void readObject(final java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
final int version = in.readInt();
- if ( version != VERSION ) {
+ if ( version < 1 || version > VERSION ) {
throw new ClassNotFoundException(this.getClass().getName());
}
Util.setField(this, "url", in.readObject());
@@ -123,6 +127,11 @@ public class RegisteredResourceImpl
Util.setField(this, "resourceType", in.readObject());
Util.setField(this, "priority", in.readInt());
this.state = ResourceState.valueOf((String) in.readObject());
+ if ( version > 1 ) {
+ this.lastChange = in.readLong();
+ } else {
+ this.lastChange = 0;
+ }
}
/**
@@ -305,13 +314,22 @@ public class RegisteredResourceImpl
}
/**
- *Set the state for the resource.
+ * Set the state for the resource.
*/
public void setState(ResourceState s) {
+ this.lastChange = System.currentTimeMillis();
this.state = s;
}
/**
+ * When did the last change happen?
+ * @return -1 if no change , 0 if unknown, > 0 otherwise
+ */
+ public long getLastChange() {
+ return this.lastChange;
+ }
+
+ /**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1064788&r1=1064787&r2=1064788&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
Fri Jan 28 17:32:53 2011
@@ -20,10 +20,13 @@ package org.apache.sling.installer.core.
import java.io.IOException;
import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -34,10 +37,12 @@ import javax.servlet.ServletResponse;
import org.apache.sling.installer.api.InstallableResource;
import org.apache.sling.installer.api.tasks.RegisteredResource;
+import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.apache.sling.installer.core.impl.Activator;
import org.apache.sling.installer.core.impl.EntityResourceList;
import org.apache.sling.installer.core.impl.OsgiInstallerImpl;
+import org.apache.sling.installer.core.impl.RegisteredResourceImpl;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -150,6 +155,20 @@ public class OsgiInstallerWebConsolePlug
return id;
}
+ /** Default date format used. */
+ private final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSS
yyyy-MMM-dd");
+
+ /**
+ * Format a date
+ */
+ private synchronized String formatDate(final long time) {
+ if ( time == -1 ) {
+ return "-";
+ }
+ final Date d = new Date(time);
+ return dateFormat.format(d);
+ }
+
@Override
public void service(ServletRequest req, ServletResponse res)
throws IOException {
@@ -201,11 +220,23 @@ public class OsgiInstallerWebConsolePlug
pw.printf("<tr><th>Entity
ID</th><th>Digest</th><th>URL</th><th>State</th></tr>");
rt = first.getType();
}
-
pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
- getEntityId(first),
- first.getDigest(),
- first.getURL(),
- first.getState());
+ pw.print("<tr><td>");
+ pw.print(getEntityId(first));
+ pw.print("</td><td>");
+ pw.print(first.getDigest());
+ pw.print("</td><td>");
+ pw.print(first.getURL());
+ pw.print("</td><td>");
+ pw.print(first.getState());
+ if ( first.getState() == ResourceState.INSTALLED ) {
+ final long lastChange =
((RegisteredResourceImpl)first).getLastChange();
+ if ( lastChange > 0 ) {
+ pw.print("<br/>");
+ pw.print(formatDate(lastChange));
+ }
+ }
+ pw.print("</td></tr>");
+
while ( iter.hasNext() ) {
final TaskResource resource = iter.next();
pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>",