@Override public void broadcastPacket(Message packet, boolean onlyLocal) { // Send the message to client sessions connected to this JVM for(ClientSession session : localRoutingTable.getClientRoutes()) { session.process(packet); } // Check if we need to broadcast the message to client sessions connected to remote cluter nodes if (!onlyLocal && remotePacketRouter != null) { remotePacketRouter.broadcastPacket(packet); } }
@Override public Collection<ClientSession> getClientsRoutes(boolean onlyLocal) { // Add sessions hosted by this cluster node Collection<ClientSession> sessions = new ArrayList<ClientSession>(localRoutingTable.getClientRoutes()); if (!onlyLocal) { // Add sessions not hosted by this JVM RemoteSessionLocator locator = server.getRemoteSessionLocator(); if (locator != null) { // Add sessions of non-anonymous users hosted by other cluster nodes for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) { ClientRoute route = entry.getValue(); if (!server.getNodeID().equals(route.getNodeID())) { sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey()))); } } // Add sessions of anonymous users hosted by other cluster nodes for (Map.Entry<String, ClientRoute> entry : anonymousUsersCache.entrySet()) { ClientRoute route = entry.getValue(); if (!server.getNodeID().equals(route.getNodeID())) { sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey()))); } } } } return sessions; }
@Override public void joinedCluster() { restoreCacheContent(); // Broadcast presence of local sessions to remote sessions when subscribed to presence // Probe presences of remote sessions when subscribed to presence of local session // Send pending subscription requests to local sessions from remote sessions // Deliver offline messages sent to local sessions that were unavailable in other nodes // Send available presences of local sessions to other resources of the same user PresenceUpdateHandler presenceUpdateHandler = XMPPServer.getInstance().getPresenceUpdateHandler(); for (LocalClientSession session : localRoutingTable.getClientRoutes()) { // Simulate that the local session has just became available session.setInitialized(false); // Simulate that current session presence has just been received presenceUpdateHandler.process(session.getPresence()); } }
private void restoreCacheContent() { // Add outgoing server sessions hosted locally to the cache (using new nodeID) for (LocalOutgoingServerSession session : localRoutingTable.getServerRoutes()) { for (DomainPair pair : session.getOutgoingDomainPairs()) { addServerRoute(pair, session); } } // Add component sessions hosted locally to the cache (using new nodeID) and remove traces to old nodeID for (RoutableChannelHandler route : localRoutingTable.getComponentRoute()) { addComponentRoute(route.getAddress(), route); } // Add client sessions hosted locally to the cache (using new nodeID) for (LocalClientSession session : localRoutingTable.getClientRoutes()) { addClientRoute(session.getAddress(), session); } }
@Override public void broadcastPacket(Message packet, boolean onlyLocal) { // Send the message to client sessions connected to this JVM for(ClientSession session : localRoutingTable.getClientRoutes()) { session.process(packet); } // Check if we need to broadcast the message to client sessions connected to remote cluter nodes if (!onlyLocal && remotePacketRouter != null) { remotePacketRouter.broadcastPacket(packet); } }
@Override public Collection<ClientSession> getClientsRoutes(boolean onlyLocal) { // Add sessions hosted by this cluster node Collection<ClientSession> sessions = new ArrayList<ClientSession>(localRoutingTable.getClientRoutes()); if (!onlyLocal) { // Add sessions not hosted by this JVM RemoteSessionLocator locator = server.getRemoteSessionLocator(); if (locator != null) { // Add sessions of non-anonymous users hosted by other cluster nodes for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) { ClientRoute route = entry.getValue(); if (!server.getNodeID().equals(route.getNodeID())) { sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey()))); } } // Add sessions of anonymous users hosted by other cluster nodes for (Map.Entry<String, ClientRoute> entry : anonymousUsersCache.entrySet()) { ClientRoute route = entry.getValue(); if (!server.getNodeID().equals(route.getNodeID())) { sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey()))); } } } } return sessions; }
@Override public void joinedCluster() { restoreCacheContent(); // Broadcast presence of local sessions to remote sessions when subscribed to presence // Probe presences of remote sessions when subscribed to presence of local session // Send pending subscription requests to local sessions from remote sessions // Deliver offline messages sent to local sessions that were unavailable in other nodes // Send available presences of local sessions to other resources of the same user PresenceUpdateHandler presenceUpdateHandler = XMPPServer.getInstance().getPresenceUpdateHandler(); for (LocalClientSession session : localRoutingTable.getClientRoutes()) { // Simulate that the local session has just became available session.setInitialized(false); // Simulate that current session presence has just been received presenceUpdateHandler.process(session.getPresence()); } }
private void restoreCacheContent() { // Add outgoing server sessions hosted locally to the cache (using new nodeID) for (LocalOutgoingServerSession session : localRoutingTable.getServerRoutes()) { for (DomainPair pair : session.getOutgoingDomainPairs()) { addServerRoute(pair, session); } } // Add component sessions hosted locally to the cache (using new nodeID) and remove traces to old nodeID for (RoutableChannelHandler route : localRoutingTable.getComponentRoute()) { addComponentRoute(route.getAddress(), route); } // Add client sessions hosted locally to the cache (using new nodeID) for (LocalClientSession session : localRoutingTable.getClientRoutes()) { addClientRoute(session.getAddress(), session); } }