]> source.dussan.org Git - vaadin-framework.git/commitdiff
Detect Atmosphere in the same way for servlets and portlets (#11493)
authorArtur Signell <artur@vaadin.com>
Mon, 5 Oct 2015 13:41:40 +0000 (16:41 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 7 Oct 2015 06:54:22 +0000 (06:54 +0000)
Change-Id: I6c153291045a35f253cd7e6987d7eb90dbc93a1e

server/src/com/vaadin/server/VaadinService.java
server/src/com/vaadin/server/VaadinServletService.java

index 8a6be63dd6d1911adee76668b09a8a9adf2cb481..09704838b674d32389f49c499fbcefee83b174ca 100644 (file)
@@ -52,6 +52,7 @@ import com.vaadin.annotations.PreserveOnRefresh;
 import com.vaadin.event.EventRouter;
 import com.vaadin.server.VaadinSession.FutureAccess;
 import com.vaadin.server.VaadinSession.State;
+import com.vaadin.server.communication.AtmospherePushConnection;
 import com.vaadin.server.communication.FileUploadHandler;
 import com.vaadin.server.communication.HeartbeatHandler;
 import com.vaadin.server.communication.PublishedFileHandler;
@@ -133,6 +134,8 @@ public abstract class VaadinService implements Serializable {
 
     private Iterable<RequestHandler> requestHandlers;
 
+    private boolean atmosphereAvailable = checkAtmosphereSupport();
+
     /**
      * Keeps track of whether a warning about missing push support has already
      * been logged. This is used to avoid spamming the log with the same message
@@ -1625,13 +1628,43 @@ public abstract class VaadinService implements Serializable {
      *         is not available.
      */
     public boolean ensurePushAvailable() {
-        if (!pushWarningEmitted) {
-            pushWarningEmitted = true;
-            getLogger().log(Level.WARNING, Constants.PUSH_NOT_SUPPORTED_ERROR,
-                    getClass().getSimpleName());
+        if (atmosphereAvailable) {
+            return true;
+        } else {
+            if (!pushWarningEmitted) {
+                pushWarningEmitted = true;
+                getLogger().log(Level.WARNING,
+                        Constants.ATMOSPHERE_MISSING_ERROR);
+            }
+            return false;
         }
-        // Not supported by default for now, sublcasses may override
-        return false;
+    }
+
+    private static boolean checkAtmosphereSupport() {
+        String rawVersion = AtmospherePushConnection.getAtmosphereVersion();
+        if (rawVersion == null) {
+            return false;
+        }
+
+        if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION.equals(rawVersion)) {
+            getLogger().log(
+                    Level.WARNING,
+                    Constants.INVALID_ATMOSPHERE_VERSION_WARNING,
+                    new Object[] {
+                            Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION,
+                            rawVersion });
+        }
+        return true;
+    }
+
+    /**
+     * Checks whether Atmosphere is avilable for use
+     * 
+     * @since
+     * @return true if Atmosphere is available, false otherwise
+     */
+    protected boolean isAtmosphereAvailable() {
+        return atmosphereAvailable;
     }
 
     /**
index 22848c023c707b3f79a63737dded313a831d5d87..5faea1ce6c52aa767c725b5705e3aec0d135c42f 100644 (file)
@@ -27,7 +27,6 @@ import java.util.logging.Logger;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
-import com.vaadin.server.communication.AtmospherePushConnection;
 import com.vaadin.server.communication.PushRequestHandler;
 import com.vaadin.server.communication.ServletBootstrapHandler;
 import com.vaadin.server.communication.ServletUIInitHandler;
@@ -36,15 +35,6 @@ import com.vaadin.ui.UI;
 public class VaadinServletService extends VaadinService {
     private final VaadinServlet servlet;
 
-    private boolean atmosphereAvailable = checkAtmosphereSupport();
-
-    /**
-     * Keeps track of whether a warning about missing push support has already
-     * been logged. This is used to avoid spamming the log with the same message
-     * every time a new UI is bootstrapped.
-     */
-    private boolean pushWarningLogged = false;
-
     public VaadinServletService(VaadinServlet servlet,
             DeploymentConfiguration deploymentConfiguration)
             throws ServiceException {
@@ -52,30 +42,13 @@ public class VaadinServletService extends VaadinService {
         this.servlet = servlet;
     }
 
-    private static boolean checkAtmosphereSupport() {
-        String rawVersion = AtmospherePushConnection.getAtmosphereVersion();
-        if (rawVersion == null) {
-            return false;
-        }
-
-        if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION.equals(rawVersion)) {
-            getLogger().log(
-                    Level.WARNING,
-                    Constants.INVALID_ATMOSPHERE_VERSION_WARNING,
-                    new Object[] {
-                            Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION,
-                            rawVersion });
-        }
-        return true;
-    }
-
     @Override
     protected List<RequestHandler> createRequestHandlers()
             throws ServiceException {
         List<RequestHandler> handlers = super.createRequestHandlers();
         handlers.add(0, new ServletBootstrapHandler());
         handlers.add(new ServletUIInitHandler());
-        if (atmosphereAvailable) {
+        if (isAtmosphereAvailable()) {
             try {
                 handlers.add(new PushRequestHandler(this));
             } catch (ServiceException e) {
@@ -86,7 +59,6 @@ public class VaadinServletService extends VaadinService {
                         .log(Level.WARNING,
                                 "Error initializing Atmosphere. Push will not work.",
                                 e);
-                atmosphereAvailable = false;
             }
         }
         return handlers;
@@ -271,17 +243,4 @@ public class VaadinServletService extends VaadinService {
         return Logger.getLogger(VaadinServletService.class.getName());
     }
 
-    @Override
-    public boolean ensurePushAvailable() {
-        if (atmosphereAvailable) {
-            return true;
-        } else {
-            if (!pushWarningLogged) {
-                pushWarningLogged = true;
-                getLogger().log(Level.WARNING,
-                        Constants.ATMOSPHERE_MISSING_ERROR);
-            }
-            return false;
-        }
-    }
 }