Search in sources :

Example 1 with DispatchMessage

use of com.corundumstudio.socketio.store.pubsub.DispatchMessage in project netty-socketio by mrniko.

the class BroadcastOperations method dispatch.

private void dispatch(Packet packet) {
    Map<String, Set<String>> namespaceRooms = new HashMap<String, Set<String>>();
    for (SocketIOClient socketIOClient : clients) {
        Namespace namespace = (Namespace) socketIOClient.getNamespace();
        Set<String> rooms = namespace.getRooms(socketIOClient);
        Set<String> roomsList = namespaceRooms.get(namespace.getName());
        if (roomsList == null) {
            roomsList = new HashSet<String>();
            namespaceRooms.put(namespace.getName(), roomsList);
        }
        roomsList.addAll(rooms);
    }
    for (Entry<String, Set<String>> entry : namespaceRooms.entrySet()) {
        for (String room : entry.getValue()) {
            storeFactory.pubSubStore().publish(PubSubType.DISPATCH, new DispatchMessage(room, packet, entry.getKey()));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DispatchMessage(com.corundumstudio.socketio.store.pubsub.DispatchMessage) Namespace(com.corundumstudio.socketio.namespace.Namespace)

Aggregations

Namespace (com.corundumstudio.socketio.namespace.Namespace)1 DispatchMessage (com.corundumstudio.socketio.store.pubsub.DispatchMessage)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1