qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r683337 - in /incubator/qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ common/src/main/java/org/apache/qpid/util/ tools/src/main/java/org/apache/qpid/tools/
Date Wed, 06 Aug 2008 17:48:25 GMT
Author: rhs
Date: Wed Aug  6 10:48:25 2008
New Revision: 683337

URL: http://svn.apache.org/viewvc?rev=683337&view=rev
Log:
QPID-1221: added customizable UUID generation and switched the default strategy to use nameUUIDFromBytes
rather than randomUUID

Added:
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java
  (with props)
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java
  (with props)
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java
  (with props)
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java  
(with props)
Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
    incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java?rev=683337&r1=683336&r2=683337&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
Wed Aug  6 10:48:25 2008
@@ -48,6 +48,8 @@
 import org.apache.qpid.framing.ContentBody;
 import org.apache.qpid.framing.ContentHeaderBody;
 import org.apache.qpid.framing.ExchangeDeclareBody;
+import org.apache.qpid.util.UUIDGen;
+import org.apache.qpid.util.UUIDs;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -122,6 +124,8 @@
 
     private boolean _disableMessageId;
 
+    private UUIDGen _messageIdGenerator = UUIDs.newGenerator();
+
     private static final ContentBody[] NO_CONTENT_BODIES = new ContentBody[0];
 
     protected BasicMessageProducer(AMQConnection connection, AMQDestination destination,
boolean transacted, int channelId,
@@ -460,7 +464,7 @@
         }
         else
         {
-            messageId = UUID.randomUUID();
+            messageId = _messageIdGenerator.generate();
             StringBuilder b = new StringBuilder(39);
             b.append("ID:");
             b.append(messageId);

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java?rev=683337&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java
(added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java
Wed Aug  6 10:48:25 2008
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.qpid.util;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+
+/**
+ * NameUUIDGen
+ *
+ */
+
+public final class NameUUIDGen implements UUIDGen
+{
+
+    private static final int WIDTH = 8;
+
+    final private byte[] seed;
+    final private ByteBuffer seedBuf;
+    private long counter;
+
+    public NameUUIDGen()
+    {
+        String namespace = UUID.randomUUID().toString();
+        this.seed = new byte[namespace.length() + WIDTH];
+        for (int i = WIDTH; i < seed.length; i++)
+        {
+            seed[i] = (byte) namespace.charAt(i - WIDTH);
+        }
+        this.seedBuf = ByteBuffer.wrap(seed);
+        this.counter = 0;
+    }
+
+    public UUID generate()
+    {
+        seedBuf.putLong(0, counter++);
+        return UUID.nameUUIDFromBytes(seed);
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/NameUUIDGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java?rev=683337&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java
(added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java
Wed Aug  6 10:48:25 2008
@@ -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.qpid.util;
+
+import java.util.UUID;
+
+
+/**
+ * RandomUUIDGen
+ *
+ */
+
+public final class RandomUUIDGen implements UUIDGen
+{
+
+    public UUID generate()
+    {
+        return UUID.randomUUID();
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/RandomUUIDGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java?rev=683337&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java
(added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java
Wed Aug  6 10:48:25 2008
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.qpid.util;
+
+
+import java.util.UUID;
+
+/**
+ * UUIDGen
+ *
+ */
+
+public interface UUIDGen
+{
+
+    public UUID generate();
+
+}

Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java?rev=683337&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java Wed
Aug  6 10:48:25 2008
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.qpid.util;
+
+
+/**
+ * UUIDs
+ *
+ */
+
+public final class UUIDs
+{
+
+    public static final UUIDGen newGenerator()
+    {
+        return newGenerator(System.getProperty("qpid.uuid.generator",
+                                               NameUUIDGen.class.getName()));
+    }
+
+    public static UUIDGen newGenerator(String name)
+    {
+        try
+        {
+            Class cls = Class.forName(name);
+            return (UUIDGen) cls.newInstance();
+        }
+        catch (InstantiationException e)
+        {
+            throw new RuntimeException(e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new RuntimeException(e);
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/UUIDs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java?rev=683337&r1=683336&r2=683337&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java
(original)
+++ incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java
Wed Aug  6 10:48:25 2008
@@ -32,6 +32,8 @@
 import org.apache.qpid.client.AMQConnection;
 import org.apache.qpid.transport.*;
 import org.apache.qpid.transport.network.io.IoTransport;
+import org.apache.qpid.util.UUIDGen;
+import org.apache.qpid.util.UUIDs;
 
 import static org.apache.qpid.tools.QpidBench.Mode.*;
 
@@ -732,6 +734,8 @@
         ssn.messageFlow("echo-queue", MessageCreditUnit.MESSAGE, 0xFFFFFFFF);
         ssn.messageFlow("echo-queue", MessageCreditUnit.BYTE, 0xFFFFFFFF);
 
+        UUIDGen gen = UUIDs.newGenerator();
+
         long count = 0;
         long lastTime = 0;
         long start = System.currentTimeMillis();
@@ -774,7 +778,7 @@
 
             if (opts.message_id)
             {
-                mp.setMessageId(UUID.randomUUID());
+                mp.setMessageId(gen.generate());
             }
 
             if (opts.timestamp)



Mime
View raw message