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; ...@@ -14,6 +14,10 @@ package org.jivesoftware.wildfire;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager; 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.AuditManager;
import org.jivesoftware.wildfire.audit.spi.AuditManagerImpl; import org.jivesoftware.wildfire.audit.spi.AuditManagerImpl;
import org.jivesoftware.wildfire.commands.AdHocCommandHandler; import org.jivesoftware.wildfire.commands.AdHocCommandHandler;
...@@ -33,10 +37,6 @@ import org.jivesoftware.wildfire.roster.RosterManager; ...@@ -33,10 +37,6 @@ import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.spi.*; import org.jivesoftware.wildfire.spi.*;
import org.jivesoftware.wildfire.transport.TransportHandler; import org.jivesoftware.wildfire.transport.TransportHandler;
import org.jivesoftware.wildfire.user.UserManager; 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 org.xmpp.packet.JID;
import java.io.File; import java.io.File;
...@@ -172,8 +172,7 @@ public class XMPPServer { ...@@ -172,8 +172,7 @@ public class XMPPServer {
*/ */
public boolean isRemote(JID jid) { public boolean isRemote(JID jid) {
if (jid != null) { if (jid != null) {
String domain = jid.getDomain(); if (!name.equals(jid.getDomain()) && componentManager.getComponent(jid) == null) {
if (!name.equals(domain) && componentManager.getComponent(domain) == null) {
return true; return true;
} }
} }
...@@ -188,7 +187,7 @@ public class XMPPServer { ...@@ -188,7 +187,7 @@ public class XMPPServer {
*/ */
public boolean matchesComponent(JID jid) { public boolean matchesComponent(JID jid) {
if (jid != null) { if (jid != null) {
return componentManager.getComponent(jid.getDomain()) != null; return !name.equals(jid.getDomain()) && componentManager.getComponent(jid) != null;
} }
return false; return false;
} }
......
...@@ -213,22 +213,20 @@ public class InternalComponentManager implements ComponentManager, RoutableChann ...@@ -213,22 +213,20 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
* @return the component with the specified id. * @return the component with the specified id.
*/ */
public Component getComponent(JID componentJID) { public Component getComponent(JID componentJID) {
String jid = componentJID.toBareJID(); Component component = components.get(componentJID.getDomain());
if (components.containsKey(jid)) { if (component != null) {
return components.get(jid); return component;
} }
else { else {
if (!jid.contains(serverDomain)) { // Search again for those JIDs whose domain include the server name but this
// Ignore JIDs that doesn't belong to this server // time remove the server name from the JID's domain
return null; String serverName = componentJID.getDomain();
int index = serverName.lastIndexOf(serverDomain);
if (index > 0) {
return components.get(serverName.substring(0, --index));
} }
String serverName = new JID(jid).getDomain();
int index = serverName.indexOf(".");
if (index != -1) {
jid = serverName.substring(0, index);
} }
} return null;
return components.get(jid);
} }
/** /**
...@@ -256,7 +254,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann ...@@ -256,7 +254,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
for (JID prober : presenceMap.keySet()) { for (JID prober : presenceMap.keySet()) {
JID probee = presenceMap.get(prober); JID probee = presenceMap.get(prober);
Component component = getComponent(probee.toBareJID()); Component component = getComponent(probee);
if (component != null) { if (component != null) {
Presence presence = new Presence(); Presence presence = new Presence();
presence.setFrom(prober); presence.setFrom(prober);
...@@ -300,7 +298,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann ...@@ -300,7 +298,7 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
* @param packet the packet to process. * @param packet the packet to process.
*/ */
public void process(Packet packet) throws PacketException { 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 // Only process packets that were sent by registered components
if (component != null) { if (component != null) {
if (packet instanceof IQ && IQ.Type.result == ((IQ) packet).getType()) { if (packet instanceof IQ && IQ.Type.result == ((IQ) packet).getType()) {
......
...@@ -246,7 +246,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -246,7 +246,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public void probePresence(JID prober, JID probee) { public void probePresence(JID prober, JID probee) {
try { try {
Component component = getPresenceComponent(probee);
if (server.isLocal(probee)) { if (server.isLocal(probee)) {
// If the probee is a local user then don't send a probe to the contact's server. // 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 // But instead just send the contact's presence to the prober
...@@ -297,7 +296,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -297,7 +296,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
} }
else if (component != null) { else {
Component component = getPresenceComponent(probee);
if (component != null) {
// If the probee belongs to a component then ask the component to process the // If the probee belongs to a component then ask the component to process the
// probe presence // probe presence
Presence presence = new Presence(); Presence presence = new Presence();
...@@ -327,6 +328,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -327,6 +328,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
} }
}
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
...@@ -367,7 +369,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -367,7 +369,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public Component getPresenceComponent(JID probee) { public Component getPresenceComponent(JID probee) {
// Check for registered components // Check for registered components
Component component = componentManager.getComponent(probee.toBareJID()); Component component = componentManager.getComponent(probee);
if (component != null) { if (component != null) {
return component; return component;
} }
......
...@@ -133,7 +133,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -133,7 +133,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
public Iterator getRoutes(JID node) { public Iterator getRoutes(JID node) {
// Check if the address belongs to a remote server // Check if the address belongs to a remote server
if (!serverName.equals(node.getDomain()) && routes.get(node.getDomain()) == null && 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 // Return a promise of a remote session. This object will queue packets pending
// to be sent to remote servers // to be sent to remote servers
return Arrays.asList(OutgoingSessionPromise.getInstance()).iterator(); 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