public class

BlockingCell

extends Object
java.lang.Object
   ↳ com.rabbitmq.utility.BlockingCell<T>
Known Direct Subclasses

Class Overview

Simple one-shot IPC mechanism. Essentially a one-place buffer that cannot be emptied once filled.

Summary

Public Constructors
BlockingCell()
Instantiate a new BlockingCell waiting for a value of the specified type.
Public Methods
synchronized T get(long timeout)
Wait for a value, and when one arrives, return it (without clearing it).
synchronized T get()
Wait for a value, and when one arrives, return it (without clearing it).
synchronized void set(T newValue)
Store a value in this BlockingCell, throwing AssertionError if the cell already has a value.
synchronized boolean setIfUnset(T newValue)
Store a value in this BlockingCell if it doesn't already have a value.
synchronized T uninterruptibleGet()
As get(), but catches and ignores InterruptedException, retrying until a value appears.
synchronized T uninterruptibleGet(int timeout)
As get(long timeout), but catches and ignores InterruptedException, retrying until a value appears or until specified timeout is reached.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public BlockingCell ()

Instantiate a new BlockingCell waiting for a value of the specified type.

Public Methods

public synchronized T get (long timeout)

Wait for a value, and when one arrives, return it (without clearing it). If there's already a value present, there's no need to wait - the existing value is returned. If timeout is reached and value hasn't arrived, TimeoutException is thrown.

Parameters
timeout timeout in milliseconds. -1 effectively means infinity
Returns
  • the waited-for value
Throws
InterruptedException if this thread is interrupted
TimeoutException

public synchronized T get ()

Wait for a value, and when one arrives, return it (without clearing it). If there's already a value present, there's no need to wait - the existing value is returned.

Returns
  • the waited-for value
Throws
InterruptedException if this thread is interrupted

public synchronized void set (T newValue)

Store a value in this BlockingCell, throwing AssertionError if the cell already has a value.

Parameters
newValue the new value to store

public synchronized boolean setIfUnset (T newValue)

Store a value in this BlockingCell if it doesn't already have a value.

Parameters
newValue the new value to store
Returns
  • true if this call to setIfUnset actually updated the BlockingCell; false if the cell already had a value.

public synchronized T uninterruptibleGet ()

As get(), but catches and ignores InterruptedException, retrying until a value appears.

Returns
  • the waited-for value

public synchronized T uninterruptibleGet (int timeout)

As get(long timeout), but catches and ignores InterruptedException, retrying until a value appears or until specified timeout is reached. If timeout is reached, TimeoutException is thrown. We also use System.nanoTime() to behave correctly when system clock jumps around.

Parameters
timeout timeout in milliseconds. -1 means 'infinity': never time out
Returns
  • the waited-for value