public static void sendMessage(final String selectedId, final String msg) { final Collection<SSEWebSocket> instances = SSEWebSocketStorage.currentWSs(); for (SSEWebSocket webSocket : instances) { String id = webSocket.getInitParameter(SSEWebSocket.ID_KEY); if (id == null) { final String[] urlPatterns = findUrlPatterns(webSocket); if (urlPatterns != null) { for (String pattern : urlPatterns) { if (match(selectedId, pattern)) { webSocket.sendMessage(msg); break; } } } } else if (match(selectedId, id)) { webSocket.sendMessage(msg); } } }
private static String[] findUrlPatterns(final SSEWebSocket webSocket) { final Class<?> clazz = webSocket.getClass(); final ClassLoader loader = clazz.getClassLoader(); final Map<Class<?>, String[]> clValues = getUrlPatternMap(loader); String[] patterns = clValues.get(clazz); if (patterns != null) { return patterns; } final WebServlet webServlet = webSocket.getClass().getAnnotation(WebServlet.class); if (webServlet == null) { patterns = EMPTY_URL_PATTERN; } else { patterns = webServlet.urlPatterns(); } clValues.put(clazz, patterns); return patterns; }