james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r960937 - in /james/imap/trunk: store/src/main/java/org/apache/james/imap/store/ torque/src/main/java/org/apache/james/mailboxmanager/torque/
Date Tue, 06 Jul 2010 16:41:23 GMT
Author: norman
Date: Tue Jul  6 16:41:23 2010
New Revision: 960937

URL: http://svn.apache.org/viewvc?rev=960937&view=rev
Log:
Introduce a new abstract class DelegatingMailboxManager to allow the share of more code. This
will be useful later for cassandra mailbox implementation ;)

Added:
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingMailboxManager.java
Modified:
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingMailboxManager.java?rev=960937&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingMailboxManager.java
(added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingMailboxManager.java
Tue Jul  6 16:41:23 2010
@@ -0,0 +1,181 @@
+/****************************************************************
+ * 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.store;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.api.AbstractLogEnabled;
+import org.apache.james.imap.mailbox.BadCredentialsException;
+import org.apache.james.imap.mailbox.MailboxConstants;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.SubscriptionException;
+
+/**
+ * Abstract {@link MailboxManager} which delegates various stuff to the {@link Authenticator}
and {@link Subscriber}
+ *
+ */
+public abstract class DelegatingMailboxManager extends AbstractLogEnabled implements MailboxManager{
+
+    private final Authenticator authenticator;
+    private final Subscriber subscriper;
+    private final static Random RANDOM = new Random();
+
+    public DelegatingMailboxManager(final Authenticator authenticator, final Subscriber subscriper)
{
+        this.subscriper = subscriper;
+        this.authenticator = authenticator;
+    }
+
+    /**
+     * Generate an return the next uid validity 
+     * 
+     * @return uidValidity
+     */
+    protected int randomUidValidity() {
+        return Math.abs(RANDOM.nextInt());
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#createSystemSession(java.lang.String,
org.apache.commons.logging.Log)
+     */
+    public MailboxSession createSystemSession(String userName, Log log) {
+        return createSession(userName, null, log);
+    }
+
+    /**
+     * Create Session 
+     * 
+     * @param userName
+     * @param log
+     * @return session
+     */
+    private SimpleMailboxSession createSession(String userName, String password, Log log)
{
+        return new SimpleMailboxSession(randomId(), userName, password, log, new ArrayList<Locale>());
+    }
+
+    /**
+     * Generate and return the next id to use
+     * 
+     * @return id
+     */
+    protected long randomId() {
+        return RANDOM.nextLong();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#getDelimiter()
+     */
+    public final char getDelimiter() {
+        return MailboxConstants.DEFAULT_DELIMITER;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#resolve(java.lang.String, java.lang.String)
+     */
+    public String resolve(final String userName, String mailboxPath) {
+        if (mailboxPath.length() > 0 && mailboxPath.charAt(0) != MailboxConstants.DEFAULT_DELIMITER)
{
+            mailboxPath = MailboxConstants.DEFAULT_DELIMITER + mailboxPath;
+        }
+        final String result = MailboxConstants.USER_NAMESPACE + MailboxConstants.DEFAULT_DELIMITER
+ userName
+        + mailboxPath;
+        return result;
+    }
+
+    /**
+     * Log in the user with the given userid and password
+     * 
+     * @param userid the username
+     * @param passwd the password
+     * @return success true if login success false otherwise
+     */
+    public boolean login(String userid, String passwd) {
+        return authenticator.isAuthentic(userid, passwd);
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#login(java.lang.String, java.lang.String,
org.apache.commons.logging.Log)
+     */
+    public MailboxSession login(String userid, String passwd, Log log) throws BadCredentialsException,
MailboxException {
+        if (login(userid, passwd)) {
+            return createSession(userid, passwd, log);
+        } else {
+            throw new BadCredentialsException();
+        }
+    }
+    
+    /**
+     * Default do nothing. Should be overridden by subclass if needed
+     */
+    public void logout(MailboxSession session, boolean force) throws MailboxException {
+        // Do nothing by default
+    }
+  
+
+    /**
+     * Start processing of Request for session. Default is to do nothing.
+     * Implementations should override this if they need to do anything special
+     */
+    public void startProcessingRequest(MailboxSession session) {
+        // Default do nothing
+    }
+
+    /**
+     * End processing of a Request for the given session. Default is to do nothing
+     */
+    public void endProcessingRequest(MailboxSession session) {
+        // Default do nothing
+        
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#subscribe(org.apache.james.imap.mailbox.MailboxSession,
java.lang.String)
+     */
+    public void subscribe(MailboxSession session, String mailbox) throws SubscriptionException
{
+        subscriper.subscribe(session, mailbox);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#subscriptions(org.apache.james.imap.mailbox.MailboxSession)
+     */
+    public Collection<String> subscriptions(MailboxSession session) throws SubscriptionException
{
+        return subscriper.subscriptions(session);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxManager#unsubscribe(org.apache.james.imap.mailbox.MailboxSession,
java.lang.String)
+     */
+    public void unsubscribe(MailboxSession session, String mailbox) throws SubscriptionException
{
+        subscriper.unsubscribe(session, mailbox);
+    }
+
+}

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=960937&r1=960936&r2=960937&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
Tue Jul  6 16:41:23 2010
@@ -20,15 +20,10 @@
 package org.apache.james.imap.store;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Locale;
-import java.util.Random;
 
 import org.apache.commons.logging.Log;
-import org.apache.james.imap.api.AbstractLogEnabled;
-import org.apache.james.imap.mailbox.BadCredentialsException;
 import org.apache.james.imap.mailbox.MailboxConstants;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxExistsException;
@@ -40,7 +35,6 @@ import org.apache.james.imap.mailbox.Mai
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.mailbox.MailboxMetaData.Selectability;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.mailbox.util.SimpleMailboxMetaData;
@@ -57,25 +51,20 @@ import org.apache.james.imap.store.trans
  *
  * @param <Id>
  */
-public abstract class StoreMailboxManager<Id> extends AbstractLogEnabled implements
MailboxManager {
+public abstract class StoreMailboxManager<Id> extends DelegatingMailboxManager {
     
     public static final char SQL_WILDCARD_CHAR = '%';
 
     private final Object mutex = new Object();
     
-    private final static Random random = new Random();
-
     private final MailboxEventDispatcher dispatcher = new MailboxEventDispatcher();
-    private final DelegatingMailboxListener delegatingListener = new DelegatingMailboxListener();
-    private final Authenticator authenticator;    
-    private final Subscriber subscriber;    
+    private final DelegatingMailboxListener delegatingListener = new DelegatingMailboxListener();
  
     protected final MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory;
     private UidConsumer<Id> consumer;
     
     
     public StoreMailboxManager(MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory,
final Authenticator authenticator, final Subscriber subscriber, final UidConsumer<Id>
consumer) {
-        this.authenticator = authenticator;
-        this.subscriber = subscriber;
+        super(authenticator, subscriber);
         this.consumer = consumer;
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
     }
@@ -248,15 +237,7 @@ public abstract class StoreMailboxManage
         }
     }
 
-    /**
-     * Generate an return the next uid validity 
-     * 
-     * @return uidValidity
-     */
-    protected int randomUidValidity() {
-        return Math.abs(random.nextInt());
-    }
-    
+ 
     /**
      * Changes the name of the mailbox instance in the cache.
      * @param from not null
@@ -342,130 +323,10 @@ public abstract class StoreMailboxManage
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#createSystemSession(java.lang.String,
org.apache.commons.logging.Log)
-     */
-    public MailboxSession createSystemSession(String userName, Log log) {
-        return createSession(userName, null, log);
-    }
-
-    /**
-     * Create Session 
-     * 
-     * @param userName
-     * @param log
-     * @return session
-     */
-    private SimpleMailboxSession createSession(String userName, String password, Log log)
{
-        return new SimpleMailboxSession(randomId(), userName, password, log, new ArrayList<Locale>());
-    }
-
-    /**
-     * Generate and return the next id to use
-     * 
-     * @return id
-     */
-    protected long randomId() {
-        return random.nextLong();
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#resolve(java.lang.String, java.lang.String)
-     */
-    public String resolve(final String userName, String mailboxPath) {
-        if (mailboxPath.length() > 0 && mailboxPath.charAt(0) != MailboxConstants.DEFAULT_DELIMITER)
{
-            mailboxPath = MailboxConstants.DEFAULT_DELIMITER + mailboxPath;
-        }
-        final String result = MailboxConstants.USER_NAMESPACE + MailboxConstants.DEFAULT_DELIMITER
+ userName
-        + mailboxPath;
-        return result;
-    }
-
-    /**
-     * Log in the user with the given userid and password
-     * 
-     * @param userid the username
-     * @param passwd the password
-     * @return success true if login success false otherwise
-     */
-    public boolean login(String userid, String passwd) {
-        return authenticator.isAuthentic(userid, passwd);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#subscribe(org.apache.james.imap.mailbox.MailboxSession,
java.lang.String)
-     */
-    public void subscribe(MailboxSession session, String mailbox)
-    throws SubscriptionException {
-        subscriber.subscribe(session, mailbox);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#subscriptions(org.apache.james.imap.mailbox.MailboxSession)
-     */
-    public Collection<String> subscriptions(MailboxSession session) throws SubscriptionException
{
-        return subscriber.subscriptions(session);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#unsubscribe(org.apache.james.imap.mailbox.MailboxSession,
java.lang.String)
-     */
-    public void unsubscribe(MailboxSession session, String mailbox)
-    throws SubscriptionException {
-        subscriber.unsubscribe(session, mailbox);
-    }
-
-    /*
-     * (non-Javadoc)
      * @see org.apache.james.imap.mailbox.MailboxManager#addListener(java.lang.String, org.apache.james.imap.mailbox.MailboxListener,
org.apache.james.imap.mailbox.MailboxSession)
      */
     public void addListener(String mailboxName, MailboxListener listener, MailboxSession
session) throws MailboxException {
         delegatingListener.addListener(mailboxName, listener);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#login(java.lang.String, java.lang.String,
org.apache.commons.logging.Log)
-     */
-    public MailboxSession login(String userid, String passwd, Log log) throws BadCredentialsException,
MailboxException {
-        if (login(userid, passwd)) {
-            return createSession(userid, passwd, log);
-        } else {
-            throw new BadCredentialsException();
-        }
-    }
-    
-    /**
-     * Default do nothing. Should be overriden by subclass if needed
-     */
-    public void logout(MailboxSession session, boolean force) throws MailboxException {
-        // Do nothing by default
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#getDelimiter()
-     */
-    public final char getDelimiter() {
-        return MailboxConstants.DEFAULT_DELIMITER;
-    }
-
-    /**
-     * End processing of Request for session
-     */
-    public void endProcessingRequest(MailboxSession session) {
-        mailboxSessionMapperFactory.endRequest(session);
-    }
-
-    /**
-     * Start processing of Request for session. Default is to do nothing.
-     * Implementations should override this if they need to do anything special
-     */
-    public void startProcessingRequest(MailboxSession session) {
-        // Default do nothing
-    }
-
 }

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=960937&r1=960936&r2=960937&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
Tue Jul  6 16:41:23 2010
@@ -20,38 +20,29 @@
 package org.apache.james.mailboxmanager.torque;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
-import java.util.Random;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.mailbox.BadCredentialsException;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxConstants;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxListener;
-import org.apache.james.imap.mailbox.MailboxManager;
 import org.apache.james.imap.mailbox.MailboxMetaData;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxQuery;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.mailbox.MailboxMetaData.Selectability;
 import org.apache.james.imap.mailbox.util.SimpleMailboxMetaData;
 import org.apache.james.imap.store.Authenticator;
-import org.apache.james.imap.store.SimpleMailboxSession;
+import org.apache.james.imap.store.DelegatingMailboxManager;
 import org.apache.james.imap.store.Subscriber;
 import org.apache.james.mailboxmanager.torque.om.MailboxRow;
 import org.apache.james.mailboxmanager.torque.om.MailboxRowPeer;
@@ -59,27 +50,18 @@ import org.apache.torque.TorqueException
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
 
-public class TorqueMailboxManager implements MailboxManager {
+public class TorqueMailboxManager extends DelegatingMailboxManager {
     
     private static final char SQL_WILDCARD_CHAR = '%';
 
-    private final static Random random = new Random();
-
-    protected Log log = LogFactory.getLog(TorqueMailboxManager.class);
-
     private final ReentrantReadWriteLock lock;
 
     private final Map<String, TorqueMailbox> mailboxes;
-
-    private final Authenticator authenticator;
-
-    private final Subscriber subscriper;
     
     public TorqueMailboxManager(final Authenticator authenticator, final Subscriber subscriper)
{
+        super(authenticator, subscriper);
         this.lock = new ReentrantReadWriteLock();
         mailboxes = new HashMap<String, TorqueMailbox>();
-        this.authenticator = authenticator;
-        this.subscriper = subscriper;
     }
 
     public Mailbox getMailbox(String mailboxName, MailboxSession session)
@@ -157,7 +139,7 @@ public class TorqueMailboxManager implem
         MailboxRow mr = new MailboxRow();
         mr.setName(namespaceName);
         mr.setLastUid(0);
-        mr.setUidValidity(Math.abs(random.nextInt()));
+        mr.setUidValidity(randomUidValidity());
         try {
             mr.save();
         } catch (TorqueException e) {
@@ -344,85 +326,9 @@ public class TorqueMailboxManager implem
         }
     }
 
-    protected Log getLog() {
-        if (log == null) {
-            log = new SimpleLog("TorqueMailboxManager");
-        }
-        return log;
-    }
-
-    public MailboxSession createSystemSession(String userName, Log log) {
-        return createSession(userName, null, log);
-    }
-
-    private MailboxSession createSession(String userName, String password, Log log) {
-        return new SimpleMailboxSession(random.nextLong(), userName, password, log, new ArrayList<Locale>());
-    }
-
-    public String resolve(final String userName, String mailboxPath) {
-        if (mailboxPath.charAt(0) != MailboxConstants.DEFAULT_DELIMITER) {
-            mailboxPath = MailboxConstants.DEFAULT_DELIMITER + mailboxPath;
-        }
-        final String result = MailboxConstants.USER_NAMESPACE + MailboxConstants.DEFAULT_DELIMITER
+ userName
-                + mailboxPath;
-        return result;
-    }
-
-    public boolean login(String userid, String passwd) {
-        return authenticator.isAuthentic(userid, passwd);
-    }
-
-    public void subscribe(MailboxSession session, String mailbox)
-            throws SubscriptionException {
-        subscriper.subscribe(session, mailbox);
-    }
-
-    public Collection<String> subscriptions(MailboxSession session) throws SubscriptionException
{
-        return subscriper.subscriptions(session);
-    }
-
-    public void unsubscribe(MailboxSession session, String mailbox)
-            throws SubscriptionException {
-        subscriper.unsubscribe(session, mailbox);
-    }
-
     public void addListener(String mailboxName, MailboxListener listener, MailboxSession
session) throws MailboxException {
         final TorqueMailbox mailbox = doGetMailbox(mailboxName);
         mailbox.addListener(listener);
     }
 
-    public MailboxSession login(String userid, String passwd, Log log) throws BadCredentialsException,
MailboxException {
-        if (login(userid, passwd)) {
-            return createSession(userid, passwd, log);
-        } else {
-            throw new BadCredentialsException();
-        }
-    }
-
-    public void logout(MailboxSession session, boolean force) throws MailboxException {
-        // fine
-    }
-
-    /**
-     * Do nothing
-     */
-    public void endProcessingRequest(MailboxSession session) {
-        // Do nothing 
-    }
-
-    /**
-     * Do nothing
-     */
-    public void startProcessingRequest(MailboxSession session) {
-        // Do nothing        
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#getDelimiter()
-     */
-    public final char getDelimiter() {
-        return MailboxConstants.DEFAULT_DELIMITER;
-    }
-
 }



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