diff options
5 files changed, 63 insertions, 17 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index c3bf3f8b44..2771871653 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -290,6 +290,10 @@ public class ApplicationConfiguration implements EntryPoint { return rootId; } + /** + * @return The interval in seconds between heartbeat requests, or a + * non-positive number if heartbeat is disabled. + */ public int getHeartbeatInterval() { return heartbeatInterval; } diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 2a26f7f365..cd90403139 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -230,6 +230,8 @@ public class ApplicationConnection { rootConnector.init(cnf.getRootPanelId(), this); showLoadingIndicator(); + + scheduleHeartbeat(); } /** @@ -2522,19 +2524,23 @@ public class ApplicationConnection { } /** - * Schedules a heartbeat request. + * Schedules a heartbeat request to occur after the configured heartbeat + * interval elapses if the interval is a positive number. Otherwise, does + * nothing. * * @see #sendHeartbeat() + * @see ApplicationConfiguration#getHeartbeatInterval() */ - private void scheduleHeartbeat() { - final int interval = 1000 * getConfiguration().getHeartbeatInterval(); + protected void scheduleHeartbeat() { + final int interval = getConfiguration().getHeartbeatInterval(); if (interval > 0) { + VConsole.log("Scheduling heartbeat in " + interval + " seconds"); new Timer() { @Override public void run() { sendHeartbeat(); } - }.schedule(interval); + }.schedule(interval * 1000); } } @@ -2550,7 +2556,7 @@ public class ApplicationConnection { * @see #scheduleHeartbeat() * @see com.vaadin.ui.Root#heartbeat() */ - private void sendHeartbeat() { + protected void sendHeartbeat() { final String uri = addGetParameters( translateVaadinUri(ApplicationConstants.APP_PROTOCOL_PREFIX + ApplicationConstants.HEARTBEAT_REQUEST_PATH), @@ -2566,6 +2572,7 @@ public class ApplicationConnection { int status = response.getStatusCode(); if (status == Response.SC_OK) { // TODO Permit retry in some error situations + VConsole.log("Heartbeat response OK"); scheduleHeartbeat(); } else { VConsole.error("Heartbeat request failed with status code " @@ -2583,6 +2590,7 @@ public class ApplicationConnection { rb.setCallback(callback); try { + VConsole.log("Sending heartbeat request..."); rb.send(); } catch (RequestException re) { callback.onError(null, re); diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 62052cd3b7..d4768abfb4 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -2448,7 +2448,9 @@ public class Application implements Terminal.ErrorListener, Serializable { /** * Removes all those roots from the application whose last heartbeat * occurred more than {@link #getHeartbeatTimeout()} seconds ago. Close - * events are fired for the removed roots. + * events are fired for the removed roots. If + * <code>getHeartbeatTimeout()</code> returns a nonpositive number, no + * cleanup is performed. * <p> * Called by the framework at the end of every request. * @@ -2459,13 +2461,15 @@ public class Application implements Terminal.ErrorListener, Serializable { * @since 7.0.0 */ public void closeInactiveRoots() { - long now = System.currentTimeMillis(); - for (Iterator<Root> i = roots.values().iterator(); i.hasNext();) { - Root root = i.next(); - if (now - root.getLastHeartbeat() > 1000 * getHeartbeatTimeout()) { - i.remove(); - retainOnRefreshRoots.values().remove(root.getRootId()); - root.fireCloseEvent(); + if (getHeartbeatTimeout() > 0) { + long now = System.currentTimeMillis(); + for (Iterator<Root> i = roots.values().iterator(); i.hasNext();) { + Root root = i.next(); + if (now - root.getLastHeartbeat() > 1000 * getHeartbeatTimeout()) { + i.remove(); + retainOnRefreshRoots.values().remove(root.getRootId()); + root.fireCloseEvent(); + } } } } @@ -2478,7 +2482,8 @@ public class Application implements Terminal.ErrorListener, Serializable { * * @since 7.0.0 * - * @return The heartbeat timeout in seconds. + * @return The heartbeat timeout in seconds or a nonpositive number if + * timeout never occurs. */ public int getHeartbeatTimeout() { // Permit three missed heartbeats before closing the root diff --git a/server/src/com/vaadin/terminal/DeploymentConfiguration.java b/server/src/com/vaadin/terminal/DeploymentConfiguration.java index 550bfdb7cf..8d5686ebbd 100644 --- a/server/src/com/vaadin/terminal/DeploymentConfiguration.java +++ b/server/src/com/vaadin/terminal/DeploymentConfiguration.java @@ -136,6 +136,8 @@ public interface DeploymentConfiguration extends Serializable { /** * Returns whether Vaadin is in production mode. * + * @since 7.0.0 + * * @return true if in production mode, false otherwise. */ public boolean isProductionMode(); @@ -143,6 +145,8 @@ public interface DeploymentConfiguration extends Serializable { /** * Returns whether cross-site request forgery protection is enabled. * + * @since 7.0.0 + * * @return true if XSRF protection is enabled, false otherwise. */ public boolean isXsrfProtectionEnabled(); @@ -150,12 +154,17 @@ public interface DeploymentConfiguration extends Serializable { /** * Returns the time resources can be cached in the browsers, in seconds. * + * @since 7.0.0 + * * @return The resource cache time. */ public int getResourceCacheTime(); /** - * Returns the number of seconds between heartbeat requests of a root. + * Returns the number of seconds between heartbeat requests of a root, or a + * non-negative number if heartbeat is disabled. + * + * @since 7.0.0 * * @return */ diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java index 3e7f1eaf71..1895560209 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java @@ -164,21 +164,41 @@ public abstract class AbstractDeploymentConfiguration implements return addonContext; } + /** + * {@inheritDoc} + * + * The default is false. + */ @Override public boolean isProductionMode() { return productionMode; } + /** + * {@inheritDoc} + * + * The default is true. + */ @Override public boolean isXsrfProtectionEnabled() { return xsrfProtectionEnabled; } + /** + * {@inheritDoc} + * + * The default interval is 3600 seconds (1 hour). + */ @Override public int getResourceCacheTime() { return resourceCacheTime; } + /** + * {@inheritDoc} + * + * The default interval is 300 seconds (5 minutes). + */ @Override public int getHeartbeatInterval() { return heartbeatInterval; @@ -228,11 +248,11 @@ public abstract class AbstractDeploymentConfiguration implements try { heartbeatInterval = Integer .parseInt(getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "500")); + Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "300")); } catch (NumberFormatException e) { getLogger().warning( Constants.WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC); - heartbeatInterval = 500; + heartbeatInterval = 300; } } |