@Override public void removeConnection(Application application, String sessionId, IKey key) { setConnection(application, sessionId, key, null); } }
public PageKey(String sessionId, Integer pageId) { this.sessionId = sessionId; this.pageId = new PageIdKey(pageId); }
protected IKey getRegistryKey() { IKey key; if (Strings.isEmpty(resourceName)) { key = new PageIdKey(pageId); } else { key = new ResourceNameKey(resourceName); } return 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); } }
@Override public void onClose(int closeCode, String message) { IKey key = getRegistryKey(); broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); }
String sessionId = connection.getSessionId(); IKey key = connection.getKey(); IWebSocketConnection wsConnection = registry.getConnection(application, sessionId, key); if (wsConnection == null)
@Override public void run() { for (IWebSocketConnection connection: new SimpleWebSocketConnectionRegistry().getConnections(application)) { if (connection.isOpen()) { try { connection.sendMessage(WebSocketManager.KEEP_ALIVE); } catch (IOException e) { throw new RuntimeException(e); } } } }
@Override public void start() { scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { @Override public void run() { for (IWebSocketConnection connection: new SimpleWebSocketConnectionRegistry().getConnections(application)) { if (connection.isOpen()) { try { connection.sendMessage(WebSocketManager.KEEP_ALIVE); } catch (IOException e) { throw new RuntimeException(e); } } } } }, 0, webSocketPolicy.getIdleTimeout()/2, TimeUnit.MILLISECONDS); }
@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); } }
private IKey getRegistryKey() { IKey key; if (Strings.isEmpty(resourceName)) { key = new PageIdKey(pageId); } else { key = new ResourceNameKey(resourceName); } return key; }
@Override public void removeConnection(Application application, String sessionId, IKey key) { setConnection(application, sessionId, key, null); } }
@Override public void notifyObserverChange(BasePage page) { String sessionId = page.getSession().getId(); if (sessionId != null) { Map<IKey, Collection<String>> sessionPages = observables.get(sessionId); if (sessionPages == null) { sessionPages = new ConcurrentHashMap<>(); observables.put(sessionId, sessionPages); } sessionPages.put(new PageIdKey(page.getPageId()), page.findWebSocketObservables()); } }
@Override public void onClose(int closeCode, String message) { IKey key = getRegistryKey(); broadcastMessage(new ClosedMessage(getApplication(), getSessionId(), key)); connectionRegistry.removeConnection(getApplication(), getSessionId(), key); }
String sessionId = connection.getSessionId(); IKey key = connection.getKey(); IWebSocketConnection wsConnection = registry.getConnection(application, sessionId, key); if (wsConnection == null)
/** * 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); }
private IKey getRegistryKey() { IKey key; if (Strings.isEmpty(resourceName)) { key = new PageIdKey(pageId); } else { key = new ResourceNameKey(resourceName); } return key; }
@Override public void removeConnection(Application application, String sessionId, IKey key) { setConnection(application, sessionId, key, null); }
@Nullable public static PageKey getPageKey() { Page page = getPage(); if (page != null) { String sessionId = page.getSession().getId(); if (sessionId != null) { return new PageKey(sessionId, new PageIdKey(page.getPageId())); } } return null; }
@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); }