james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r544933 - in /james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src: main/java/org/apache/james/experimental/imapserver/ main/java/org/apache/james/experimental/imapserver/processor/ main/java/org/apache/james/experimen...
Date Wed, 06 Jun 2007 20:06:54 GMT
Author: rdonkin
Date: Wed Jun  6 13:06:53 2007
New Revision: 544933

URL: http://svn.apache.org/viewvc?view=rev&rev=544933
Log:
Improve naming consistency. Pushed business logic from session into mailbox.

Added:
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/SelectedMailboxSession.java
Removed:
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/ImapRequestProcessor.java
Modified:
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSession.java
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSessionImpl.java
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/MockImapSession.java
    james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/handler/commands/LoginTest.java

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSession.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSession.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSession.java
Wed Jun  6 13:06:53 2007
@@ -73,7 +73,7 @@
      * the supplied user.
      * @param user The user who is authenticated for this session.
      */
-    void setAuthenticated( User user );
+    void authenticated( User user );
 
     /**
      * Provides the authenticated user for this session, or <code>null</code>
if this
@@ -90,7 +90,7 @@
      * @param readOnly If <code>true</code>, the selection is set to be read
only.
      * @throws MailboxManagerException 
      */
-    void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException;
+    void selected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException;
 
     /**
      * Moves the session out of {@link ImapSessionState#SELECTED} state and back into

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSessionImpl.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSessionImpl.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/ImapSessionImpl.java
Wed Jun  6 13:06:53 2007
@@ -20,24 +20,14 @@
 package org.apache.james.experimental.imapserver;
 
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import javax.mail.Flags;
-
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.commons.collections.ListUtils;
 import org.apache.james.api.imap.ImapConstants;
 import org.apache.james.api.imap.ImapSessionState;
-import org.apache.james.api.imap.message.MessageFlags;
-import org.apache.james.imap.message.response.imap4rev1.ExistsResponse;
-import org.apache.james.imap.message.response.imap4rev1.ExpungeResponse;
-import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
-import org.apache.james.imap.message.response.imap4rev1.RecentResponse;
-import org.apache.james.imap.message.response.imap4rev1.status.UntaggedNoResponse;
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
 import org.apache.james.services.User;
 
@@ -76,103 +66,13 @@
     public List unsolicitedResponses(boolean omitExpunged, boolean useUid) {
         final List results;
         final SelectedMailboxSession selected = getSelected();
-            if (selected == null) {
+        if (selected == null) {
             results = ListUtils.EMPTY_LIST;
         } else {
-            results = new ArrayList();
-            final ImapMailboxSession mailbox = selected.getMailbox();
-            // New message response
-            if (selected.isSizeChanged()) {
-                selected.setSizeChanged(false);
-                addExistsResponses(results, mailbox);
-                addRecentResponses(results, mailbox);
-            }
-
-            // Message updates
-            // TODO: slow to check flags every time
-            // TODO: add conditional to selected mailbox
-            addFlagsResponses(results, useUid, mailbox);
-
-            // Expunged messages
-            if (!omitExpunged) {
-                // TODO: slow to check flags every time
-                // TODO: add conditional to selected mailbox
-                addExpungedResponses(results, mailbox);
-            }
+            results = selected.unsolicitedResponses(omitExpunged, useUid);
         }
         return results;
     }
-
-    private void addExpungedResponses(List responses, final ImapMailboxSession mailbox) {
-        try {
-            MessageResult[] expunged = mailbox.getExpungedEvents(true);
-            for (int i = 0; i < expunged.length; i++) {
-                MessageResult mr = expunged[i];
-                final int msn = mr.getMsn();
-                // TODO: use factory
-                ExpungeResponse response = new ExpungeResponse(msn);
-                responses.add(response);
-            }
-        } catch (MailboxManagerException e) {
-            final String message = "Failed to retrieve expunged count data";
-            handleResponseException(responses, e, message);
-        }
-    }
-
-    private void addFlagsResponses(final List responses, boolean useUid, final ImapMailboxSession
mailbox) {
-        try {
-            MessageResult[] flagUpdates = mailbox.getFlagEvents(true);
-                for (int i = 0; i < flagUpdates.length; i++) {
-                MessageResult mr = flagUpdates[i];
-                int msn = mr.getMsn();
-                Flags updatedFlags = mr.getFlags();
-                StringBuffer out = new StringBuffer("FLAGS ");
-                out.append(MessageFlags.format(updatedFlags));
-                if (useUid) {
-                    out.append(" UID ");
-                    out.append(mr.getUid());
-                }
-                // TODO: use CharSequence instead (avoid unnecessary string creation)
-                FetchResponse response = new FetchResponse(msn, out.toString());
-                responses.add(response);
-            }
-        } catch (MailboxManagerException e) {
-            final String message = "Failed to retrieve flags data";
-            handleResponseException(responses, e, message);
-        }
-    }
-
-    private void addRecentResponses(final List responses, final ImapMailboxSession mailbox)
{
-        try {
-            final int recentCount = mailbox.getRecentCount(true);
-            // TODO: use factory
-            RecentResponse response = new RecentResponse(recentCount);
-            responses.add(response);
-        } catch (MailboxManagerException e) {
-            final String message = "Failed to retrieve recent count data";
-            handleResponseException(responses, e, message);
-        }
-    }
-
-    private void handleResponseException(final List responses, MailboxManagerException e,
final String message) {
-        getLogger().info(message);
-        getLogger().debug(message, e);
-        // TODO: consider whether error message should be passed to the user
-        UntaggedNoResponse response = new UntaggedNoResponse(message, null);
-        responses.add(response);
-    }
-
-    private void addExistsResponses(final List responses, final ImapMailboxSession mailbox)
{
-            try {
-                final int messageCount = mailbox.getMessageCount();
-                // TODO: use factory
-                ExistsResponse response = new ExistsResponse(messageCount);
-                responses.add(response);
-            } catch (MailboxManagerException e) {
-                final String message = "Failed to retrieve exists count data";
-                handleResponseException(responses, e, message);
-            }
-    }
     
     public void closeConnection(String byeMessage) {
         closeMailbox();
@@ -195,7 +95,7 @@
         return clientAddress;
     }
 
-    public void setAuthenticated( User user )
+    public void authenticated( User user )
     {
         this.state = ImapSessionState.AUTHENTICATED;
         this.user = user;
@@ -212,9 +112,9 @@
         closeMailbox();
     }
 
-    public void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException
+    public void selected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException
     {
-        SelectedMailboxSession sessionMailbox = new SelectedMailboxSession(mailbox, this,
readOnly);
+        SelectedMailboxSession sessionMailbox = new SelectedMailboxSession(mailbox, this);
         setupLogger(sessionMailbox);
         this.state = ImapSessionState.SELECTED;
         closeMailbox();

Added: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/SelectedMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/SelectedMailboxSession.java?view=auto&rev=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/SelectedMailboxSession.java
(added)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/SelectedMailboxSession.java
Wed Jun  6 13:06:53 2007
@@ -0,0 +1,209 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.apache.james.experimental.imapserver;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.Flags;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.api.imap.message.MessageFlags;
+import org.apache.james.imap.message.response.imap4rev1.ExistsResponse;
+import org.apache.james.imap.message.response.imap4rev1.ExpungeResponse;
+import org.apache.james.imap.message.response.imap4rev1.FetchResponse;
+import org.apache.james.imap.message.response.imap4rev1.RecentResponse;
+import org.apache.james.imap.message.response.imap4rev1.status.UntaggedNoResponse;
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+
+public class SelectedMailboxSession extends AbstractLogEnabled implements MailboxListener
{
+
+    private ImapSession _session;
+    private boolean _sizeChanged;
+    private List expungedMsn = new ArrayList();
+    private ImapMailboxSession mailbox;
+
+    public SelectedMailboxSession(ImapMailboxSession mailbox, ImapSession session) throws
MailboxManagerException {
+        this.mailbox = mailbox;
+        _session = session;
+        // TODO make this a weak reference (or make sure deselect() is *always* called).
+        mailbox.addListener(this,MessageResult.MSN | MessageResult.UID);
+    }
+
+    public void deselect() {
+        mailbox.removeListener(this);
+        mailbox = null;
+    }
+
+
+    public void mailboxDeleted() {
+        try {
+            _session.closeConnection("Mailbox " + mailbox.getName() + " has been deleted");
+        } catch (MailboxManagerException e) {
+            getLogger().error("error closing connection", e);
+        }
+    }
+
+
+    public boolean isSizeChanged() {
+        return _sizeChanged;
+    }
+
+    public void setSizeChanged(boolean sizeChanged) {
+        _sizeChanged = sizeChanged;
+    }
+    
+
+    public void close() throws MailboxManagerException  {
+        mailbox.close();
+        mailbox=null;
+    }
+
+    public void create() {
+        throw new RuntimeException("should not create a selected mailbox");
+        
+    }
+
+    public void expunged(MessageResult mr) {
+        expungedMsn.add(new Integer(mr.getSize()));
+    }
+
+    public void added(MessageResult mr) {
+       _sizeChanged = true;
+    }
+
+    public void flagsUpdated(MessageResult mr,MailboxListener silentListener) {
+    }
+
+    public ImapMailboxSession getMailbox() {
+        return mailbox;
+    }
+
+    public void mailboxRenamed(String origName, String newName) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void mailboxRenamed(String newName) {
+        // TODO Auto-generated method stub
+        
+    }
+    
+
+    public List unsolicitedResponses(boolean omitExpunged, boolean useUid) {
+        final List results = new ArrayList();
+        final ImapMailboxSession mailbox = getMailbox();
+        // New message response
+        if (isSizeChanged()) {
+            setSizeChanged(false);
+            addExistsResponses(results, mailbox);
+            addRecentResponses(results, mailbox);
+        }
+
+        // Message updates
+        // TODO: slow to check flags every time
+        // TODO: add conditional to selected mailbox
+        addFlagsResponses(results, useUid, mailbox);
+
+        // Expunged messages
+        if (!omitExpunged) {
+            // TODO: slow to check flags every time
+            // TODO: add conditional to selected mailbox
+            addExpungedResponses(results, mailbox);
+        }
+        
+        return results;
+    }
+
+    private void addExpungedResponses(List responses, final ImapMailboxSession mailbox) {
+        try {
+            MessageResult[] expunged = mailbox.getExpungedEvents(true);
+            for (int i = 0; i < expunged.length; i++) {
+                MessageResult mr = expunged[i];
+                final int msn = mr.getMsn();
+                // TODO: use factory
+                ExpungeResponse response = new ExpungeResponse(msn);
+                responses.add(response);
+            }
+        } catch (MailboxManagerException e) {
+            final String message = "Failed to retrieve expunged count data";
+            handleResponseException(responses, e, message);
+        }
+    }
+
+    private void addFlagsResponses(final List responses, boolean useUid, final ImapMailboxSession
mailbox) {
+        try {
+            MessageResult[] flagUpdates = mailbox.getFlagEvents(true);
+                for (int i = 0; i < flagUpdates.length; i++) {
+                MessageResult mr = flagUpdates[i];
+                int msn = mr.getMsn();
+                Flags updatedFlags = mr.getFlags();
+                StringBuffer out = new StringBuffer("FLAGS ");
+                out.append(MessageFlags.format(updatedFlags));
+                if (useUid) {
+                    out.append(" UID ");
+                    out.append(mr.getUid());
+                }
+                // TODO: use CharSequence instead (avoid unnecessary string creation)
+                FetchResponse response = new FetchResponse(msn, out.toString());
+                responses.add(response);
+            }
+        } catch (MailboxManagerException e) {
+            final String message = "Failed to retrieve flags data";
+            handleResponseException(responses, e, message);
+        }
+    }
+
+    private void addRecentResponses(final List responses, final ImapMailboxSession mailbox)
{
+        try {
+            final int recentCount = mailbox.getRecentCount(true);
+            // TODO: use factory
+            RecentResponse response = new RecentResponse(recentCount);
+            responses.add(response);
+        } catch (MailboxManagerException e) {
+            final String message = "Failed to retrieve recent count data";
+            handleResponseException(responses, e, message);
+        }
+    }
+
+    private void handleResponseException(final List responses, MailboxManagerException e,
final String message) {
+        getLogger().info(message);
+        getLogger().debug(message, e);
+        // TODO: consider whether error message should be passed to the user
+        UntaggedNoResponse response = new UntaggedNoResponse(message, null);
+        responses.add(response);
+    }
+
+    private void addExistsResponses(final List responses, final ImapMailboxSession mailbox)
{
+            try {
+                final int messageCount = mailbox.getMessageCount();
+                // TODO: use factory
+                ExistsResponse response = new ExistsResponse(messageCount);
+                responses.add(response);
+            } catch (MailboxManagerException e) {
+                final String message = "Failed to retrieve exists count data";
+                handleResponseException(responses, e, message);
+            }
+    }
+
+}

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/AbstractMailboxSelectionProcessor.java
Wed Jun  6 13:06:53 2007
@@ -82,7 +82,7 @@
             throw new MailboxException( "Nonselectable mailbox." );
         }
 
-        session.setSelected( mailbox, readOnly );
+        session.selected( mailbox, readOnly );
         return readOnly;
     }
 }

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/main/java/org/apache/james/experimental/imapserver/processor/imap4rev1/LoginProcessor.java
Wed Jun  6 13:06:53 2007
@@ -67,7 +67,7 @@
         final ImapResponseMessage result;
         if ( users.test( userid, password ) ) {
             User user = users.getUserByName( userid );
-            session.setAuthenticated( user );
+            session.authenticated( user );
             result = new CommandCompleteResponse(command, tag);
         }
         else {

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/MockImapSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/MockImapSession.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/MockImapSession.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/MockImapSession.java
Wed Jun  6 13:06:53 2007
@@ -63,11 +63,11 @@
         return null;
     }
 
-    public void setAuthenticated(User user) {
+    public void authenticated(User user) {
 
     }
 
-    public void setSelected(ImapMailboxSession mailbox, boolean readOnly)
+    public void selected(ImapMailboxSession mailbox, boolean readOnly)
             throws MailboxManagerException {
     }
 

Modified: james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/handler/commands/LoginTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/handler/commands/LoginTest.java?view=diff&rev=544933&r1=544932&r2=544933
==============================================================================
--- james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/handler/commands/LoginTest.java
(original)
+++ james/server/sandbox/seda-imap-modular/experimental-seda-imap-function/src/test/java/org/apache/james/experimental/imapserver/handler/commands/LoginTest.java
Wed Jun  6 13:06:53 2007
@@ -14,7 +14,7 @@
         mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(true));
         mockUsersRepository.expects(once()).method("getUserByName").with( eq("joachim2")).will(returnValue(mockUser.proxy()));
         
-        mockSession.expects(once()).method("setAuthenticated").with( same(mockUser.proxy()));
+        mockSession.expects(once()).method("authenticated").with( same(mockUser.proxy()));
 
         String response = handleRequest("1 LOGIN joachim2 abc\n");
 



---------------------------------------------------------------------
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