james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1179215 - in /james/mailbox/trunk: api/src/main/java/org/apache/james/mailbox/ store/src/main/java/org/apache/james/mailbox/store/
Date Wed, 05 Oct 2011 13:28:07 GMT
Author: norman
Date: Wed Oct  5 13:28:07 2011
New Revision: 1179215

URL: http://svn.apache.org/viewvc?rev=1179215&view=rev
Log:
Add new MailboxSessionIdGenerator interface and an implementation which use Random under the
hood. This allows to have a distributed id generator if needed. This also fixes the problem
with generated MailboxSession ids that returned 0L before. See MAILBOX-149

Added:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java
  (with props)
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java
  (with props)
Modified:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java

Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSession.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSession.java?rev=1179215&r1=1179214&r2=1179215&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSession.java (original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSession.java Wed
Oct  5 13:28:07 2011
@@ -32,6 +32,11 @@ import org.slf4j.Logger;
 public interface MailboxSession {
 
 
+    /**
+     * Id which will be used for a System session
+     */
+    public final static long SYSTEM_SESSION_ID = 0L;
+
     public static enum SessionType {
         /**
          * Session was created via the System

Added: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java?rev=1179215&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java
(added)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java
Wed Oct  5 13:28:07 2011
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.mailbox;
+
+
+/**
+ * Generator for id's which should used for new {@link MailboxSession} instances
+ * 
+ *
+ */
+public interface MailboxSessionIdGenerator {
+
+    /**
+     * Return the next id to use for a {@link MailboxSession}. The id must be unique
+     * while the server is running and can be any long except {@link MailboxSession#SYSTEM_SESSION_ID}.
+     * 
+     * The returned ids can be in any specific order.
+     * 
+     * @return id
+     */
+    long nextId();
+}

Propchange: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxSessionIdGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java?rev=1179215&view=auto
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java
(added)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java
Wed Oct  5 13:28:07 2011
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.mailbox.store;
+
+import java.util.Random;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSessionIdGenerator;
+
+
+/**
+ * {@link MailboxSessionIdGenerator} which use a {@link Random} to generate the next Id to
use
+ * 
+ *
+ */
+public class RandomMailboxSessionIdGenerator implements MailboxSessionIdGenerator {
+    private final static Random RANDOM = new Random();
+
+    @Override
+    public long nextId() {
+        long id;
+        while ((id = RANDOM.nextLong()) == MailboxSession.SYSTEM_SESSION_ID) {
+            // loop till the id is not 0L
+            //
+            // See also MAILBOX-149
+        }
+        return id;
+    }
+
+}

Propchange: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/RandomMailboxSessionIdGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1179215&r1=1179214&r2=1179215&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
Wed Oct  5 13:28:07 2011
@@ -38,6 +38,7 @@ import org.apache.james.mailbox.MailboxP
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxQuery;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSessionIdGenerator;
 import org.apache.james.mailbox.MessageRange;
 import org.apache.james.mailbox.RequestAware;
 import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
@@ -82,6 +83,8 @@ public class StoreMailboxManager<Id> imp
 
     private MessageSearchIndex<Id> index;
 
+    private MailboxSessionIdGenerator idGenerator;
+
     
     public StoreMailboxManager(MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory,
final Authenticator authenticator, final MailboxPathLocker locker) {
         this.authenticator = authenticator;
@@ -93,6 +96,10 @@ public class StoreMailboxManager<Id> imp
         this(mailboxSessionMapperFactory, authenticator, new JVMMailboxPathLocker());
     }
    
+    public void setMailboxSessionIdGenerator(MailboxSessionIdGenerator idGenerator) {
+        this.idGenerator = idGenerator;
+    }
+    
     public void setCopyBatchSize(int copyBatchSize) {
         this.copyBatchSize = copyBatchSize;
     }
@@ -113,6 +120,10 @@ public class StoreMailboxManager<Id> imp
         if (index instanceof ListeningMessageSearchIndex) {
             addGlobalListener((ListeningMessageSearchIndex) index, null);
         }
+        
+        if (idGenerator == null) {
+            idGenerator = new RandomMailboxSessionIdGenerator();
+        }
     }
     
     /**
@@ -216,7 +227,7 @@ public class StoreMailboxManager<Id> imp
      * @return id
      */
     protected long randomId() {
-        return RANDOM.nextLong();
+        return idGenerator.nextId();
     }
     
     /*



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