]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add heartbeat interval to DeploymentConfiguration, include in bootstrap config (...
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 20 Aug 2012 09:22:27 +0000 (12:22 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Tue, 21 Aug 2012 11:44:22 +0000 (14:44 +0300)
client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
server/src/com/vaadin/terminal/DeploymentConfiguration.java
server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java
server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java
server/src/com/vaadin/terminal/gwt/server/Constants.java

index eea60b04ea3bfdf98b26aaf5dc87ff0f88555c12..c3bf3f8b443bf01441fb4d1145f5fa53b59f3aec 100644 (file)
@@ -204,6 +204,7 @@ public class ApplicationConfiguration implements EntryPoint {
     private ErrorMessage communicationError;
     private ErrorMessage authorizationError;
     private boolean useDebugIdInDom = true;
+    private int heartbeatInterval;
 
     private HashMap<Integer, String> unknownComponents;
 
@@ -289,6 +290,10 @@ public class ApplicationConfiguration implements EntryPoint {
         return rootId;
     }
 
+    public int getHeartbeatInterval() {
+        return heartbeatInterval;
+    }
+
     public JavaScriptObject getVersionInfoJSObject() {
         return getJsoConfiguration(id).getVersionInfoJSObject();
     }
@@ -319,6 +324,9 @@ public class ApplicationConfiguration implements EntryPoint {
         // null -> false
         standalone = jsoConfiguration.getConfigBoolean("standalone") == Boolean.TRUE;
 
+        heartbeatInterval = jsoConfiguration
+                .getConfigInteger("heartbeatInterval");
+
         communicationError = jsoConfiguration.getConfigError("comErrMsg");
         authorizationError = jsoConfiguration.getConfigError("authErrMsg");
 
index 14a5a3724fc6b6ab60260aa856e05dc3a5bdacda..550bfdb7cf42b35d644582d3670de5674179cda2 100644 (file)
@@ -153,4 +153,11 @@ public interface DeploymentConfiguration extends Serializable {
      * @return The resource cache time.
      */
     public int getResourceCacheTime();
+
+    /**
+     * Returns the number of seconds between heartbeat requests of a root.
+     * 
+     * @return
+     */
+    public int getHeartbeatInterval();
 }
index ad5acad5e90e52e9ab2241bb98d64ba839964a91..3e7f1eaf71df93121646292a0b52196798d1cbdd 100644 (file)
@@ -33,6 +33,7 @@ public abstract class AbstractDeploymentConfiguration implements
     private boolean productionMode;
     private boolean xsrfProtectionEnabled;
     private int resourceCacheTime;
+    private int heartbeatInterval;
 
     public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass,
             Properties applicationProperties) {
@@ -42,12 +43,12 @@ public abstract class AbstractDeploymentConfiguration implements
         checkProductionMode();
         checkXsrfProtection();
         checkResourceCacheTime();
+        checkHeartbeatInterval();
     }
 
     @Override
     public String getApplicationOrSystemProperty(String propertyName,
             String defaultValue) {
-
         String val = null;
 
         // Try application properties
@@ -178,6 +179,11 @@ public abstract class AbstractDeploymentConfiguration implements
         return resourceCacheTime;
     }
 
+    @Override
+    public int getHeartbeatInterval() {
+        return heartbeatInterval;
+    }
+
     /**
      * Log a warning if Vaadin is not running in production mode.
      */
@@ -218,6 +224,18 @@ public abstract class AbstractDeploymentConfiguration implements
         }
     }
 
+    private void checkHeartbeatInterval() {
+        try {
+            heartbeatInterval = Integer
+                    .parseInt(getApplicationOrSystemProperty(
+                            Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "500"));
+        } catch (NumberFormatException e) {
+            getLogger().warning(
+                    Constants.WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC);
+            heartbeatInterval = 500;
+        }
+    }
+
     private Logger getLogger() {
         return Logger.getLogger(getClass().getName());
     }
index fad80cacaa80863222c14b01a456b50b930b8a07..de31e4e779046b8ee5692621163258bb2f5110b5 100644 (file)
@@ -170,8 +170,8 @@ public abstract class BootstrapHandler implements RequestHandler {
             Map<String, Object> headers = new LinkedHashMap<String, Object>();
             Document document = Document.createShell("");
             BootstrapPageResponse pageResponse = new BootstrapPageResponse(
-                    this, request, context.getApplication(), context.getRootId(), document,
-                    headers);
+                    this, request, context.getApplication(),
+                    context.getRootId(), document, headers);
             List<Node> fragmentNodes = fragmentResponse.getFragmentNodes();
             Element body = document.body();
             for (Node node : fragmentNodes) {
@@ -274,8 +274,8 @@ public abstract class BootstrapHandler implements RequestHandler {
     public BootstrapContext createContext(WrappedRequest request,
             WrappedResponse response, Application application, Integer rootId) {
         BootstrapContext context = new BootstrapContext(response,
-                new BootstrapFragmentResponse(this, request,
-                        application, rootId, new ArrayList<Node>()));
+                new BootstrapFragmentResponse(this, request, application,
+                        rootId, new ArrayList<Node>()));
         return context;
     }
 
@@ -500,6 +500,9 @@ public abstract class BootstrapHandler implements RequestHandler {
             defaults.put("standalone", true);
         }
 
+        defaults.put("heartbeatInterval",
+                deploymentConfiguration.getHeartbeatInterval());
+
         defaults.put("appUri", getAppUri(context));
 
         return defaults;
index 78c043da694cf9bea2875812b0a497d09b52b878..a04288055e886764dd5be3709002085b24e25662 100644 (file)
@@ -41,6 +41,12 @@ public interface Constants {
             + "in web.xml. The default of 1h will be used.\n"
             + "===========================================================";
 
+    static final String WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC = "\n"
+            + "===========================================================\n"
+            + "WARNING: heartbeatInterval has been set to a non integer value "
+            + "in web.xml. The default of 5min will be used.\n"
+            + "===========================================================";
+
     static final String WIDGETSET_MISMATCH_INFO = "\n"
             + "=================================================================\n"
             + "The widgetset in use does not seem to be built for the Vaadin\n"
@@ -58,6 +64,7 @@ public interface Constants {
     static final String SERVLET_PARAMETER_PRODUCTION_MODE = "productionMode";
     static final String SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION = "disable-xsrf-protection";
     static final String SERVLET_PARAMETER_RESOURCE_CACHE_TIME = "resourceCacheTime";
+    static final String SERVLET_PARAMETER_HEARTBEAT_RATE = "heartbeatRate";
 
     // Configurable parameter names
     static final String PARAMETER_VAADIN_RESOURCES = "Resources";