james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r992659 - in /james/imap/trunk: deployment/src/test/java/org/apache/james/imap/functional/ mailbox/src/main/java/org/apache/james/imap/mailbox/ processor/src/main/java/org/apache/james/imap/processor/ processor/src/test/java/org/apache/jame...
Date Sat, 04 Sep 2010 18:57:38 GMT
Author: norman
Date: Sat Sep  4 18:57:37 2010
New Revision: 992659

URL: http://svn.apache.org/viewvc?rev=992659&view=rev
Log:
Add startProcessing, endProcessing methods to SubscriptionManager interface so we are able
to handle request scope operations. 

Added:
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
Modified:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/InMemoryUserManager.java
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/SubscriptionManager.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
    james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/InMemoryUserManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/InMemoryUserManager.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/InMemoryUserManager.java
(original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/InMemoryUserManager.java
Sat Sep  4 18:57:37 2010
@@ -91,4 +91,14 @@ public class InMemoryUserManager impleme
         user.setPassword(password);
     }
 
+    public void endProcessingRequest(MailboxSession session) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void startProcessingRequest(MailboxSession session) {
+        // TODO Auto-generated method stub
+        
+    }
+
 }

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/SubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/SubscriptionManager.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/SubscriptionManager.java
(original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/SubscriptionManager.java
Sat Sep  4 18:57:37 2010
@@ -52,4 +52,18 @@ public interface SubscriptionManager{
      */
     public void unsubscribe(MailboxSession session, String mailbox)
             throws SubscriptionException;
+    
+    /**
+     * Start the processing of a request for the given MailboxSession. If the user is not
logged in already then the MailboxSession will be null
+     * 
+     * @param session 
+     */
+    public void startProcessingRequest(MailboxSession session);
+    
+    /**
+     * End the processing of a request for the given MailboxSession. If the user is not logged
in already then the MailboxSession will be null
+     * 
+     * @param session 
+     */
+    public void endProcessingRequest(MailboxSession session);
 }

Added: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java?rev=992659&view=auto
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
(added)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
Sat Sep  4 18:57:37 2010
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.request.ImapRequest;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.SubscriptionManager;
+import org.apache.james.imap.processor.base.ImapSessionUtils;
+
+/**
+ * Abstract base class which should be used by implementations which need to access the {@link
SubscriptionManager}
+ *
+ */
+public abstract class AbstractSubscriptionProcessor extends AbstractMailboxProcessor{
+
+    private final SubscriptionManager subscriptionManager;
+
+    public AbstractSubscriptionProcessor(ImapProcessor next, MailboxManager mailboxManager,
final SubscriptionManager subscriptionManager,StatusResponseFactory factory) {
+        super(next, mailboxManager, factory);
+        this.subscriptionManager = subscriptionManager;
+    }
+
+    /**
+     * Return the {@link SubscriptionManager}
+     * 
+     * @return subscriptionManager
+     */
+    protected SubscriptionManager getSubscriptionManager() {
+        return subscriptionManager;
+    }
+
+    @Override
+    protected final void doProcess(ImapRequest message, ImapSession session, String tag,
ImapCommand command, Responder responder) {
+        
+        // take care of calling the start/end processing 
+        MailboxSession mSession = ImapSessionUtils.getMailboxSession(session);
+        getSubscriptionManager().startProcessingRequest(mSession);
+        doProcessRequest(message, session, tag, command, responder);
+        getSubscriptionManager().endProcessingRequest(mSession);
+    }
+    
+    /**
+     * Process the request
+     * 
+     * @param message
+     * @param session
+     * @param tag
+     * @param command
+     * @param responder
+     */
+    protected abstract void doProcessRequest(ImapRequest message, ImapSession session, String
tag, ImapCommand command, Responder responder);
+    
+}

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/LSubProcessor.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
Sat Sep  4 18:57:37 2010
@@ -42,59 +42,21 @@ import org.apache.james.imap.message.req
 import org.apache.james.imap.message.response.LSubResponse;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class LSubProcessor extends AbstractMailboxProcessor {
+public class LSubProcessor extends AbstractSubscriptionProcessor {
 
-    private final SubscriptionManager subscriptionManager;
-
-    public LSubProcessor(final ImapProcessor next,
-            final MailboxManager mailboxManager, 
-            final SubscriptionManager subscriptionManager,
-            final StatusResponseFactory factory) {
-        super(next, mailboxManager, factory);
-        this.subscriptionManager = subscriptionManager;
+    public LSubProcessor(ImapProcessor next, MailboxManager mailboxManager, SubscriptionManager
subscriptionManager, StatusResponseFactory factory) {
+        super(next, mailboxManager, subscriptionManager, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {
         return (message instanceof LsubRequest);
     }
 
-    protected void doProcess(ImapRequest message, ImapSession session,
-            String tag, ImapCommand command, Responder responder) {
-        final LsubRequest request = (LsubRequest) message;
-        final String referenceName = request.getBaseReferenceName();
-        final String mailboxPattern = request.getMailboxPattern();
-
-        try {
-            if (mailboxPattern.length() == 0) {
-                respondWithHierarchyDelimiter(responder);
-            } else {
-                listSubscriptions(session, responder, referenceName, mailboxPattern);
-            }
-
-            okComplete(command, tag, responder);
-
-        } catch (SubscriptionException e) {
-            session.getLog().debug("Subscription failed", e);
-            final HumanReadableText exceptionKey = e.getKey();
-            final HumanReadableText displayTextKey;
-            if (exceptionKey == null) {
-                displayTextKey = HumanReadableText.GENERIC_LSUB_FAILURE;
-            } else {
-                displayTextKey = exceptionKey;
-            }
-            no(command, tag, responder, displayTextKey);
-        } catch (MailboxException e) {
-            session.getLog().debug("Subscription failed", e);
-            final HumanReadableText displayTextKey = HumanReadableText.GENERIC_LSUB_FAILURE;
-            no(command, tag, responder, displayTextKey);
-        }
-    }
-
     private void listSubscriptions(ImapSession session, Responder responder,
             final String referenceName, final String mailboxName)
             throws SubscriptionException, MailboxException {
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
-        final Collection<String> mailboxes = subscriptionManager.subscriptions(mailboxSession);
+        final Collection<String> mailboxes = getSubscriptionManager().subscriptions(mailboxSession);
         // If the mailboxName is fully qualified, ignore the reference name.
         String finalReferencename = referenceName;
         
@@ -153,4 +115,36 @@ public class LSubProcessor extends Abstr
         final LSubResponse response = new LSubResponse("", true);
         responder.respond(response);
     }
+
+    @Override
+    protected void doProcessRequest(ImapRequest message, ImapSession session, String tag,
ImapCommand command, Responder responder) {
+        final LsubRequest request = (LsubRequest) message;
+        final String referenceName = request.getBaseReferenceName();
+        final String mailboxPattern = request.getMailboxPattern();
+
+        try {
+            if (mailboxPattern.length() == 0) {
+                respondWithHierarchyDelimiter(responder);
+            } else {
+                listSubscriptions(session, responder, referenceName, mailboxPattern);
+            }
+
+            okComplete(command, tag, responder);
+
+        } catch (SubscriptionException e) {
+            session.getLog().debug("Subscription failed", e);
+            final HumanReadableText exceptionKey = e.getKey();
+            final HumanReadableText displayTextKey;
+            if (exceptionKey == null) {
+                displayTextKey = HumanReadableText.GENERIC_LSUB_FAILURE;
+            } else {
+                displayTextKey = exceptionKey;
+            }
+            no(command, tag, responder, displayTextKey);
+        } catch (MailboxException e) {
+            session.getLog().debug("Subscription failed", e);
+            final HumanReadableText displayTextKey = HumanReadableText.GENERIC_LSUB_FAILURE;
+            no(command, tag, responder, displayTextKey);
+        }        
+    }
 }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
Sat Sep  4 18:57:37 2010
@@ -33,29 +33,23 @@ import org.apache.james.imap.mailbox.Sub
 import org.apache.james.imap.message.request.SubscribeRequest;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class SubscribeProcessor extends AbstractMailboxProcessor {
+public class SubscribeProcessor extends AbstractSubscriptionProcessor {
 
-    private final SubscriptionManager subscriptionManager;
-
-    public SubscribeProcessor(final ImapProcessor next,
-            final MailboxManager mailboxManager,
-            final SubscriptionManager subscriptionManager,
-            final StatusResponseFactory factory) {
-        super(next, mailboxManager, factory);
-        this.subscriptionManager = subscriptionManager;
+    public SubscribeProcessor(ImapProcessor next, MailboxManager mailboxManager, SubscriptionManager
subscriptionManager, StatusResponseFactory factory) {
+        super(next, mailboxManager, subscriptionManager, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {
         return (message instanceof SubscribeRequest);
     }
 
-    protected void doProcess(ImapRequest message, ImapSession session,
-            String tag, ImapCommand command, Responder responder) {
+    @Override
+    protected void doProcessRequest(ImapRequest message, ImapSession session, String tag,
ImapCommand command, Responder responder) {
         final SubscribeRequest request = (SubscribeRequest) message;
         final String mailboxName = request.getMailboxName();
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
         try {
-            subscriptionManager.subscribe(mailboxSession, mailboxName);
+            getSubscriptionManager().subscribe(mailboxSession, mailboxName);
 
             unsolicitedResponses(session, responder, false);
             okComplete(command, tag, responder);
@@ -72,6 +66,7 @@ public class SubscribeProcessor extends 
                 displayTextKey = exceptionKey;
             }
             no(command, tag, responder, displayTextKey);
-        }
+        }        
     }
+
 }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
Sat Sep  4 18:57:37 2010
@@ -33,30 +33,24 @@ import org.apache.james.imap.mailbox.Sub
 import org.apache.james.imap.message.request.UnsubscribeRequest;
 import org.apache.james.imap.processor.base.ImapSessionUtils;
 
-public class UnsubscribeProcessor extends AbstractMailboxProcessor {
+public class UnsubscribeProcessor extends AbstractSubscriptionProcessor {
 
-    private final SubscriptionManager subscriptionManager;
 
-    
-    public UnsubscribeProcessor(final ImapProcessor next,
-            final MailboxManager mailboxManager,
-            final SubscriptionManager subscriptionManager,
-            final StatusResponseFactory factory) {
-        super(next, mailboxManager, factory);
-        this.subscriptionManager = subscriptionManager;
+    public UnsubscribeProcessor(ImapProcessor next, MailboxManager mailboxManager, SubscriptionManager
subscriptionManager, StatusResponseFactory factory) {
+        super(next, mailboxManager, subscriptionManager, factory);
     }
 
     protected boolean isAcceptable(ImapMessage message) {
         return (message instanceof UnsubscribeRequest);
     }
 
-    protected void doProcess(ImapRequest message, ImapSession session,
-            String tag, ImapCommand command, Responder responder) {
+    @Override
+    protected void doProcessRequest(ImapRequest message, ImapSession session, String tag,
ImapCommand command, Responder responder) {
         final UnsubscribeRequest request = (UnsubscribeRequest) message;
         final String mailboxName = request.getMailboxName();
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
         try {
-            subscriptionManager.unsubscribe(mailboxSession, mailboxName);
+            getSubscriptionManager().unsubscribe(mailboxSession, mailboxName);
 
             unsolicitedResponses(session, responder, false);
             okComplete(command, tag, responder);
@@ -73,6 +67,7 @@ public class UnsubscribeProcessor extend
                 displayTextKey = exceptionKey;
             }
             no(command, tag, responder, displayTextKey);
-        }
+        }        
     }
+
 }

Modified: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
(original)
+++ james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
Sat Sep  4 18:57:37 2010
@@ -115,7 +115,9 @@ public class LSubProcessorTest {
         subscriptions.add(MAILBOX_A);
         subscriptions.add(MAILBOX_B);
         subscriptions.add(MAILBOX_C);
+
         mockery.checking(new Expectations() {{
+            allowing(session).getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
will(returnValue(mailboxSession));
             oneOf(responder).respond(with(
                     equal(new LSubResponse("", true))));
         }});
@@ -123,7 +125,7 @@ public class LSubProcessorTest {
         expectOk();
 
         LsubRequest request = new LsubRequest(command, "", "", TAG);
-        processor.doProcess(request, session, TAG, command, responderImpl);
+        processor.doProcessRequest(request, session, TAG, command, responderImpl);
 
     }
 
@@ -148,7 +150,7 @@ public class LSubProcessorTest {
 
         LsubRequest request = new LsubRequest(command, "", PARENT
                 + ImapConstants.HIERARCHY_DELIMITER + "%", TAG);
-        processor.doProcess(request, session, TAG, command, responderImpl);
+        processor.doProcessRequest(request, session, TAG, command, responderImpl);
 
     }
 
@@ -171,7 +173,7 @@ public class LSubProcessorTest {
 
         LsubRequest request = new LsubRequest(command, "", ROOT
                 + ImapConstants.HIERARCHY_DELIMITER + "%", TAG);
-        processor.doProcess(request, session, TAG, command, responderImpl);
+        processor.doProcessRequest(request, session, TAG, command, responderImpl);
 
     }
 
@@ -195,7 +197,7 @@ public class LSubProcessorTest {
 
         LsubRequest request = new LsubRequest(command, "", ROOT
                 + ImapConstants.HIERARCHY_DELIMITER + "%", TAG);
-        processor.doProcess(request, session, TAG, command, responderImpl);
+        processor.doProcessRequest(request, session, TAG, command, responderImpl);
 
     }
 
@@ -217,7 +219,7 @@ public class LSubProcessorTest {
         expectOk();
 
         LsubRequest request = new LsubRequest(command, "", "*", TAG);
-        processor.doProcess(request, session, TAG, command, responderImpl);
+        processor.doProcessRequest(request, session, TAG, command, responderImpl);
 
     }
 

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java?rev=992659&r1=992658&r2=992659&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java
Sat Sep  4 18:57:37 2010
@@ -111,4 +111,21 @@ public abstract class StoreSubscriptionM
             throw new SubscriptionException(e.getKey(), (Exception)e.getCause());
         }
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.SubscriptionManager#endProcessingRequest(org.apache.james.imap.mailbox.MailboxSession)
+     */
+    public void endProcessingRequest(MailboxSession session) {
+        mapperFactory.endRequest(session);
+    }
+
+    /**
+     * Do nothing, Sub classes should override this if needed
+     */
+    public void startProcessingRequest(MailboxSession session) {
+        // Do nothing        
+    }
+    
+    
 }



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