@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); } }
String sessionId = connection.getSessionId(); IKey key = connection.getKey(); IWebSocketConnection wsConnection = registry.getConnection(application, sessionId, key); if (wsConnection == null)
@Override public void onClose(int closeCode, String message) { IKey key = getRegistryKey(); broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); }
/** * A helper that registers the opened connection in the application-level registry. * * @param connection * the web socket connection to use to communicate with the client * @see #onOpen(Object) */ protected final void onConnect(final IWebSocketConnection connection) { IKey key = getRegistryKey(); connectionRegistry.setConnection(getApplication(), getSessionId(), key, connection); if (connectionFilter != null) { ConnectionRejected connectionRejected = connectionFilter.doFilter(servletRequest); if (connectionRejected != null) { broadcastMessage(new AbortedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); connection.close(connectionRejected.getCode(), connectionRejected.getReason()); return; } } broadcastMessage(new ConnectedMessage(getApplication(), getSessionId(), key)); }
/** * A helper that registers the opened connection in the application-level registry. * * @param connection * the web socket connection to use to communicate with the client * @see #onOpen(Object) */ protected final void onConnect(final IWebSocketConnection connection) { IKey key = getRegistryKey(); connectionRegistry.setConnection(getApplication(), getSessionId(), key, connection); if (connectionFilter != null) { ConnectionRejected connectionRejected = connectionFilter.doFilter(servletRequest); if (connectionRejected != null) { broadcastMessage(new AbortedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); connection.close(connectionRejected.getCode(), connectionRejected.getReason()); return; } } broadcastMessage(new ConnectedMessage(getApplication(), getSessionId(), key)); }
@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); } }
/** * A helper that registers the opened connection in the application-level registry. * * @param connection * the web socket connection to use to communicate with the client * @see #onOpen(Object) */ protected final void onConnect(final IWebSocketConnection connection) { IKey key = getRegistryKey(); connectionRegistry.setConnection(getApplication(), getSessionId(), key, connection); if (connectionFilter != null) { ConnectionRejected connectionRejected = connectionFilter.doFilter(servletRequest); if (connectionRejected != null) { broadcastMessage(new AbortedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); connection.close(connectionRejected.getCode(), connectionRejected.getReason()); return; } } broadcastMessage(new ConnectedMessage(getApplication(), getSessionId(), key)); }
String sessionId = connection.getSessionId(); IKey key = connection.getKey(); IWebSocketConnection wsConnection = registry.getConnection(application, sessionId, key); if (wsConnection == null)
@Override public void onClose(int closeCode, String message) { IKey key = getRegistryKey(); broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); }
@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); } } } } } }
IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
@Override public void onClose(int closeCode, String message) { IKey key = getRegistryKey(); broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); }
/** * 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); }
IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
/** * 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); }
IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
/** * 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) {