From: Johannes Dahlström Date: Mon, 20 Aug 2012 09:22:27 +0000 (+0300) Subject: Add heartbeat interval to DeploymentConfiguration, include in bootstrap config (... X-Git-Tag: 7.0.0.beta1~220^2~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3741529097e52114b526fb1598d6d4f70be49b2b;p=vaadin-framework.git Add heartbeat interval to DeploymentConfiguration, include in bootstrap config (#9265) --- diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index eea60b04ea..c3bf3f8b44 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -204,6 +204,7 @@ public class ApplicationConfiguration implements EntryPoint { private ErrorMessage communicationError; private ErrorMessage authorizationError; private boolean useDebugIdInDom = true; + private int heartbeatInterval; private HashMap 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"); diff --git a/server/src/com/vaadin/terminal/DeploymentConfiguration.java b/server/src/com/vaadin/terminal/DeploymentConfiguration.java index 14a5a3724f..550bfdb7cf 100644 --- a/server/src/com/vaadin/terminal/DeploymentConfiguration.java +++ b/server/src/com/vaadin/terminal/DeploymentConfiguration.java @@ -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(); } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java index ad5acad5e9..3e7f1eaf71 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java @@ -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()); } diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java index fad80cacaa..de31e4e779 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java @@ -170,8 +170,8 @@ public abstract class BootstrapHandler implements RequestHandler { Map headers = new LinkedHashMap(); 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 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())); + new BootstrapFragmentResponse(this, request, application, + rootId, new ArrayList())); 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; diff --git a/server/src/com/vaadin/terminal/gwt/server/Constants.java b/server/src/com/vaadin/terminal/gwt/server/Constants.java index 78c043da69..a04288055e 100644 --- a/server/src/com/vaadin/terminal/gwt/server/Constants.java +++ b/server/src/com/vaadin/terminal/gwt/server/Constants.java @@ -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";