Class AtomicLongPosition

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class AtomicLongPosition
    extends Position
    Position that is backed by an AtomicLong which is useful for tests.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int id  
      private boolean isClosed  
      private java.util.concurrent.atomic.AtomicLong value  
    • Constructor Summary

      Constructors 
      Constructor Description
      AtomicLongPosition()
      Default constructor.
      AtomicLongPosition​(int id)
      Create a position with a given id and zero as an initial value.
      AtomicLongPosition​(int id, long initialValue)
      Create a position with a given id and an initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      long get()
      Get the current position of a component without memory ordering semantics.
      long getVolatile()
      Get the current position of a component with volatile semantics.
      int id()
      Identifier for this position.
      boolean isClosed()
      Has this Position been closed?
      boolean proposeMax​(long proposedValue)
      Set the position to a new proposedValue if greater than the current value without memory ordering semantics.
      boolean proposeMaxOrdered​(long proposedValue)
      Set the position to the new proposedValue if greater than the current value with memory ordering semantics.
      void set​(long value)
      Sets the current position of the component without memory ordering semantics.
      void setOrdered​(long value)
      Sets the current position of the component with ordered memory semantics.
      void setVolatile​(long value)
      Sets the current position of the component with volatile memory semantics.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • isClosed

        private boolean isClosed
      • id

        private final int id
      • value

        private final java.util.concurrent.atomic.AtomicLong value
    • Constructor Detail

      • AtomicLongPosition

        public AtomicLongPosition()
        Default constructor.
      • AtomicLongPosition

        public AtomicLongPosition​(int id)
        Create a position with a given id and zero as an initial value.
        Parameters:
        id - to be assigned.
      • AtomicLongPosition

        public AtomicLongPosition​(int id,
                                  long initialValue)
        Create a position with a given id and an initial value.
        Parameters:
        id - to be assigned.
        initialValue - to be assigned.
    • Method Detail

      • isClosed

        public boolean isClosed()
        Has this Position been closed?
        Specified by:
        isClosed in class Position
        Returns:
        true if this position has already been closed.
      • id

        public int id()
        Identifier for this position.
        Specified by:
        id in class ReadablePosition
        Returns:
        the identifier for this position.
      • get

        public long get()
        Get the current position of a component without memory ordering semantics.
        Specified by:
        get in class Position
        Returns:
        the current position of a component
      • getVolatile

        public long getVolatile()
        Get the current position of a component with volatile semantics.
        Specified by:
        getVolatile in class ReadablePosition
        Returns:
        the current position of a component with volatile semantics.
      • set

        public void set​(long value)
        Sets the current position of the component without memory ordering semantics.
        Specified by:
        set in class Position
        Parameters:
        value - the current position of the component.
      • setOrdered

        public void setOrdered​(long value)
        Sets the current position of the component with ordered memory semantics.
        Specified by:
        setOrdered in class Position
        Parameters:
        value - the current position of the component.
      • setVolatile

        public void setVolatile​(long value)
        Sets the current position of the component with volatile memory semantics.
        Specified by:
        setVolatile in class Position
        Parameters:
        value - the current position of the component.
      • proposeMax

        public boolean proposeMax​(long proposedValue)
        Set the position to a new proposedValue if greater than the current value without memory ordering semantics.
        Specified by:
        proposeMax in class Position
        Parameters:
        proposedValue - for the new max.
        Returns:
        true if a new max as been set otherwise false.
      • proposeMaxOrdered

        public boolean proposeMaxOrdered​(long proposedValue)
        Set the position to the new proposedValue if greater than the current value with memory ordering semantics.
        Specified by:
        proposeMaxOrdered in class Position
        Parameters:
        proposedValue - for the new max.
        Returns:
        true if a new max as been set otherwise false.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class ReadablePosition
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object