use of com.vaadin.flow.server.communication.AtmospherePushConnection in project flow by vaadin.
the class AtmospherePushConnectionTest method testSerialization.
@Test
public void testSerialization() throws Exception {
UI ui = EasyMock.createNiceMock(UI.class);
AtmosphereResource resource = EasyMock.createNiceMock(AtmosphereResource.class);
AtmospherePushConnection connection = new AtmospherePushConnection(ui);
connection.connect(resource);
Assert.assertEquals(State.CONNECTED, connection.getState());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(connection);
connection = (AtmospherePushConnection) new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
Assert.assertEquals(State.DISCONNECTED, connection.getState());
}
use of com.vaadin.flow.server.communication.AtmospherePushConnection in project flow by vaadin.
the class PushConfigurationImpl method setPushMode.
@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
}
}
Aggregations