You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/10/31 10:16:24 UTC

svn commit: r469424 - in /incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util: ./ ConcurrentLinkedQueueAtomicSize.java ConcurrentLinkedQueueNoSize.java

Author: ritchiem
Date: Tue Oct 31 01:16:23 2006
New Revision: 469424

URL: http://svn.apache.org/viewvc?view=rev&rev=469424
Log:
QPID-56
Also resolves a race condition where an messages could be sent out of order.
Modification of the Java ConcurrentLinkedQueue to provide a constant time size() method


Added:
    incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/
    incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueAtomicSize.java   (with props)
    incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueNoSize.java   (with props)

Added: incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueAtomicSize.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueAtomicSize.java?view=auto&rev=469424
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueAtomicSize.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueAtomicSize.java Tue Oct 31 01:16:23 2006
@@ -0,0 +1,55 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class ConcurrentLinkedQueueAtomicSize<E> extends ConcurrentLinkedQueue<E>
+{
+    AtomicInteger _size = new AtomicInteger(0);
+
+    public int size()
+    {
+        return _size.get();
+    }
+
+    public boolean offer(E o)
+    {
+
+        if (super.offer(o))
+        {
+            _size.incrementAndGet();
+            return true;
+        }
+
+        return false;
+    }
+
+    public E poll()
+    {
+        E e = super.poll();
+
+        if (e != null)
+        {
+            _size.decrementAndGet();
+        }
+
+        return e;
+    }
+}

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

Added: incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueNoSize.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueNoSize.java?view=auto&rev=469424
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueNoSize.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/org/apache/qpid/util/ConcurrentLinkedQueueNoSize.java Tue Oct 31 01:16:23 2006
@@ -0,0 +1,35 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.concurrent.ConcurrentLinkedQueue;
+
+public class ConcurrentLinkedQueueNoSize<E> extends ConcurrentLinkedQueue<E>
+{
+    public int size()
+    {
+        if (isEmpty())
+        {
+            return 0;
+        }
+        else
+        {
+            return 1;
+        }
+    }        
+}

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