james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1042197 - in /james/mailbox/trunk: jcr/src/main/java/org/apache/james/mailbox/jcr/ jcr/src/main/java/org/apache/james/mailbox/jcr/mail/ jcr/src/main/java/org/apache/james/mailbox/jcr/user/ parent/
Date Sat, 04 Dec 2010 15:03:27 GMT
Author: norman
Date: Sat Dec  4 15:03:27 2010
New Revision: 1042197

URL: http://svn.apache.org/viewvc?rev=1042197&view=rev
Log:
upgrade to jackrabbit 2.2-SNAPSHOT and remove the NodeLocker usage in JCRMessageMapper. I
also removed the nested folder structure to store mails (break done per day). This allows
us to store 8x faster then before

Modified:
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRMapper.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
    james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/user/JCRSubscriptionMapper.java
    james/mailbox/trunk/parent/pom.xml

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRMapper.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRMapper.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRMapper.java
Sat Dec  4 15:03:27 2010
@@ -38,20 +38,14 @@ public abstract class AbstractJCRMapper 
     private final Log logger;
     private final MailboxSessionJCRRepository repository;
     protected final MailboxSession mSession;
-    private final NodeLocker locker;
 
     
-    public AbstractJCRMapper(final MailboxSessionJCRRepository repository, MailboxSession
mSession, NodeLocker locker, Log logger) {
+    public AbstractJCRMapper(final MailboxSessionJCRRepository repository, MailboxSession
mSession, Log logger) {
         this.repository = repository;
         this.mSession = mSession;
         this.logger = logger;
-        this.locker = locker;
     }
 
-    public NodeLocker getNodeLocker() {
-        return locker;
-    }
-    
     /**
      * Return the logger
      * 

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/AbstractJCRScalingMapper.java
Sat Dec  4 15:03:27 2010
@@ -34,8 +34,8 @@ public abstract class AbstractJCRScaling
     private final int scaling;
     private final static char PAD ='_';
     
-    public AbstractJCRScalingMapper(MailboxSessionJCRRepository repository, MailboxSession
mSession, NodeLocker locker, int scaling, Log logger) {
-        super(repository, mSession, locker, logger);
+    public AbstractJCRScalingMapper(MailboxSessionJCRRepository repository, MailboxSession
mSession, int scaling, Log logger) {
+        super(repository, mSession, logger);
         this.scaling = scaling;
     }
 

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxSessionMapperFactory.java
Sat Dec  4 15:03:27 2010
@@ -44,20 +44,18 @@ public class JCRMailboxSessionMapperFact
     private final Log logger;
     private final NodeLocker locker;
     private final static int DEFAULT_SCALING = 2;
-    private int scaling;
-    private int messageScaling;
-    private UidProvider<String> provider;
+    private final int scaling;
+    private final UidProvider<String> provider;
 
     public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository repository, final
NodeLocker locker, final UidProvider<String> uidProvider) {
-        this(repository, locker, uidProvider, DEFAULT_SCALING, JCRMessageMapper.MESSAGE_SCALE_DAY);
+        this(repository, locker, uidProvider, DEFAULT_SCALING);
     }
 
-    public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository repository, final
NodeLocker locker, final UidProvider<String> provider, final int scaling, final int
messageScaling) {
+    public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository repository, final
NodeLocker locker, final UidProvider<String> provider, final int scaling) {
         this.repository = repository;
         this.logger = LogFactory.getLog(JCRMailboxSessionMapperFactory.class);
         this.locker = locker;
         this.scaling = scaling;
-        this.messageScaling = messageScaling;
         this.provider = provider;
     }
     
@@ -69,13 +67,13 @@ public class JCRMailboxSessionMapperFact
 
     @Override
     public MessageMapper<String> createMessageMapper(MailboxSession session) throws
MailboxException {
-        JCRMessageMapper messageMapper = new JCRMessageMapper(repository, session, locker,
provider, logger, messageScaling);
+        JCRMessageMapper messageMapper = new JCRMessageMapper(repository, session, provider,
logger);
         return messageMapper;
     }
 
     @Override
     public SubscriptionMapper createSubscriptionMapper(MailboxSession session) throws SubscriptionException
{
-        JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(repository, session, locker,
DEFAULT_SCALING, logger);
+        JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(repository, session, DEFAULT_SCALING,
logger);
         return mapper;
     }
     

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
Sat Dec  4 15:03:27 2010
@@ -54,8 +54,11 @@ import org.apache.james.mailbox.store.ma
  */
 public class JCRMailboxMapper extends AbstractJCRScalingMapper implements MailboxMapper<String>
{
 
-    public JCRMailboxMapper(final MailboxSessionJCRRepository repos, MailboxSession session,
final NodeLocker locker, final int scaling, final Log logger) {
-        super(repos, session, locker, scaling, logger);
+    private NodeLocker locker;
+
+	public JCRMailboxMapper(final MailboxSessionJCRRepository repos, MailboxSession session,
final NodeLocker locker, final int scaling, final Log logger) {
+        super(repos, session, scaling, logger);
+        this.locker = locker;
     }
 
     /*
@@ -165,7 +168,6 @@ public class JCRMailboxMapper extends Ab
                 } else {
                     mailboxNode = rootNode.getNode(MAILBOXES_PATH);
                 }
-                NodeLocker locker = getNodeLocker();
                 locker.execute(new NodeLockedExecution<Void>() {
 
                     public Void execute(Node node) throws RepositoryException {

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
Sat Dec  4 15:03:27 2010
@@ -20,8 +20,6 @@ package org.apache.james.mailbox.jcr.mai
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -34,20 +32,16 @@ import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
 import org.apache.commons.logging.Log;
-import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageRange;
-import org.apache.james.mailbox.SearchQuery;
 import org.apache.james.mailbox.MessageRange.Type;
+import org.apache.james.mailbox.SearchQuery;
 import org.apache.james.mailbox.SearchQuery.Criterion;
 import org.apache.james.mailbox.SearchQuery.NumericRange;
 import org.apache.james.mailbox.jcr.AbstractJCRMapper;
 import org.apache.james.mailbox.jcr.MailboxSessionJCRRepository;
-import org.apache.james.mailbox.jcr.NodeLocker;
-import org.apache.james.mailbox.jcr.NodeLocker.NodeLockedExecution;
 import org.apache.james.mailbox.jcr.mail.model.JCRMessage;
 import org.apache.james.mailbox.store.SearchQueryIterator;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -56,76 +50,24 @@ import org.apache.james.mailbox.store.ma
 import org.apache.james.mailbox.store.mail.model.MailboxMembership;
 
 /**
- * JCR implementation of a {@link MessageMapper}
+ * JCR implementation of a {@link MessageMapper}. The implementation store each message as

+ * a seperate child node under the mailbox
  *
  */
 public class JCRMessageMapper extends AbstractJCRMapper implements MessageMapper<String>
{
 
-    /**
-     * Store the messages directly in the mailbox:
-     * .../mailbox/
-     */
-    public final static int MESSAGE_SCALE_NONE = 0;
-    
-    /**
-     * Store the messages under a year directory in the mailbox:
-     * .../mailbox/2010/
-     */
-    public final static int MESSAGE_SCALE_YEAR = 1;
-    
-    /**
-     * Store the messages under a year/month directory in the mailbox:
-     * .../mailbox/2010/05/
-     */
-    public final static int MESSAGE_SCALE_MONTH = 2;
-    
-    /**
-     * Store the messages under a year/month/day directory in the mailbox:
-     * .../mailbox/2010/05/01/
-     */
-    public final static int MESSAGE_SCALE_DAY = 3;
-    
-    /**
-     * Store the messages under a year/month/day/hour directory in the mailbox:
-     * .../mailbox/2010/05/02/11
-     */
-    public final static int MESSAGE_SCALE_HOUR = 4;
-    
-    
-    /**
-     * Store the messages under a year/month/day/hour/min directory in the mailbox:
-     * .../mailbox/2010/05/02/11/59
-     */
-    public final static int MESSAGE_SCALE_MINUTE = 5;
-
-    private final int scaleType;
-
     private UidProvider<String> uidGenerator;
     
 
     /**
-     * 
-     * @see #JCRMessageMapper(MailboxSessionJCRRepository, MailboxSession, NodeLocker, Log,
int)
-     * 
-     * In this case {@link #MESSAGE_SCALE_DAY} is used
-     */
-    public JCRMessageMapper(final MailboxSessionJCRRepository repos, MailboxSession session,
NodeLocker locker, final UidProvider<String> uidGenerator, final Log logger) {
-        this(repos, session, locker, uidGenerator, logger, MESSAGE_SCALE_DAY);
-    }
-
-    /**
      * Construct a new {@link JCRMessageMapper} instance
      * 
      * @param repos {@link MailboxSessionJCRRepository} to use
      * @param session {@link MailboxSession} to which the mapper is bound
-     * @param locker {@link NodeLocker} for locking Nodes
-     * @param logger Lo
-     * @param scaleType the scale type to use when storing messages. See {@link #MESSAGE_SCALE_NONE},
{@link #MESSAGE_SCALE_YEAR}, {@link #MESSAGE_SCALE_MONTH}, {@link #MESSAGE_SCALE_DAY},
-     *                  {@link #MESSAGE_SCALE_HOUR}, {@link #MESSAGE_SCALE_MINUTE}  
-     */
-    public JCRMessageMapper(final MailboxSessionJCRRepository repos, MailboxSession session,
NodeLocker locker, final UidProvider<String> uidGenerator, final Log logger, int scaleType)
{
-        super(repos, session, locker, logger);
-        this.scaleType = scaleType;
+     * @param logger Log
+     */
+    public JCRMessageMapper(final MailboxSessionJCRRepository repos, MailboxSession session,
final UidProvider<String> uidGenerator, final Log logger) {
+        super(repos, session, logger);
         this.uidGenerator = uidGenerator;
     }
     
@@ -477,102 +419,23 @@ public class JCRMessageMapper extends Ab
             }
 
             if (messageNode == null) {
-                Date date = message.getInternalDate();
-                if (date == null) {
-                    date = new Date();
-                }
-
-                // extracte the date from the message to create node structure
-                // later
-                Calendar cal = Calendar.getInstance();
-                cal.setTime(date);
-                final String year = convertIntToString(cal.get(Calendar.YEAR));
-                final String month = convertIntToString(cal.get(Calendar.MONTH) + 1);
-                final String day = convertIntToString(cal.get(Calendar.DAY_OF_MONTH));
-                final String hour = convertIntToString(cal.get(Calendar.HOUR_OF_DAY));
-                final String min = convertIntToString(cal.get(Calendar.MINUTE));
-
-                Node node = null;
+               
                 Node mailboxNode = getSession().getNodeByIdentifier(mailbox.getMailboxId());
 
                 final long nextUid = uidGenerator.nextUid(mSession, mailbox);
 
                 
-                NodeLocker locker = getNodeLocker();
+                messageNode = mailboxNode.addNode(String.valueOf(nextUid), "nt:file");
+                messageNode.addMixin("jamesMailbox:message");
+                try {
+                    membership.merge(messageNode);
+                    messageNode.setProperty(JCRMessage.UID_PROPERTY, nextUid);
 
-                if (scaleType > MESSAGE_SCALE_NONE) {
-                    // we lock the whole mailbox with all its childs while
-                    // adding the folder structure for the date
-                    
-                    // TODO: Maybe we should just lock the last child folder to
-                    // improve performance
-                    node = locker.execute(new NodeLocker.NodeLockedExecution<Node>()
{
-
-                        public Node execute(Node node) throws RepositoryException {
-
-                            if (scaleType >= MESSAGE_SCALE_YEAR) {
-                                node = JcrUtils.getOrAddFolder(node, year);
-                                node.addMixin(JcrConstants.MIX_LOCKABLE);
-
-                                if (scaleType >= MESSAGE_SCALE_MONTH) {
-                                    node = JcrUtils.getOrAddFolder(node, month);
-                                    node.addMixin(JcrConstants.MIX_LOCKABLE);
-
-                                    if (scaleType >= MESSAGE_SCALE_DAY) {
-                                        node = JcrUtils.getOrAddFolder(node, day);
-                                        node.addMixin(JcrConstants.MIX_LOCKABLE);
-
-                                        if (scaleType >= MESSAGE_SCALE_HOUR) {
-                                            node = JcrUtils.getOrAddFolder(node, hour);
-                                            node.addMixin(JcrConstants.MIX_LOCKABLE);
-
-                                            if (scaleType >= MESSAGE_SCALE_MINUTE) {
-                                                node = JcrUtils.getOrAddFolder(node, min);
-                                                node.addMixin(JcrConstants.MIX_LOCKABLE);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-
-                            // save the folders for now
-                            getSession().save();
-                            return node;
-                        }
-
-                        public boolean isDeepLocked() {
-                            return true;
-                        }
-                    }, mailboxNode, Node.class);
-                } else {
-                    node = mailboxNode;
+                } catch (IOException e) {
+                    throw new RepositoryException("Unable to merge message in to tree", e);
                 }
-
-                // lock the day node and add the message
-                locker.execute(new NodeLockedExecution<Void>() {
-
-                    public Void execute(Node node) throws RepositoryException {
-                        Node messageNode = node.addNode(String.valueOf(nextUid), "nt:file");
-                        messageNode.addMixin("jamesMailbox:message");
-                        try {
-                            membership.merge(messageNode);
-                            messageNode.setProperty(JCRMessage.UID_PROPERTY, nextUid);
-
-                        } catch (IOException e) {
-                            throw new RepositoryException("Unable to merge message in to
tree", e);
-                        }
-                        // save the message
-                        getSession().save();
-
-                        return null;
-                    }
-
-                    public boolean isDeepLocked() {
-                        return true;
-                    }
-                }, node, Void.class);
                 return nextUid;
-
+                
             } else {
                 membership.merge(messageNode);
                 return membership.getUid();
@@ -581,26 +444,10 @@ public class JCRMessageMapper extends Ab
             throw new MailboxException("Unable to save message " + message + " in mailbox
" + mailbox, e);
         } catch (IOException e) {
             throw new MailboxException("Unable to save message " + message + " in mailbox
" + mailbox, e);
-        } catch (InterruptedException e) {
-            throw new MailboxException("Unable to save message " + message + " in mailbox
" + mailbox, e);
         }
 
     }
 
-    /**
-     * Convert the given int value to a String. If the int value is smaller then 9 it will
prefix the String with 0.
-     * 
-     * @param value
-     * @return stringValue
-     */
-    private String convertIntToString(int value) {
-        if (value <= 9) {
-            return "0" +String.valueOf(value);
-        } else {
-            return String.valueOf(value);
-        }
-    }
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.mailbox.store.mail.MessageMapper#searchMailbox(org.apache.james.mailbox.store.mail.model.Mailbox,
org.apache.james.mailbox.SearchQuery)

Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/user/JCRSubscriptionMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/user/JCRSubscriptionMapper.java?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/user/JCRSubscriptionMapper.java
(original)
+++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/user/JCRSubscriptionMapper.java
Sat Dec  4 15:03:27 2010
@@ -39,7 +39,6 @@ import org.apache.james.mailbox.MailboxS
 import org.apache.james.mailbox.SubscriptionException;
 import org.apache.james.mailbox.jcr.AbstractJCRScalingMapper;
 import org.apache.james.mailbox.jcr.MailboxSessionJCRRepository;
-import org.apache.james.mailbox.jcr.NodeLocker;
 import org.apache.james.mailbox.jcr.user.model.JCRSubscription;
 import org.apache.james.mailbox.store.user.SubscriptionMapper;
 import org.apache.james.mailbox.store.user.model.Subscription;
@@ -50,8 +49,8 @@ import org.apache.james.mailbox.store.us
  */
 public class JCRSubscriptionMapper extends AbstractJCRScalingMapper implements SubscriptionMapper
{
 
-    public JCRSubscriptionMapper(final MailboxSessionJCRRepository repos, MailboxSession
session, final NodeLocker locker, final int scaling, final Log log) {
-        super(repos,session, locker, scaling, log);
+    public JCRSubscriptionMapper(final MailboxSessionJCRRepository repos, MailboxSession
session, final int scaling, final Log log) {
+        super(repos,session, scaling, log);
     }
 
     /*

Modified: james/mailbox/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/parent/pom.xml?rev=1042197&r1=1042196&r2=1042197&view=diff
==============================================================================
--- james/mailbox/trunk/parent/pom.xml (original)
+++ james/mailbox/trunk/parent/pom.xml Sat Dec  4 15:03:27 2010
@@ -531,12 +531,12 @@
       <dependency>
         <groupId>org.apache.jackrabbit</groupId>
         <artifactId>jackrabbit-jcr-commons</artifactId>
-        <version>2.1.2</version>
+        <version>2.2-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.jackrabbit</groupId>
         <artifactId>jackrabbit-core</artifactId>
-        <version>2.1.2</version>
+        <version>2.2-SNAPSHOT</version>
         <scope>test</scope>
       </dependency>
       <dependency>



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