james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r731334 - in /james/protocols/imap/trunk: jpa/src/main/java/org/apache/james/imap/jpa/ mailbox/src/main/java/org/apache/james/imap/mailbox/ mailbox/src/main/java/org/apache/james/imap/mailbox/util/ mailbox/src/test/java/org/apache/james/ima...
Date Sun, 04 Jan 2009 19:00:13 GMT
Author: rdonkin
Date: Sun Jan  4 11:00:13 2009
New Revision: 731334

URL: http://svn.apache.org/viewvc?rev=731334&view=rev
Log:
Listeners should know when they are closed.

Modified:
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidToMsnConverter.java
    james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/EventCollector.java
    james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxListenerCollector.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
    james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
(original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
Sun Jan  4 11:00:13 2009
@@ -364,10 +364,6 @@
         tracker.addMailboxListener(listener);
     }
 
-    public void removeListener(MailboxListener mailboxListener) {
-        tracker.removeMailboxListener(mailboxListener);
-    }
-
     public long getUidValidity(MailboxSession mailboxSession) throws MailboxException {
         final long result = getMailboxRow().getUidValidity();
         return result;

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
Sun Jan  4 11:00:13 2009
@@ -179,15 +179,15 @@
             MailboxSession mailboxSession) throws MailboxException;
 
     /**
-     * Implementations of Mailbox may interpret the fact that someone is
+     * <p>Implementations of Mailbox may interpret the fact that someone is
      * listening and do some caching and even postpone persistence until
      * everyone has removed itself.
-     * 
-     * @param listener
+     * </p><p>
+     * Listeners should return true from {@link MailboxListener#isClosed()}
+     * when they are ready to be removed.
+     * </p>
+     * @param listener not null
      * @throws MailboxException
      */
     void addListener(MailboxListener listener) throws MailboxException;
-
-    void removeListener(MailboxListener listener);
-
 }

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
Sun Jan  4 11:00:13 2009
@@ -25,11 +25,26 @@
 
 /**
  * Listens to <code>Mailbox</code> events.
+ * Note that listeners may be removed asynchronously.
+ * When {@link #isClosed()} returns true,
+ * the listener may be removed from the mailbox by
+ * the dispatcher.
  */
