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

Improved performance by avoiding creating JIDs instance. JM-555

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3388 b35dd754-fafc-0310-a699-88a17e54d16e
parent 527e5154
......@@ -14,6 +14,10 @@ package org.jivesoftware.wildfire;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Version;
import org.jivesoftware.wildfire.audit.AuditManager;
import org.jivesoftware.wildfire.audit.spi.AuditManagerImpl;
import org.jivesoftware.wildfire.commands.AdHocCommandHandler;
......@@ -33,10 +37,6 @@ import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.spi.*;
import org.jivesoftware.wildfire.transport.TransportHandler;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Version;
import org.xmpp.packet.JID;
import java.io.File;
......@@ -172,8 +172,7 @@ public class XMPPServer {
*/
public boolean isRemote(JID jid) {
if (jid != null) {
String domain = jid.getDomain();
if (!name.equals(domain) && componentManager.getComponent(domain) == null) {
if (!name.equals(jid.getDomain()) && componentManager.getComponent(jid) == null) {
return true;
}
}
......@@ -188,7 +187,7 @@ public class XMPPServer {
*/
public boolean matchesComponent(JID jid) {
if (jid != null) {
return componentManager.getComponent(jid.getDomain()) != null;
return !name.equals(jid.getDomain()) && componentManager.getComponent(jid) != null;
}
return false;
}
......
......@@ -213,22 +213,20 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
* @return the component with the specified id.
*/
public Component getComponent(JID componentJID) {
String jid = componentJID.toBareJID();
if (components.containsKey(jid)) {
return components.get(jid);
Component component = components.get(componentJID.getDomain());
if (component != null) {
return component;
}
else {
if (!jid.contains(serverDomain)) {
// Ignore JIDs that doesn't belong to this server
return null;
}
String serverName = new JID(jid).getDomain();
int index = serverName.indexOf(".");
if (index != -1) {
jid = serverName.substring(0, index);
// Search again for those JIDs whose domain include the server name but this
// time remove the server name from the JID's domain
String serverName = componentJID.getDomain();
int index = serverName.lastIndexOf(serverDomain);
if (index > 0) {
return components.get(serverName.substring(0, --index));
}
}
return components.get(jid);
return null;
}
/**
......@@ -256,7 +254,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
for (JID prober : presenceMap.keySet()) {
JID probee = presenceMap.get(prober);
Component component = getComponent(probee.toBareJID());
Component component = getComponent(probee);
if (component != null) {
Presence presence = new Presence();
presence.setFrom(prober);
......@@ -300,7 +298,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
* @param packet the packet to process.
*/
public void process(Packet packet) throws PacketException {
Component component = getComponent(packet.getFrom().getDomain());
Component component = getComponent(packet.getFrom());
// Only process packets that were sent by registered components
if (component != null) {
if (packet instanceof IQ && IQ.Type.result == ((IQ) packet).getType()) {
......
......@@ -246,7 +246,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public void probePresence(JID prober, JID probee) {
try {
Component component = getPresenceComponent(probee);
if (server.isLocal(probee)) {
// If the probee is a local user then don't send a probe to the contact's server.
// But instead just send the contact's presence to the prober
......@@ -297,33 +296,36 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
}
}
}
else if (component != null) {
// If the probee belongs to a component then ask the component to process the
// probe presence
Presence presence = new Presence();
presence.setType(Presence.Type.probe);
presence.setFrom(prober);
presence.setTo(probee);
component.processPacket(presence);
}
else {
// Check if the probee may be hosted by this server
/*String serverDomain = server.getServerInfo().getName();
if (!probee.getDomain().contains(serverDomain)) {*/
if (server.isRemote(probee)) {
// Send the probe presence to the remote server
Presence probePresence = new Presence();
probePresence.setType(Presence.Type.probe);
probePresence.setFrom(prober);
probePresence.setTo(probee.toBareJID());
// Send the probe presence
deliverer.deliver(probePresence);
Component component = getPresenceComponent(probee);
if (component != null) {
// If the probee belongs to a component then ask the component to process the
// probe presence
Presence presence = new Presence();
presence.setType(Presence.Type.probe);
presence.setFrom(prober);
presence.setTo(probee);
component.processPacket(presence);
}
else {
// The probee may be related to a component that has not yet been connected so
// we will keep a registry of this presence probe. The component will answer
// this presence probe when he becomes online
componentManager.addPresenceRequest(prober, probee);
// Check if the probee may be hosted by this server
/*String serverDomain = server.getServerInfo().getName();
if (!probee.getDomain().contains(serverDomain)) {*/
if (server.isRemote(probee)) {
// Send the probe presence to the remote server
Presence probePresence = new Presence();
probePresence.setType(Presence.Type.probe);
probePresence.setFrom(prober);
probePresence.setTo(probee.toBareJID());
// Send the probe presence
deliverer.deliver(probePresence);
}
else {
// The probee may be related to a component that has not yet been connected so
// we will keep a registry of this presence probe. The component will answer
// this presence probe when he becomes online
componentManager.addPresenceRequest(prober, probee);
}
}
}
}
......@@ -367,7 +369,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public Component getPresenceComponent(JID probee) {
// Check for registered components
Component component = componentManager.getComponent(probee.toBareJID());
Component component = componentManager.getComponent(probee);
if (component != null) {
return component;
}
......
......@@ -133,7 +133,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
public Iterator getRoutes(JID node) {
// Check if the address belongs to a remote server
if (!serverName.equals(node.getDomain()) && routes.get(node.getDomain()) == null &&
componentManager.getComponent(node.getDomain()) == null) {
componentManager.getComponent(node) == null) {
// Return a promise of a remote session. This object will queue packets pending
// to be sent to remote servers
return Arrays.asList(OutgoingSessionPromise.getInstance()).iterator();
......
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