Example usage for org.apache.wicket.protocol.ws.api IWebSocketConnection isOpen

List of usage examples for org.apache.wicket.protocol.ws.api IWebSocketConnection isOpen

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.ws.api IWebSocketConnection isOpen.

Prototype

boolean isOpen();

Source Link

Usage

From source file:org.apache.openmeetings.core.util.WebSocketHelper.java

License:Apache License

private static void sendClient(IWsClient client, Consumer<IWebSocketConnection> wsc) {
    Application app = (Application) getApp();
    WebSocketSettings settings = WebSocketSettings.Holder.get(app);
    IWebSocketConnectionRegistry reg = settings.getConnectionRegistry();
    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));
    }//from   w w w .ja  va 2  s  .c  o  m
}

From source file:org.apache.openmeetings.core.util.WebSocketHelper.java

License:Apache License

static void send(final Function<Application, Collection<Client>> func,
        BiConsumer<IWebSocketConnection, Client> consumer, Predicate<Client> check) {
    new Thread(() -> {
        Application app = (Application) getApp();
        if (app == null) {
            return; // Application is not ready
        }/*from  w  w  w. ja va 2  s  .  c o  m*/
        WebSocketSettings settings = WebSocketSettings.Holder.get(app);
        IWebSocketConnectionRegistry reg = settings.getConnectionRegistry();
        Executor executor = settings.getWebSocketPushMessageExecutor();
        for (Client c : func.apply(app)) {
            if (check == null || check.test(c)) {
                final IWebSocketConnection wc = reg.getConnection(app, c.getSessionId(),
                        new PageIdKey(c.getPageId()));
                if (wc != null && wc.isOpen()) {
                    executor.run(() -> consumer.accept(wc, c));
                }
            }
        }
    }).start();
}