Commit adc51827 authored by guus's avatar guus

OF-605: Remove cache-the-world solution in IQPEPHandler.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13423 b35dd754-fafc-0310-a699-88a17e54d16e
parent 61b4df3c
...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.interceptor.InterceptorManager; ...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.user.RemotePresenceEventDispatcher;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -153,14 +152,6 @@ public class PresenceRouter extends BasicModule { ...@@ -153,14 +152,6 @@ public class PresenceRouter extends BasicModule {
if (senderJID != null && !serverName.equals(senderJID.getDomain()) && if (senderJID != null && !serverName.equals(senderJID.getDomain()) &&
!routingTable.hasComponentRoute(senderJID)) { !routingTable.hasComponentRoute(senderJID)) {
entityCapsManager.process(packet); entityCapsManager.process(packet);
if (type == null) {
// Remote user has become available
RemotePresenceEventDispatcher.remoteUserAvailable(packet);
}
else if (type == Presence.Type.unavailable) {
// Remote user is now unavailable
RemotePresenceEventDispatcher.remoteUserUnavailable(packet);
}
} }
// Check that sender session is still active (let unavailable presence go through) // Check that sender session is still active (let unavailable presence go through)
......
...@@ -21,11 +21,8 @@ ...@@ -21,11 +21,8 @@
package org.jivesoftware.openfire.pep; package org.jivesoftware.openfire.pep;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -57,8 +54,6 @@ import org.jivesoftware.openfire.roster.RosterManager; ...@@ -57,8 +54,6 @@ import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.user.PresenceEventDispatcher; import org.jivesoftware.openfire.user.PresenceEventDispatcher;
import org.jivesoftware.openfire.user.PresenceEventListener; import org.jivesoftware.openfire.user.PresenceEventListener;
import org.jivesoftware.openfire.user.RemotePresenceEventDispatcher;
import org.jivesoftware.openfire.user.RemotePresenceEventListener;
import org.jivesoftware.openfire.user.User; import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
...@@ -101,7 +96,7 @@ import org.xmpp.packet.Presence; ...@@ -101,7 +96,7 @@ import org.xmpp.packet.Presence;
* @author Guus der Kinderen, guus.der.kinderen@gmail.com * @author Guus der Kinderen, guus.der.kinderen@gmail.com
*/ */
public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider, public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider,
UserIdentitiesProvider, UserItemsProvider, PresenceEventListener, RemotePresenceEventListener, UserIdentitiesProvider, UserItemsProvider, PresenceEventListener,
RosterEventListener, UserEventListener { RosterEventListener, UserEventListener {
private static final Logger Log = LoggerFactory.getLogger(IQPEPHandler.class); private static final Logger Log = LoggerFactory.getLogger(IQPEPHandler.class);
...@@ -128,15 +123,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -128,15 +123,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// depend on database access (ideally, these should get dedicated resource // depend on database access (ideally, these should get dedicated resource
// pools too). // pools too).
private ExecutorService executor = null; private ExecutorService executor = null;
/**
* A map of all known full JIDs that have sent presences from a remote server.
* table: key Bare JID (String); value Set of JIDs
*
* This map is convenient for sending notifications to the full JID of remote users
* that have sent available presences to the PEP service.
*/
private Map<String, Set<JID>> knownRemotePresences = new ConcurrentHashMap<String, Set<JID>>();
/** /**
* Constructs a new {@link IQPEPHandler} instance. * Constructs a new {@link IQPEPHandler} instance.
...@@ -189,8 +175,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -189,8 +175,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// Listen to presence events to manage PEP auto-subscriptions. // Listen to presence events to manage PEP auto-subscriptions.
PresenceEventDispatcher.addListener(this); PresenceEventDispatcher.addListener(this);
// Listen to remote presence events to manage the knownRemotePresences map.
RemotePresenceEventDispatcher.addListener(this);
// Listen to roster events for PEP subscription cancelling on contact deletion. // Listen to roster events for PEP subscription cancelling on contact deletion.
RosterEventDispatcher.addListener(this); RosterEventDispatcher.addListener(this);
// Listen to user events in order to destroy a PEP service when a user is deleted. // Listen to user events in order to destroy a PEP service when a user is deleted.
...@@ -208,7 +192,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -208,7 +192,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// Remove listeners // Remove listeners
PresenceEventDispatcher.removeListener(this); PresenceEventDispatcher.removeListener(this);
RemotePresenceEventDispatcher.removeListener(this);
RosterEventDispatcher.removeListener(this); RosterEventDispatcher.removeListener(this);
UserEventDispatcher.removeListener(this); UserEventDispatcher.removeListener(this);
...@@ -440,15 +423,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -440,15 +423,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// Other error flows were handled in pubSubEngine.process(...) // Other error flows were handled in pubSubEngine.process(...)
return null; return null;
} }
/**
* Returns the knownRemotePresences map.
*
* @return the knownRemotePresences map
*/
public Map<String, Set<JID>> getKnownRemotePresences() {
return knownRemotePresences;
}
/** /**
* Generates and processes an IQ stanza that subscribes to a PEP service. * Generates and processes an IQ stanza that subscribes to a PEP service.
...@@ -609,60 +583,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -609,60 +583,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
executor.submit(task); executor.submit(task);
} }
public void remoteUserAvailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
JID jidFrom = presence.getFrom();
JID jidTo = presence.getTo();
// Manage the cache of remote presence resources.
Set<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
if (jidFrom.getResource() != null) {
if (remotePresenceSet != null) {
remotePresenceSet.add(jidFrom);
}
else {
remotePresenceSet = new HashSet<JID>();
remotePresenceSet.add(jidFrom);
knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet);
}
// TODO Check the roster presence subscription to allow or ignore the received presence.
// TODO Directed presences should be ignored when no presence subscription exists
// Send the presence packet recipient's last published items to the remote user.
PEPService pepService = pepServiceManager.getPEPService(jidTo.toBareJID());
if (pepService != null) {
pepService.sendLastPublishedItems(jidFrom);
}
}
}
public void remoteUserUnavailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
final JID jidFrom = presence.getFrom();
final JID jidTo = presence.getTo();
// Manage the cache of remote presence resources.
final Set<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
if (remotePresenceSet != null) {
remotePresenceSet.remove(jidFrom);
}
}
public void contactDeleted(Roster roster, RosterItem item) { public void contactDeleted(Roster roster, RosterItem item) {
JID rosterOwner = XMPPServer.getInstance().createJID(roster.getUsername(), null); JID rosterOwner = XMPPServer.getInstance().createJID(roster.getUsername(), null);
JID deletedContact = item.getJid(); JID deletedContact = item.getJid();
cancelSubscriptionToPEPService(deletedContact, rosterOwner); cancelSubscriptionToPEPService(deletedContact, rosterOwner);
} }
public void userDeleting(User user, Map<String, Object> params) { public void userDeleting(User user, Map<String, Object> params) {
......
...@@ -348,17 +348,12 @@ public class PEPService implements PubSubService, Cacheable { ...@@ -348,17 +348,12 @@ public class PEPService implements PubSubService, Cacheable {
else { else {
// Since recipientJID is not local, try to get presence info from cached known remote // Since recipientJID is not local, try to get presence info from cached known remote
// presences. // presences.
Map<String, Set<JID>> knownRemotePresences = XMPPServer.getInstance().getIQPEPHandler()
.getKnownRemotePresences(); // TODO: OF-605 the old code depends on a cache that would contain presence state on all (?!) JIDS on all (?!)
// remote domains. As we cannot depend on this information to be correct (even if we could ensure that this
Set<JID> remotePresenceSet = knownRemotePresences.get(getAddress().toBareJID()); // potentially unlimited amount of data would indeed be manageable in the first place), this code was removed.
if (remotePresenceSet != null) {
for (JID remotePresence : remotePresenceSet) { recipientFullJIDs.add(recipientJID);
if (recipientJID.toBareJID().equals(remotePresence.toBareJID())) {
recipientFullJIDs.add(remotePresence);
}
}
}
} }
if (recipientFullJIDs.isEmpty()) { if (recipientFullJIDs.isEmpty()) {
......
/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.user;
import org.xmpp.packet.Presence;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Dispatches presence events of remote users. The following events are supported:
* <ul>
* <li><b>remoteUserAvailable</b> --> A remote user is now available.</li>
* <li><b>remoteUserUnavailable</b> --> A remote user is no longer available.</li>
* </ul>
* Use {@link #addListener(RemotePresenceEventListener)} and
* {@link #removeListener(RemotePresenceEventListener)} to add or remove {@link RemotePresenceEventListener}.
*
* @author Armando Jagucki
*/
public class RemotePresenceEventDispatcher {
private static List<RemotePresenceEventListener> listeners =
new CopyOnWriteArrayList<RemotePresenceEventListener>();
/**
* Registers a listener to receive events.
*
* @param listener the listener.
*/
public static void addListener(RemotePresenceEventListener listener) {
if (listener == null) {
throw new NullPointerException();
}
listeners.add(listener);
}
/**
* Unregisters a listener to receive events.
*
* @param listener the listener.
*/
public static void removeListener(RemotePresenceEventListener listener) {
listeners.remove(listener);
}
/**
* Notification message indicating that a remote user is now available or has changed
* his available presence. This event is triggered when an available presence is received
* by <tt>PresenceRouter</tt>.
*
* @param presence the received available presence.
*/
public static void remoteUserAvailable(Presence presence) {
if (!listeners.isEmpty()) {
for (RemotePresenceEventListener listener : listeners) {
listener.remoteUserAvailable(presence);
}
}
}
/**
* Notification message indicating that a remote user that was available is no longer
* available. A remote user becomes unavailable when an unavailable presence is received.
* by <tt>PresenceRouter</tt>.
*
* @param presence the received unavailable presence.
*/
public static void remoteUserUnavailable(Presence presence) {
if (!listeners.isEmpty()) {
for (RemotePresenceEventListener listener : listeners) {
listener.remoteUserUnavailable(presence);
}
}
}
}
/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.user;
import org.xmpp.packet.Presence;
/**
* Interface to listen for presence events of remote users. Use the
* {@link RemotePresenceEventDispatcher#addListener(RemotePresenceEventListener)}
* method to register for events.
*
* @author Armando Jagucki
*/
public interface RemotePresenceEventListener {
/**
* Notification message indicating that a remote user is now available or has changed
* his available presence. This event is triggered when an available presence is received
* by <tt>PresenceRouter</tt>.
*
* @param presence the received available presence.
*/
public void remoteUserAvailable(Presence presence);
/**
* Notification message indicating that a remote user is no longer available.
* A remote user becomes unavailable when an unavailable presence is received.
* by <tt>PresenceRouter</tt>.
*
* @param presence the received unavailable presence.
*/
public void remoteUserUnavailable(Presence presence);
}
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