Search in sources :

Example 1 with PageIdKey

use of org.apache.wicket.protocol.ws.api.registry.PageIdKey in project wicket by apache.

the class WebSocketTesterBehaviorTest method serverSideBroadcast.

@Test
public void serverSideBroadcast() {
    final String expectedMessage = "Broadcasted Message";
    final BroadcastMessage broadcastMessage = new BroadcastMessage(expectedMessage);
    final AtomicBoolean messageReceived = new AtomicBoolean(false);
    WebSocketBehaviorTestPage page = new WebSocketBehaviorTestPage(broadcastMessage);
    tester.startPage(page);
    WebSocketTester webSocketTester = new WebSocketTester(tester, page) {

        @Override
        protected void onOutMessage(String message) {
            assertEquals(expectedMessage.toUpperCase(), message);
            messageReceived.set(true);
        }
    };
    webSocketTester.broadcast(tester.getApplication(), tester.getHttpSession().getId(), new PageIdKey(page.getPageId()), broadcastMessage);
    assertTrue(messageReceived.get());
    webSocketTester.destroy();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PageIdKey(org.apache.wicket.protocol.ws.api.registry.PageIdKey) Test(org.junit.Test)

Example 2 with PageIdKey

use of org.apache.wicket.protocol.ws.api.registry.PageIdKey in project openmeetings by apache.

the class WebSocketHelper method sendClient.

private static void sendClient(IWsClient client, Consumer<IWebSocketConnection> wsc) {
    Application app = (Application) getApp();
    WebSocketSettings settings = WebSocketSettings.Holder.get(app);
    IWebSocketConnectionRegistry reg = settings.getConnectionRegistry();
    // FIXME TODO
    Executor executor = settings.getWebSocketPushMessageExecutor();
    final IWebSocketConnection wc = reg.getConnection(app, client.getSessionId(), new PageIdKey(client.getPageId()));
    if (wc != null && wc.isOpen()) {
        executor.run(() -> {
            wsc.accept(wc);
        });
    }
}
Also used : Executor(org.apache.wicket.protocol.ws.concurrent.Executor) PageIdKey(org.apache.wicket.protocol.ws.api.registry.PageIdKey) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) IWebSocketConnection(org.apache.wicket.protocol.ws.api.IWebSocketConnection) IWebSocketConnectionRegistry(org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry) IApplication(org.apache.openmeetings.IApplication) Application(org.apache.wicket.Application)

Aggregations

PageIdKey (org.apache.wicket.protocol.ws.api.registry.PageIdKey)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IApplication (org.apache.openmeetings.IApplication)1 Application (org.apache.wicket.Application)1 WebSocketSettings (org.apache.wicket.protocol.ws.WebSocketSettings)1 IWebSocketConnection (org.apache.wicket.protocol.ws.api.IWebSocketConnection)1 IWebSocketConnectionRegistry (org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry)1 Executor (org.apache.wicket.protocol.ws.concurrent.Executor)1 Test (org.junit.Test)1