org.apache.cassandra.utils.concurrent

## Class OpOrder

- java.lang.Object
- - org.apache.cassandra.utils.concurrent.OpOrder

    public class OpOrder
    extends java.lang.Object

A class for providing synchronization between producers and consumers that do not communicate directly with each other, but where the consumers need to process their work in contiguous batches. In particular this is useful for both CommitLog and Memtable where the producers (writing threads) are modifying a structure that the consumer (flush executor) only batch syncs, but needs to know what 'position' the work is at for co-ordination with other processes,

The typical usage is something like:

         public final class ExampleShared
         {
            final OpOrder order = new OpOrder();
            volatile SharedState state;

            static class SharedState
            {
                volatile Barrier barrier;

                // ...
            }

            public void consume()
            {
                SharedState state = this.state;
                state.setReplacement(new State())
                state.doSomethingToPrepareForBarrier();

                state.barrier = order.newBarrier();
                // seal() MUST be called after newBarrier() else barrier.isAfter()
                // will always return true, and barrier.await() will fail
                state.barrier.issue();

                // wait for all producer work started prior to the barrier to complete
                state.barrier.await();

                // change the shared state to its replacement, as the current state will no longer be used by producers
                this.state = state.getReplacement();

                state.doSomethingWithExclusiveAccess();
            }

            public void produce()
            {
                try (Group opGroup = order.start())
                {
                    SharedState s = state;
                    while (s.barrier != null && !s.barrier.isAfter(opGroup))
                        s = s.getReplacement();
                    s.doProduceWork();
                }
            }
        }

### Nested Class Summary

Nested Classes
`class` `OpOrder.Barrier` This class represents a synchronisation point providing ordering guarantees on operations started against the enclosing OpOrder.
`static class` `OpOrder.Group` Represents a group of identically ordered operations, i.e.

### Constructor Summary

Constructors
Constructor and Description
`OpOrder()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `awaitNewBarrier()`
`OpOrder.Group` `getCurrent()`
`OpOrder.Barrier` `newBarrier()` Creates a new barrier.
`OpOrder.Group` `start()` Start an operation against this OpOrder.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### OpOrder

    public OpOrder()

### Method Detail

#### start

    public OpOrder.Group start()

Start an operation against this OpOrder. Once the operation is completed Ordered.close() MUST be called EXACTLY once for this operation.

Returns:
  the Ordered instance that manages this OpOrder

#### newBarrier

    public OpOrder.Barrier newBarrier()

Creates a new barrier. The barrier is only a placeholder until barrier.issue() is called on it, after which all new operations will start against a new Group that will not be accepted by barrier.isAfter(), and barrier.await() will return only once all operations started prior to the issue have completed.

Returns:

#### getCurrent

    public OpOrder.Group getCurrent()

#### awaitNewBarrier

    public void awaitNewBarrier()