@Override public void setPushMode(PushMode pushMode) { if (pushMode == null) { throw new IllegalArgumentException("Push mode cannot be null"); } VaadinSession session = ui.getSession(); if (session == null) { throw new UIDetachedException( "Cannot set the push mode for a detached UI"); } session.checkHasLock(); if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) { throw new IllegalStateException( "Push is not available. See previous log messages for more information."); } PushMode oldMode = getPushConfigurationMap().getPushMode(); if (oldMode != pushMode) { getPushConfigurationMap().setPushMode(pushMode); if (!oldMode.isEnabled() && pushMode.isEnabled()) { // The push connection is initially in a disconnected state; // the client will establish the connection ui.getInternals() .setPushConnection(pushConnectionFactory.apply(ui)); } // Nothing to do here if disabling push; // the client will close the connection } }
/** * Gets the push mode to use. * * @return the desired push mode */ public PushMode getPushMode() { if (pushMode == null) { pushMode = getUI().getPushConfiguration().getPushMode(); if (pushMode == null) { pushMode = getRequest().getService() .getDeploymentConfiguration().getPushMode(); } if (pushMode.isEnabled() && !getRequest().getService().ensurePushAvailable()) { /* * Fall back if not supported (ensurePushAvailable will log * information to the developer the first time this happens) */ pushMode = PushMode.DISABLED; } } return pushMode; }