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;
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
* 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;
}
/**
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;
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 {
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) {
.log(Level.WARNING,
"Error initializing Atmosphere. Push will not work.",
e);
- atmosphereAvailable = false;
}
}
return handlers;
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;
- }
- }
}