-
 public interface MailboxListener {
 
+    /**
+     * Informs this listener about the given event.
+     * @param event not null
+     */
     void event(final Event event);
+    
+    /**
+     * Is this listener closed?
+     * Closed listeners may be unsubscribed.
+     * @return true when closed,
+     * false when open
+     */
+    boolean isClosed();
 
     /**
      * A mailbox event.

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventAnalyser.java
Sun Jan  4 11:00:13 2009
@@ -40,6 +40,7 @@
     private boolean sizeChanged = false;
     private boolean silentFlagChanges = false;
     private String mailboxName;
+    private boolean closed = false;
 
     public MailboxEventAnalyser(final long sessionId, final String mailboxName) {
         super();
@@ -160,4 +161,12 @@
     public boolean hasExpungedUids() {
         return !expungedUids.isEmpty();
     }
+
+    public void close() {
+        closed = true;
+    }
+    
+    public boolean isClosed() {
+        return closed;
+    }
 }

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
Sun Jan  4 11:00:13 2009
@@ -19,6 +19,8 @@
 
 package org.apache.james.imap.mailbox.util;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Set;
@@ -33,15 +35,25 @@
 
     private final Set<MailboxListener> listeners = new CopyOnWriteArraySet<MailboxListener>();
 
+    private void pruneClosed() {
+        final Collection<MailboxListener> closedListeners = new ArrayList<MailboxListener>();
+        for (MailboxListener listener:listeners) {
+            if (listener.isClosed()) {
+                closedListeners.add(listener);
+            }
+        }
+        if (!closedListeners.isEmpty()) {
+            listeners.removeAll(closedListeners);
+        }
+    }
+    
     public void addMailboxListener(MailboxListener mailboxListener) {
+        pruneClosed();
         listeners.add(mailboxListener);
     }
 
-    public void removeMailboxListener(MailboxListener mailboxListener) {
-        listeners.remove(mailboxListener);
-    }
-
     public void added(long uid, long sessionId) {
+        pruneClosed();
         final AddedImpl added = new AddedImpl(sessionId, uid);
         for (Iterator iter = listeners.iterator(); iter.hasNext();) {
             MailboxListener mailboxListener = (MailboxListener) iter.next();
@@ -269,4 +281,8 @@
             return sessionId;
         }
     }
+
+    public boolean isClosed() {
+        return false;
+    }
 }

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
Sun Jan  4 11:00:13 2009
@@ -231,11 +231,7 @@
     public synchronized void addMailboxListener(MailboxListener listener) {
         eventDispatcher.addMailboxListener(listener);
     }
-
-    public synchronized void removeMailboxListener(MailboxListener listener) {
-        eventDispatcher.removeMailboxListener(listener);
-    }
-
+    
     public synchronized void mailboxDeleted(long sessionId) {
         eventDispatcher.mailboxDeleted(sessionId);
     }

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidToMsnConverter.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidToMsnConverter.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidToMsnConverter.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidToMsnConverter.java
Sun Jan  4 11:00:13 2009
@@ -37,6 +37,8 @@
 
     private int highestMsn = 0;
 
+    private boolean closed = false;
+
     public UidToMsnConverter(final Collection<Long> uids) {
         msnToUid = new TreeMap<Integer, Long>();
         uidToMsn = new TreeMap<Long, Integer>();
@@ -129,4 +131,12 @@
             }
         }
     }
+
+    public void close() {
+        closed = true;
+    }
+    
+    public boolean isClosed() {
+        return closed;
+    }
 }

Modified: james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/EventCollector.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/EventCollector.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/EventCollector.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/EventCollector.java
Sun Jan  4 11:00:13 2009
@@ -26,7 +26,7 @@
 
 public class EventCollector implements MailboxListener {
 
-    public final List events = new ArrayList();
+    public final List<Event> events = new ArrayList<Event>();
 
     public void event(Event event) {
         events.add(event);
@@ -38,4 +38,8 @@
     public void mailboxRenamed(String origName, String newName) {
     }
 
+    public boolean isClosed() {
+        return false;
+    }
+
 }

Modified: james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxListenerCollector.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxListenerCollector.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxListenerCollector.java
(original)
+++ james/protocols/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxListenerCollector.java
Sun Jan  4 11:00:13 2009
@@ -95,4 +95,8 @@
         }
     }
 
+    public boolean isClosed() {
+        return false;
+    }
+
 }

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
(original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
Sun Jan  4 11:00:13 2009
@@ -36,8 +36,6 @@
 public class SelectedMailboxImpl extends AbstractLogEnabled implements
         SelectedMailbox {
 
-    private final Mailbox mailbox;
-
     private final MailboxEventAnalyser events;
 
     private final UidToMsnConverter converter;
@@ -48,7 +46,6 @@
 
     public SelectedMailboxImpl(final Mailbox mailbox, final List<Long> uids,
             final MailboxSession mailboxSession, final String name) throws MailboxException
{
-        this.mailbox = mailbox;
         recentUids = new TreeSet<Long>();
         recentUidRemoved = false;
         final long sessionId = mailboxSession.getSessionId();
@@ -64,7 +61,8 @@
      * @see org.apache.james.api.imap.process.SelectedMailbox#deselect()
      */
     public void deselect() {
-        mailbox.removeListener(events);
+        converter.close();
+        events.close();
     }
 
     public boolean isSizeChanged() {

Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=731334&r1=731333&r2=731334&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
(original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
Sun Jan  4 11:00:13 2009
@@ -582,13 +582,6 @@
         tracker.addMailboxListener(listener);
     }
 
-    public void removeListener(MailboxListener mailboxListener) {
-        if (!open) {
-            throw new RuntimeException("mailbox not open");
-        }
-        tracker.removeMailboxListener(mailboxListener);
-    }
-
     public long getUidValidity(MailboxSession mailboxSession)
             throws MailboxException {
         try {



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message