Search in sources :

Example 1 with AtmospherePushConnection

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());
}
Also used : AtmospherePushConnection(com.vaadin.flow.server.communication.AtmospherePushConnection) UI(com.vaadin.flow.component.UI) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 2 with AtmospherePushConnection

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
    }
}
Also used : AtmospherePushConnection(com.vaadin.flow.server.communication.AtmospherePushConnection) VaadinSession(com.vaadin.flow.server.VaadinSession) PushMode(com.vaadin.flow.shared.communication.PushMode)

Aggregations

AtmospherePushConnection (com.vaadin.flow.server.communication.AtmospherePushConnection)2 UI (com.vaadin.flow.component.UI)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 PushMode (com.vaadin.flow.shared.communication.PushMode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)1 Test (org.junit.Test)1