@Override public void send(IWebSocketPushMessage event) { Application application = Application.get(WicketWebInitializer.WICKET_FILTERNAME); WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application); IWebSocketConnectionRegistry connectionRegistry = webSocketSettings.getConnectionRegistry(); Collection<IWebSocketConnection> connections = connectionRegistry.getConnections(application); log.trace("sending event to {} connections", connections.size()); for (IWebSocketConnection connection : connections) { connection.sendMessage(event); } }
@Override public void send(IWebSocketPushMessage event) { Application application = Application.get(WicketWebInitializer.WICKET_FILTERNAME); WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application); IWebSocketConnectionRegistry connectionRegistry = webSocketSettings.getConnectionRegistry(); Collection<IWebSocketConnection> connections = connectionRegistry.getConnections(application); log.trace("sending event to {} connections", connections.size()); for (IWebSocketConnection connection : connections) { connection.sendMessage(event); } }
@Override public void run() { for (IWebSocketConnection connection: connectionRegistry.getConnections(application)) { PageKey pageKey = ((WebSocketConnection) connection).getPageKey(); if (connection.isOpen() && (sourcePageKey == null || !sourcePageKey.equals(pageKey))) { Map<IKey, Collection<String>> sessionPages = observables.get(pageKey.getSessionId()); if (sessionPages != null) { Collection<String> pageObservables = sessionPages.get(pageKey.getPageId()); if (pageObservables != null && pageObservables.contains(observable)) { try { connection.sendMessage(OBSERVABLE_CHANGED + ":" + observable); } catch (IOException e) { throw new RuntimeException(e); } } } } } }
/** * Processes the given message in all pages that have active Web Socket connections. * The message is sent as an event to the Page and components of the session allowing the components * to be updated. * * This method can be invoked from any thread, even a non-wicket thread. By default all processing * is done in the caller thread. Use * {@link WebSocketSettings#setWebSocketPushMessageExecutor(org.apache.wicket.protocol.ws.concurrent.Executor)} * to move processing to background threads. * * If some connections are not in valid state they are silently ignored. * * @param application * The wicket application * @param message * The push message event */ public void broadcastAll(Application application, IWebSocketPushMessage message) { Args.notNull(application, "application"); Args.notNull(message, "message"); Collection<IWebSocketConnection> wsConnections = registry.getConnections(application); if (wsConnections == null) { return; } process(application, wsConnections, message); }
/** * Processes the given message in all pages that have active Web Socket connections. * The message is sent as an event to the Page and components of the session allowing the components * to be updated. * * This method can be invoked from any thread, even a non-wicket thread. By default all processing * is done in the caller thread. Use * {@link WebSocketSettings#setWebSocketPushMessageExecutor(org.apache.wicket.protocol.ws.concurrent.Executor)} * to move processing to background threads. * * If some connections are not in valid state they are silently ignored. * * @param application * The wicket application * @param message * The push message event */ public void broadcastAll(Application application, IWebSocketPushMessage message) { Args.notNull(application, "application"); Args.notNull(message, "message"); Collection<IWebSocketConnection> wsConnections = registry.getConnections(application); if (wsConnections == null) { return; } process(application, wsConnections, message); }
/** * Load the documents list from the documents folder and synchronizing the list between whiteboard clients */ private void handleDocs() { loadDocuments(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); Set<String> keySet = docMap.keySet(); for (String key : keySet) { jsonArray.put(docMap.get(key).get(0)); } c.sendMessage(getDocumentListMessage(jsonArray).toString()); } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } }
/** * Synchronizing eraseAll request between whiteboard clients * * @return */ private boolean handleEraseAll() { elementMap.clear(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); c.sendMessage(getEraseAllMessage(jsonArray).toString()); return true; } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } return false; }
/** * Load the components of a particular document from the documents folder and synchronizing the list between * whiteboard clients * * @param docBaseName */ private void handleDocComponents(String docBaseName) { loadDocuments(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); for (String url : docMap.get(docBaseName)) { jsonArray.put(url); } c.sendMessage(getDocumentComponentListMessage(jsonArray).toString()); } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } }
for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { c.sendMessage(getUndoMessage(changeList, deleteList).toString()); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { if (previousBackground != null) {
for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONObject jsonObject = new JSONObject(editedElement);
/** * Load the clipArts list from the clipArt folder and synchronizing the list between whiteboard clients */ private void handleClipArts() { loadClipArts(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); for (String clipArtURL : clipArts) { jsonArray.put(clipArtURL); } c.sendMessage(getClipArtListMessage(jsonArray).toString()); } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } }
for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONObject jsonObject = new JSONObject(backgroundString);