aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>2006-12-27 15:05:05 +0000
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>2006-12-27 15:05:05 +0000
commitb8f27cd5de4ffe8c000581e6bac3816a92dd4dbe (patch)
tree30d0cbf6b5b9008c9e7199d9067152f1e14c06fa
parent1ef0e254974c5f079da5a1b25bdb6ae4c030fbe2 (diff)
downloadvaadin-framework-b8f27cd5de4ffe8c000581e6bac3816a92dd4dbe.tar.gz
vaadin-framework-b8f27cd5de4ffe8c000581e6bac3816a92dd4dbe.zip
Fixed bugs found in license mechanism testing
Implemented server-wide active users check svn changeset:164/svn branch:toolkit
-rw-r--r--src/com/itmill/toolkit/terminal/web/ApplicationServlet.java40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
index 47bfdab597..7ed8432ee2 100644
--- a/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
+++ b/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
@@ -168,6 +168,9 @@ public class ApplicationServlet extends HttpServlet implements
private static int SERVER_COMMAND_STREAM_MAINTAIN_PERIOD = 15000;
private static int SERVER_COMMAND_HEADER_PADDING = 2000;
+
+ // Maximum delay between request for an user to be considered active (in ms)
+ private static long ACTIVE_USER_REQUEST_INTERVAL = 1000 * 45;
// Private fields
private Class applicationClass;
@@ -192,7 +195,7 @@ public class ApplicationServlet extends HttpServlet implements
private WeakHashMap applicationToServerCommandStreamLock = new WeakHashMap();
- private WeakHashMap applicationToLastRequestDate = new WeakHashMap();
+ private static WeakHashMap applicationToLastRequestDate = new WeakHashMap();
private List allWindows = new LinkedList();
@@ -200,6 +203,8 @@ public class ApplicationServlet extends HttpServlet implements
private HashMap licenseForApplicationClass = new HashMap();
+ private static HashSet licensePrintedForApplicationClass = new HashSet();
+
/**
* Called by the servlet container to indicate to a servlet that the servlet
* is being placed into service.
@@ -1235,12 +1240,16 @@ public class ApplicationServlet extends HttpServlet implements
}
}
- // TODO Should we only print this once?
- System.out.print(license.getDescription());
+ // For each application class, print license description - once
+ if (!licensePrintedForApplicationClass.contains(applicationClass)) {
+ licensePrintedForApplicationClass.add(applicationClass);
+ if (license.shouldLimitsBePrintedOnInit())
+ System.out.print(license.getDescription());
+ }
- // TODO Add concurrent users check
+ // Check license validity
try {
- license.check(applicationClass, 1, VERSION_MAJOR,
+ license.check(applicationClass, getNumberOfActiveUsers()+1, VERSION_MAJOR,
VERSION_MINOR, "IT Mill Toolkit", null);
} catch (LicenseFileHasNotBeenRead e) {
application.close();
@@ -1256,6 +1265,27 @@ public class ApplicationServlet extends HttpServlet implements
throw e;
}
}
+
+ /** Get the number of active application-user pairs.
+ *
+ * This returns total number of all applications in the server that are considered to be active. For
+ * an application to be active, it must have been accessed less than ACTIVE_USER_REQUEST_INTERVAL ms.
+ *
+ * @return Number of active application instances in the server.
+ */
+ private int getNumberOfActiveUsers() {
+
+ Set apps = applicationToLastRequestDate.keySet();
+ int active = 0;
+ long now = System.currentTimeMillis();
+ for (Iterator i=apps.iterator(); i.hasNext();) {
+ Date lastReq = (Date) applicationToLastRequestDate.get(i.next());
+ if (now - lastReq.getTime() < ACTIVE_USER_REQUEST_INTERVAL)
+ active++;
+ }
+
+ return active;
+ }
/** End application */
private void endApplication(HttpServletRequest request,