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

Added support for offline listeners. JM-912

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6751 b35dd754-fafc-0310-a699-88a17e54d16e
parent e75ca67e
......@@ -3,7 +3,7 @@
* $Revision: 3114 $
* $Date: 2005-11-23 18:12:54 -0300 (Wed, 23 Nov 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
......@@ -21,6 +21,9 @@ import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Controls what is done with offline messages.
*
......@@ -31,6 +34,8 @@ public class OfflineMessageStrategy extends BasicModule {
private static int quota = 100*1024; // Default to 100 K.
private static Type type = Type.store_and_bounce;
private static List<OfflineMessageListener> listeners = new CopyOnWriteArrayList<OfflineMessageListener>();
private OfflineMessageStore messageStore;
private JID serverAddress;
private PacketRouter router;
......@@ -104,12 +109,39 @@ public class OfflineMessageStrategy extends BasicModule {
}
}
/**
* Registers a listener to receive events.
*
* @param listener the listener.
*/
public static void addListener(OfflineMessageListener listener) {
if (listener == null) {
throw new NullPointerException();
}
listeners.add(listener);
}
/**
* Unregisters a listener to receive events.
*
* @param listener the listener.
*/
public static void removeListener(OfflineMessageListener listener) {
listeners.remove(listener);
}
private boolean underQuota(Message message) {
return quota > messageStore.getSize(message.getTo().getNode()) + message.toXML().length();
}
private void store(Message message) {
messageStore.addMessage(message);
// Inform listeners that an offline message was stored
if (!listeners.isEmpty()) {
for (OfflineMessageListener listener : listeners) {
listener.messageStored(message);
}
}
}
private void bounce(Message message) {
......@@ -126,6 +158,12 @@ public class OfflineMessageStrategy extends BasicModule {
errorResponse.setTo(message.getFrom());
// Send the response
router.route(errorResponse);
// Inform listeners that an offline message was bounced
if (!listeners.isEmpty()) {
for (OfflineMessageListener listener : listeners) {
listener.messageBounced(message);
}
}
}
catch (Exception e) {
Log.error(e);
......
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