Commit cee7861f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More refactoring work. Broadcast should now be clusterable.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8370 b35dd754-fafc-0310-a699-88a17e54d16e
parent df01c030
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
package org.jivesoftware.openfire; package org.jivesoftware.openfire;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
/** /**
...@@ -31,4 +32,12 @@ public interface RemotePacketRouter { ...@@ -31,4 +32,12 @@ public interface RemotePacketRouter {
* @return true if the remote node was found. * @return true if the remote node was found.
*/ */
boolean routePacket(byte[] nodeID, JID receipient, Packet packet); boolean routePacket(byte[] nodeID, JID receipient, Packet packet);
/**
* Brodcasts the specified message to all local client sessions of each cluster node.
* The current cluster node is not going to be included.
*
* @param packet the message to broadcast.
*/
void broadcastPacket(Message packet);
} }
...@@ -14,6 +14,7 @@ package org.jivesoftware.openfire; ...@@ -14,6 +14,7 @@ package org.jivesoftware.openfire;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.util.List; import java.util.List;
...@@ -239,4 +240,13 @@ public interface RoutingTable { ...@@ -239,4 +240,13 @@ public interface RoutingTable {
* in remote nodes of the cluster. * in remote nodes of the cluster.
*/ */
void setRemotePacketRouter(RemotePacketRouter remotePacketRouter); void setRemotePacketRouter(RemotePacketRouter remotePacketRouter);
/**
* Broadcasts the specified message to connected client sessions to the local node or
* across the cluster. Both available and unavailable client sessions will receive the message.
*
* @param packet the message to broadcast.
* @param onlyLocal true if only client sessions connecte to the local JVM will get the message.
*/
void broadcastPacket(Message packet, boolean onlyLocal);
} }
...@@ -1454,15 +1454,8 @@ public class SessionManager extends BasicModule { ...@@ -1454,15 +1454,8 @@ public class SessionManager extends BasicModule {
* @param packet the packet to be broadcast. * @param packet the packet to be broadcast.
* @throws UnauthorizedException if not allowed to perform the operation. * @throws UnauthorizedException if not allowed to perform the operation.
*/ */
public void broadcast(Packet packet) throws UnauthorizedException { public void broadcast(Message packet) throws UnauthorizedException {
// TODO Move responsibility to routing table routingTable.broadcastPacket(packet, false);
for (SessionMap sessionMap : sessions.values()) {
sessionMap.broadcast(packet);
}
for (Session session : anonymousSessions.values()) {
session.process(packet);
}
} }
/** /**
......
...@@ -12,7 +12,11 @@ ...@@ -12,7 +12,11 @@
package org.jivesoftware.openfire.spi; package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.RoutableChannelHandler; import org.jivesoftware.openfire.RoutableChannelHandler;
import org.jivesoftware.openfire.session.ClientSession;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -47,6 +51,21 @@ class LocalRoutingTable { ...@@ -47,6 +51,21 @@ class LocalRoutingTable {
return routes.get(address); return routes.get(address);
} }
/**
* Returns the client sessions that are connected to this JVM.
*
* @return the client sessions that are connected to this JVM.
*/
Collection<RoutableChannelHandler> getClientRoutes() {
List<RoutableChannelHandler> sessions = new ArrayList<RoutableChannelHandler>();
for (RoutableChannelHandler route : routes.values()) {
if (route instanceof ClientSession) {
sessions.add(route);
}
}
return sessions;
}
/** /**
* Removes a route of a local {@link RoutableChannelHandler} * Removes a route of a local {@link RoutableChannelHandler}
* *
......
...@@ -137,6 +137,22 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -137,6 +137,22 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
} }
} }
public void broadcastPacket(Message packet, boolean onlyLocal) {
// Send the message to client sessions connected to this JVM
for(RoutableChannelHandler session : localRoutingTable.getClientRoutes()) {
try {
session.process(packet);
} catch (UnauthorizedException e) {
// Should never happen
}
}
// Check if we need to broadcast the message to client sessions connected to remote cluter nodes
if (!onlyLocal && remotePacketRouter != null) {
remotePacketRouter.broadcastPacket(packet);
}
}
public void routePacket(JID jid, Packet packet) throws UnauthorizedException, PacketException { public void routePacket(JID jid, Packet packet) throws UnauthorizedException, PacketException {
boolean routed = false; boolean routed = false;
JID address = packet.getTo(); JID address = packet.getTo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment