From 947c62d82793da6407c33565c92f2289423f2500 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 26 Apr 2013 11:53:59 +0300 Subject: Wait max 1000ms before closing push channel (#11596) Change-Id: I85c8b0a1f499294b85f130eeb9061644aa8f2f4f --- .../communication/AtmospherePushConnection.java | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 770b0b6a59..f33a10c572 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -21,6 +21,10 @@ import java.io.Serializable; import java.io.StringWriter; import java.io.Writer; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; import org.atmosphere.cpr.AtmosphereResource; import org.json.JSONException; @@ -125,12 +129,18 @@ public class AtmospherePushConnection implements Serializable, PushConnection { @Override public void disconnect() { if (lastMessage != null) { + // Wait for the last message to be sent before closing the + // connection (assumes that futures are completed in order) try { - // Wait for the last message to be sent before closing the - // connection (assumes that futures are completed in order) - lastMessage.get(); + lastMessage.get(1000, TimeUnit.MILLISECONDS); + } catch (TimeoutException e) { + getLogger() + .log(Level.INFO, + "Timeout waiting for messages to be sent to client before disconnect"); } catch (Exception e) { - e.printStackTrace(); + getLogger() + .log(Level.INFO, + "Error waiting for messages to be sent to client before disconnect"); } lastMessage = null; } @@ -140,4 +150,12 @@ public class AtmospherePushConnection implements Serializable, PushConnection { .contains(resource); resource = null; } + + /** + * @since + * @return + */ + private static Logger getLogger() { + return Logger.getLogger(AtmospherePushConnection.class.getName()); + } } -- cgit v1.2.3