use of org.jivesoftware.openfire.RemotePacketRouter in project Openfire by igniterealtime.
the class BaseTransport method processPacket.
/**
* Handles all incoming XMPP stanzas, passing them to individual
* packet type handlers.
*
* @param packet The packet to be processed.
*/
public void processPacket(Packet packet) {
JID from = packet.getFrom();
JID to = packet.getTo();
if (to == null) {
// Well clearly it's for us or it wouldn't have gotten here...
packet.setTo(getJID());
to = getJID();
}
if (from != null && to != null) {
Lock l = CacheFactory.getLock(from.toBareJID() + "@" + transportType.toString() + "pp", sessionRouter.sessionLocations);
try {
l.lock();
byte[] targetNodeID = sessionRouter.getSession(transportType.toString(), from.toBareJID());
if (targetNodeID != null && !Arrays.equals(targetNodeID, XMPPServer.getInstance().getNodeID().toByteArray())) {
RemotePacketRouter router = XMPPServer.getInstance().getRoutingTable().getRemotePacketRouter();
if (router != null) {
// Not for our node, send it elsewhere.
router.routePacket(targetNodeID, to, packet);
return;
}
}
} finally {
l.unlock();
}
}
try {
List<Packet> reply = new ArrayList<Packet>();
if (packet instanceof IQ) {
reply.addAll(processPacket((IQ) packet));
} else if (packet instanceof Presence) {
reply.addAll(processPacket((Presence) packet));
} else if (packet instanceof Message) {
reply.addAll(processPacket((Message) packet));
} else {
Log.debug("Received an unhandled packet: " + packet.toString());
}
if (reply.size() > 0) {
for (Packet p : reply) {
this.sendPacket(p);
}
}
} catch (Exception e) {
Log.warn("Error occured while processing packet:", e);
}
}
Aggregations