com.kuka.common.concurrent
Class BarrierReference<V>

java.lang.Object
  extended by com.kuka.common.concurrent.BarrierReference<V>
Type Parameters:
V - the type of the reference

public class BarrierReference<V>
extends Object

An object reference, where threads can wait for changes.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Constructor Summary
BarrierReference()
          Creates a new instance with the starting value null.
BarrierReference(V value)
          Creates a new instance with the given starting value.
 
Method Summary
 V awaitGet()
          Waits for the reference to change, and returns the new value.
 V awaitGet(long timeout, TimeUnit unit)
          Waits for the reference to change within the given timeout, and returns the new value.
 V get()
          Returns the current reference value immediately.
 void set(V newValue)
          Sets the reference to a new value, waking up all other threads that wait for a change.
 V tryAwaitGet(V expected)
          Waits for the reference to change, if the value is currently == the given expected value.
 V tryAwaitGet(V expected, long timeout, TimeUnit unit)
          Waits for the reference to change within the given timeout, if the value is currently == the given expected value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BarrierReference

public BarrierReference()
Creates a new instance with the starting value null.


BarrierReference

public BarrierReference(V value)
Creates a new instance with the given starting value.

Parameters:
value - initial value
Method Detail

set

public final void set(V newValue)
Sets the reference to a new value, waking up all other threads that wait for a change.

Parameters:
newValue - the new reference value

get

public final V get()
Returns the current reference value immediately.

Returns:
the current value

awaitGet

public final V awaitGet()
                 throws InterruptedException
Waits for the reference to change, and returns the new value. It's guaranteed to return the very next value that will be set.

Returns:
the new value of the reference.
Throws:
InterruptedException - the waiting task was interrupted

awaitGet

public final V awaitGet(long timeout,
                        TimeUnit unit)
                 throws InterruptedException,
                        TimeoutException
Waits for the reference to change within the given timeout, and returns the new value. It's guaranteed to return the very next value that will be set.

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout parameter
Returns:
the new value of the reference.
Throws:
InterruptedException - the waiting task was interrupted
TimeoutException - the maximum time elapsed without change of the reference

tryAwaitGet

public final V tryAwaitGet(V expected)
                    throws InterruptedException
Waits for the reference to change, if the value is currently == the given expected value. Returns the new value after waiting, or the current value immediately if the expected value wasn't already set. The method is guaranteed to return the very next value that will be set, if a wait occurs.

This method serves to avoid a wait if the reference is not what it was expected to be.

Parameters:
expected - the expected value of the reference
Returns:
the new value of the reference, or the current value if != the expected value
Throws:
InterruptedException - the waiting task was interrupted

tryAwaitGet

public final V tryAwaitGet(V expected,
                           long timeout,
                           TimeUnit unit)
                    throws InterruptedException,
                           TimeoutException
Waits for the reference to change within the given timeout, if the value is currently == the given expected value. Returns the new value after waiting, or the current value immediately if the expected value wasn't already set. The method is guaranteed to return the very next value that will be set, if a wait occurs.

This method serves to avoid a wait if the reference is not what it was expected to be.

Parameters:
expected - the expected value of the reference
timeout - the maximum time to wait
unit - the time unit of the timeout parameter
Returns:
the new value of the reference, or the current value if != the expected value
Throws:
InterruptedException - the waiting task was interrupted
TimeoutException - the maximum time elapsed without change of the reference


Copyright © 2019. All rights reserved.