Class SynchronizedModifiableIdQueue<E extends IdBean>

java.lang.Object
java.util.AbstractCollection<E>
org.eclipse.scanning.event.queue.SynchronizedModifiableIdQueue<E>
Type Parameters:
E - the class of objects in the queue
All Implemented Interfaces:
AutoCloseable, Iterable<E>, Collection<E>, Queue<E>, IModifiableIdQueue<E>, IPersistentModifiableIdQueue<E>

public class SynchronizedModifiableIdQueue<E extends IdBean> extends AbstractCollection<E> implements IPersistentModifiableIdQueue<E>
A persistent thread-safe modifiable Queue. In addition to implementing Queue in a thread-safe way, this class also implements IModifiableIdQueue to add methods to reorder and replace items in the queue.

The beans in the queue must be IdBeans (or some subclass), and this class uses the bean's unique id (as returned by IdBean.getUniqueId() rather than object equality. Note: it is the responsibility of client code to ensure does not contain multiple beans with the same unique id. If this requirement is not upheld the behaviour of this class is undefined.

It is imperative that the user manually synchronize on the returned queue when iterating over it:

  Queue queue = new SynchronizedModifiableIdQueue();
     ...
  synchronized (queue) {
      Iterator i = queue.iterator(); // Must be in synchronized block
      while (i.hasNext())
         foo(i.next());
  }
  
Failure to follow this advice may result in non-deterministic behavior. This warning also applies to any other behavior that the client wishes to be performed in an atomic manner.