X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2Fconcurrent%2FTrackingLinkedBlockingQueue.java;h=966dae7a2aebb0fa2149cd5828087b0715f8b4f5;hb=0df9e95c2849172793642a654ef1061811d40f30;hp=853a0aae0ebeb1d08f7145af5b30a55fac2b2328;hpb=37b7dd57b7c6a532c6751bfff35c922af1297471;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java index 853a0aae0e..966dae7a2a 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java @@ -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 the element t.ype */ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { - @SuppressWarnings("rawtypes") - private static final AtomicIntegerFieldUpdater LARGEST_QUEUE_SIZE_UPDATER = AtomicIntegerFieldUpdater.newUpdater(TrackingLinkedBlockingQueue.class, "largestQueueSize"); private static final long serialVersionUID = 1L; + @SuppressWarnings("rawtypes") + private static final AtomicIntegerFieldUpdater 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 c ) { + @SuppressWarnings("checkstyle:parameterName") + public TrackingLinkedBlockingQueue(final @NonNull Collection 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. + *

FIXME: the this return will be changed to int in a future release. */ @Beta public long getLargestQueueSize() { @@ -65,8 +66,9 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @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 extends LinkedBlockingQueue { } @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 extends LinkedBlockingQueue { } @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 c ) { + @SuppressWarnings("checkstyle:parameterName") + public boolean addAll(final Collection c) { try { - return super.addAll( c ); + return super.addAll(c); } finally { updateLargestQueueSize(); } @@ -112,6 +118,6 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { 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)); } }