Migrate common/util to use JDT annotations
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / concurrent / TrackingLinkedBlockingQueue.java
index 853a0aae0ebeb1d08f7145af5b30a55fac2b2328..966dae7a2aebb0fa2149cd5828087b0715f8b4f5 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.util.concurrent;
 
 import com.google.common.annotations.Beta;
-
 import java.util.Collection;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * A {@link LinkedBlockingQueue} that tracks the largest queue size for debugging.
@@ -23,41 +22,43 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
  * @param <E> the element t.ype
  */
 public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
-    @SuppressWarnings("rawtypes")
-    private static final AtomicIntegerFieldUpdater<TrackingLinkedBlockingQueue> LARGEST_QUEUE_SIZE_UPDATER = AtomicIntegerFieldUpdater.newUpdater(TrackingLinkedBlockingQueue.class, "largestQueueSize");
     private static final long serialVersionUID = 1L;
 
+    @SuppressWarnings("rawtypes")
+    private static final AtomicIntegerFieldUpdater<TrackingLinkedBlockingQueue> LARGEST_QUEUE_SIZE_UPDATER
+        = AtomicIntegerFieldUpdater.newUpdater(TrackingLinkedBlockingQueue.class, "largestQueueSize");
+
     /**
      * Holds largestQueueSize, this long field should be only accessed
-     * using {@value #LARGEST_QUEUE_SIZE_UPDATER}
+     * using {@link #LARGEST_QUEUE_SIZE_UPDATER}.
      */
     private volatile int largestQueueSize = 0;
 
     /**
-     * @see LinkedBlockingQueue#LinkedBlockingQueue
+     * See {@link LinkedBlockingQueue#LinkedBlockingQueue()}.
      */
     public TrackingLinkedBlockingQueue() {
-        super();
     }
 
     /**
-     * @see LinkedBlockingQueue#LinkedBlockingQueue(Collection)
+     * See {@link LinkedBlockingQueue#LinkedBlockingQueue(Collection)}.
      */
-    public TrackingLinkedBlockingQueue( final Collection<? extends E> c ) {
+    @SuppressWarnings("checkstyle:parameterName")
+    public TrackingLinkedBlockingQueue(final @NonNull Collection<? extends E> c) {
         super(c);
     }
 
     /**
-     * @see LinkedBlockingQueue#LinkedBlockingQueue(int)
+     * See {@link LinkedBlockingQueue#LinkedBlockingQueue(int)}.
      */
-    public TrackingLinkedBlockingQueue( final int capacity ) {
+    public TrackingLinkedBlockingQueue(final int capacity) {
         super(capacity);
     }
 
     /**
      * Returns the largest queue size.
      *
-     * FIXME: the this return will be changed to int in a future release.
+     * <p>FIXME: the this return will be changed to int in a future release.
      */
     @Beta
     public long getLargestQueueSize() {
@@ -65,8 +66,9 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
     }
 
     @Override
-    public boolean offer( final E e, final long timeout, final TimeUnit unit ) throws InterruptedException {
-        if( super.offer( e, timeout, unit ) ) {
+    @SuppressWarnings("checkstyle:parameterName")
+    public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException {
+        if (super.offer(e, timeout, unit)) {
             updateLargestQueueSize();
             return true;
         }
@@ -75,8 +77,9 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
     }
 
     @Override
-    public boolean offer( final E e ) {
-        if( super.offer( e ) ) {
+    @SuppressWarnings("checkstyle:parameterName")
+    public boolean offer(final E e) {
+        if (super.offer(e)) {
             updateLargestQueueSize();
             return true;
         }
@@ -85,22 +88,25 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
     }
 
     @Override
-    public void put( final E e ) throws InterruptedException {
-        super.put( e );
+    @SuppressWarnings("checkstyle:parameterName")
+    public void put(final E e) throws InterruptedException {
+        super.put(e);
         updateLargestQueueSize();
     }
 
     @Override
-    public boolean add( final E e ) {
-        boolean result = super.add( e );
+    @SuppressWarnings("checkstyle:parameterName")
+    public boolean add(final E e) {
+        boolean result = super.add(e);
         updateLargestQueueSize();
         return result;
     }
 
     @Override
-    public boolean addAll( final Collection<? extends E> c ) {
+    @SuppressWarnings("checkstyle:parameterName")
+    public boolean addAll(final Collection<? extends E> c) {
         try {
-            return super.addAll( c );
+            return super.addAll(c);
         } finally {
             updateLargestQueueSize();
         }
@@ -112,6 +118,6 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
         int largest;
         do {
             largest = largestQueueSize;
-        } while (size > largest && !LARGEST_QUEUE_SIZE_UPDATER.compareAndSet(this, largest, size));
+        } while (size > largest && !LARGEST_QUEUE_SIZE_UPDATER.weakCompareAndSet(this, largest, size));
     }
 }