Example usage for org.apache.wicket.protocol.ws WebSocketSettings getConnectionRegistry

List of usage examples for org.apache.wicket.protocol.ws WebSocketSettings getConnectionRegistry

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.ws WebSocketSettings getConnectionRegistry.

Prototype

public IWebSocketConnectionRegistry getConnectionRegistry() 

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 ww  w.  j ava 2 s . c om*/
}

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

License:Apache License

private static void sendAll(Consumer<IWebSocketConnection> sender) {
    new Thread(() -> {
        Application app = (Application) getApp();
        if (app == null) {
            return; // Application is not ready
        }/*from ww  w. j a v  a 2  s.co m*/
        WebSocketSettings settings = WebSocketSettings.Holder.get(app);
        IWebSocketConnectionRegistry reg = settings.getConnectionRegistry();
        Executor executor = settings.getWebSocketPushMessageExecutor();
        for (IWebSocketConnection c : reg.getConnections(app)) {
            executor.run(() -> sender.accept(c));
        }
    }).start();
}

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
        }/*  w w w. j a  va2s  . 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();
}

From source file:org.efaps.ui.wicket.components.connection.MessagePanel.java

License:Apache License

/**
 * @param _wicketId wicketId of this component
 * @param _pageReference reference to the page
 * @throws EFapsException on error/*w  ww . jav  a  2 s .  c  o m*/
 */
public MessagePanel(final String _wicketId, final PageReference _pageReference) throws EFapsException {
    super(_wicketId);
    final Form<Void> msgForm = new Form<>("msgForm");
    add(msgForm);

    final AjaxSubmitLink sendMsgBtn = new AjaxSubmitLink("sendMsgBtn", msgForm) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onAfterSubmit(final AjaxRequestTarget _target, final Form<?> _form) {
            final StringBuilder msg = new StringBuilder();
            _form.visitChildren(TextArea.class, new IVisitor<TextArea<String>, Void>() {
                @Override
                public void component(final TextArea<String> _textArea, final IVisit<Void> _visit) {
                    _textArea.setEscapeModelStrings(false);
                    msg.append(_textArea.getDefaultModelObjectAsString());
                    _visit.stop();
                }
            });

            if (msg.length() > 0) {
                _form.visitChildren(CheckBox.class, new IVisitor<CheckBox, Void>() {

                    @Override
                    public void component(final CheckBox _checkBox, final IVisit<Void> _visit) {
                        final Boolean selected = (Boolean) _checkBox.getDefaultModelObject();
                        if (selected) {
                            final CheckBoxPanel panel = (CheckBoxPanel) _checkBox.getParent();
                            final UIUser user = (UIUser) panel.getDefaultModelObject();
                            final List<IWebSocketConnection> conns = RegistryManager
                                    .getConnections4User(user.getUserName());
                            for (final IWebSocketConnection conn : conns) {
                                conn.sendMessage(new PushMsg(msg.toString()));
                            }
                        }
                    }
                });
            }
        }
    };
    msgForm.add(sendMsgBtn);

    final AjaxSubmitLink broadcastMsgBtn = new AjaxSubmitLink("broadcastMsgBtn", msgForm) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onAfterSubmit(final AjaxRequestTarget _target, final Form<?> _form) {

            final StringBuilder msg = new StringBuilder();
            _form.visitChildren(TextArea.class, new IVisitor<TextArea<String>, Void>() {

                @Override
                public void component(final TextArea<String> _textArea, final IVisit<Void> _visit) {
                    _textArea.setEscapeModelStrings(false);
                    msg.append(_textArea.getDefaultModelObjectAsString());
                    _visit.stop();
                }
            });

            if (msg.length() > 0) {
                final WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(getApplication());
                final WebSocketPushBroadcaster broadcaster = new WebSocketPushBroadcaster(
                        webSocketSettings.getConnectionRegistry());
                broadcaster.broadcastAll(EFapsApplication.get(), new PushMsg(msg.toString()));
            }
        }
    };
    msgForm.add(broadcastMsgBtn);

    final TextArea<String> msg = new TextArea<>("msg", Model.of(""));
    msgForm.add(msg);

    final MessageTablePanel messageTable = new MessageTablePanel("messageTable", _pageReference,
            new UserProvider());
    msgForm.add(messageTable);
}