Author: norman
Date: Fri Nov 12 18:33:00 2010
New Revision: 1034502
URL: http://svn.apache.org/viewvc?rev=1034502&view=rev
Log:
Generate an Id which can be use in distributed enviroments (JAMES-1127)
Modified:
james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
Modified:
james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java?rev=1034502&r1=1034501&r2=1034502&view=diff
==============================================================================
---
james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
(original)
+++
james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
Fri Nov 12 18:33:00 2010
@@ -23,6 +23,7 @@ package org.apache.james;
import java.net.UnknownHostException;
import java.util.Locale;
+import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -53,13 +54,6 @@ public class JamesMailServer
* The top level configuration object for this server.
*/
private HierarchicalConfiguration conf = null;
-
- /**
- * The number of mails generated. Access needs to be synchronized for
- * thread safety and to ensure that all threads see the latest value.
- */
- private static int count = 0;
- private static final Object countLock = new Object();
private DomainList domains;
@@ -164,43 +158,17 @@ public class JamesMailServer
/**
- * <p>Note that this method ensures that James cannot be run in a
distributed
- * fashion.</p>
- * <p>Two instances may return the same ID.
- * There are various ways that this could be fixed.
- * The most obvious would be to add a unique prefix.
- * The best approach would be for each instance to be configured
- * with a name which would then be combined with the network
- * address (for example, [email protected]) to create a
- * unique James instance identifier.
- * </p><p>
- * Alternatively, using a data store backed identifier (for example, from
a sequence
- * when DB backed) should be enough to gaurantee uniqueness. This would
imply
- * that the Mail interface or the spool store should be responsible for
creating
- * new Mail implementations with ID preassigned.
- * </p><p>
- * It would be useful for each
- * James cluster to have a unique name. Perhaps a random number could be
generated by
- * the spool store upon first initialisation.
- * </p><p>
- * This ID is most likely
- * to be used as message ID so this is probably useful in any case.
- * </p>
+ * The Id generated by this method use a combination of {...@link
System#currentTimeMillis()} and {...@link UUID#randomUUID()}
+ * So it should be safe to have an unique ID even when used in distributed
fashion.
*
* @see org.apache.james.services.MailServer#getId()
*/
public String getId() {
-
- final long localCount;
- synchronized (countLock) {
- localCount = count++;
- }
- StringBuffer idBuffer =
- new StringBuffer(64)
+ StringBuilder idBuffer = new StringBuilder()
.append("Mail")
.append(System.currentTimeMillis())
.append("-")
- .append(localCount);
+ .append(UUID.randomUUID());
return idBuffer.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]