@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"); } assert session.hasLock(); if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) { throw new IllegalStateException( "Push is not available. See previous log messages for more information."); } PushMode oldMode = getState().mode; if (oldMode != pushMode) { getState().mode = pushMode; if (!oldMode.isEnabled() && pushMode.isEnabled()) { // The push connection is initially in a disconnected state; // the client will establish the connection ui.setPushConnection(new AtmospherePushConnection(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) { UICreateEvent event = new UICreateEvent(getRequest(), getUIClass()); pushMode = getBootstrapResponse().getUIProvider() .getPushMode(event); 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; }
@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"); } assert session.hasLock(); 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(new AtmospherePushConnection(ui)); } // Nothing to do here if disabling push; // the client will close the connection } }
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; }
@Test public void push_config() { // given prepAttach(); ui.attach(); VaadinService service = mock(VaadinService.class); when(service.ensurePushAvailable()).thenReturn(true); when(session.getService()).thenReturn(service); // when // then assertThat(ui.getPushConfiguration()).isInstanceOf(DefaultKrailPushConfiguration.class); assertThat(ui.getPushConnection()).isNull(); // push mode not enabled yet // when ui.getPushConfiguration().setPushMode(PushMode.AUTOMATIC); assertThat(ui.getPushConnection()).isInstanceOf(SockJSPushConnection.class); //when disable and re-enabled push, connection type is still correct ui.getPushConfiguration().setPushMode(PushMode.DISABLED); ui.getPushConfiguration().setPushMode(PushMode.AUTOMATIC); //then assertThat(ui.getPushConnection()).isInstanceOf(SockJSPushConnection.class); }