com.hazelcast.crdt.pncounter

## Class PNCounterImpl

- java.lang.Object
- - com.hazelcast.crdt.pncounter.PNCounterImpl

- All Implemented Interfaces:
    CRDT<PNCounterImpl>, DataSerializable, IdentifiedDataSerializable

      public class PNCounterImpl
      extends Object
      implements CRDT<PNCounterImpl>, IdentifiedDataSerializable

  PN (Positive-Negative) CRDT counter where each replica is identified by a String.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PNCounterImpl()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `CRDTTimestampedLong` | `addAndGet(long delta, com.hazelcast.cluster.impl.VectorClock observedTimestamps)` Adds the given value to the current value.
    `CRDTTimestampedLong` | `get(com.hazelcast.cluster.impl.VectorClock observedTimestamps)` Returns the current value of the counter.
    `CRDTTimestampedLong` | `getAndAdd(long delta, com.hazelcast.cluster.impl.VectorClock observedTimestamps)` Adds the given value to the current value.
    `CRDTTimestampedLong` | `getAndSubtract(long delta, com.hazelcast.cluster.impl.VectorClock observedTimestamps)` Subtracts the given value from the current value.
    `com.hazelcast.cluster.impl.VectorClock` | `getCurrentVectorClock()` Returns the current vector clock which reflects the current CRDT state.
    `int` | `getFactoryId()` Returns DataSerializableFactory factory ID for this class.
    `int` | `getId()` Returns type identifier for this class.
    `void` | `markMigrated()` Unconditionally marks this CRDT as migrated.
    `boolean` | `markMigrated(com.hazelcast.cluster.impl.VectorClock vectorClock)` Marks this CRDT as migrated.
    `void` | `merge(PNCounterImpl other)` Merges the state of a different replica into this CRDT.
    `void` | `readData(ObjectDataInput in)` Reads fields from the input stream
    `CRDTTimestampedLong` | `subtractAndGet(long delta, com.hazelcast.cluster.impl.VectorClock observedTimestamps)` Subtracts the given value from the current value.
    `void` | `writeData(ObjectDataOutput out)` Writes object fields to output stream

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

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

- - ### Constructor Detail

    - #### PNCounterImpl

          public PNCounterImpl()

  - ### Method Detail

    - #### get

          public CRDTTimestampedLong get(com.hazelcast.cluster.impl.VectorClock observedTimestamps)

      Returns the current value of the counter.

      The method can throw a `ConsistencyLostException` when the state of this CRDT is not causally related to the observed timestamps. This means that it cannot provide the session guarantees of RYW (read your writes) and monotonic read.

      Parameters:
        `observedTimestamps` - the vector clock last observed by the client of this counter
      Returns:
        the current counter value with the current counter vector clock
      Throws:
        `ConsistencyLostException` - if this replica cannot provide the session guarantees

    - #### getAndAdd

          public CRDTTimestampedLong getAndAdd(long delta,
                                               com.hazelcast.cluster.impl.VectorClock observedTimestamps)

      Adds the given value to the current value.

      The method can throw a `ConsistencyLostException` when the state of this CRDT is not causally related to the observed timestamps. This means that it cannot provide the session guarantees of RYW (read your writes) and monotonic read.

      Parameters:
        `delta` - the value to add
        `observedTimestamps` - the vector clock last observed by the client of this counter
      Returns:
        the current counter value with the current counter vector clock
      Throws:
        `ConsistencyLostException` - if this replica cannot provide the session guarantees

    - #### addAndGet

          public CRDTTimestampedLong addAndGet(long delta,
                                               com.hazelcast.cluster.impl.VectorClock observedTimestamps)

      Adds the given value to the current value.

      The method can throw a `ConsistencyLostException` when the state of this CRDT is not causally related to the observed timestamps. This means that it cannot provide the session guarantees of RYW (read your writes) and monotonic read.

      Parameters:
        `delta` - the value to add
        `observedTimestamps` - the vector clock last observed by the client of this counter
      Returns:
        the current counter value with the current counter vector clock
      Throws:
        `ConsistencyLostException` - if this replica cannot provide the session guarantees

    - #### getAndSubtract

          public CRDTTimestampedLong getAndSubtract(long delta,
                                                    com.hazelcast.cluster.impl.VectorClock observedTimestamps)

      Subtracts the given value from the current value.

      The method can throw a `ConsistencyLostException` when the state of this CRDT is not causally related to the observed timestamps. This means that it cannot provide the session guarantees of RYW (read your writes) and monotonic read.

      Parameters:
        `delta` - the value to add
        `observedTimestamps` - the vector clock last observed by the client of this counter
      Returns:
        the current counter value with the current counter vector clock
      Throws:
        `ConsistencyLostException` - if this replica cannot provide the session guarantees

    - #### subtractAndGet

          public CRDTTimestampedLong subtractAndGet(long delta,
                                                    com.hazelcast.cluster.impl.VectorClock observedTimestamps)

      Subtracts the given value from the current value.

      The method can throw a `ConsistencyLostException` when the state of this CRDT is not causally related to the observed timestamps. This means that it cannot provide the session guarantees of RYW (read your writes) and monotonic read.

      Parameters:
        `delta` - the value to subtract
        `observedTimestamps` - the vector clock last observed by the client of this counter
      Returns:
        the current counter value with the current counter vector clock
      Throws:
        `ConsistencyLostException` - if this replica cannot provide the session guarantees

    - #### merge

          public void merge(PNCounterImpl other)

      Description copied from interface: `CRDT`
      Merges the state of a different replica into this CRDT. The merge method should not leave the CRDT in a failed state.
      Specified by:
        `merge` in interface `CRDT<PNCounterImpl>`
      Parameters:
        `other` - the CRDT to merge into this CRDT

    - #### getCurrentVectorClock

          public com.hazelcast.cluster.impl.VectorClock getCurrentVectorClock()

      Description copied from interface: `CRDT`
      Returns the current vector clock which reflects the current CRDT state.
      Specified by:
        `getCurrentVectorClock` in interface `CRDT<PNCounterImpl>`

    - #### getFactoryId

          public int getFactoryId()

      Description copied from interface: `IdentifiedDataSerializable`
      Returns DataSerializableFactory factory ID for this class.
      Specified by:
        `getFactoryId` in interface `IdentifiedDataSerializable`
      Returns:
        factory ID

    - #### getId

          public int getId()

      Description copied from interface: `IdentifiedDataSerializable`
      Returns type identifier for this class. It should be unique per DataSerializableFactory.
      Specified by:
        `getId` in interface `IdentifiedDataSerializable`
      Returns:
        type ID

    - #### writeData

          public void writeData(ObjectDataOutput out)
                         throws IOException

      Description copied from interface: `DataSerializable`
      Writes object fields to output stream
      Specified by:
        `writeData` in interface `DataSerializable`
      Parameters:
        `out` - output
      Throws:
        `IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the output stream has been closed.

    - #### readData

          public void readData(ObjectDataInput in)
                        throws IOException

      Description copied from interface: `DataSerializable`
      Reads fields from the input stream
      Specified by:
        `readData` in interface `DataSerializable`
      Parameters:
        `in` - input
      Throws:
        `IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the input stream has been closed.

    - #### markMigrated

          public boolean markMigrated(com.hazelcast.cluster.impl.VectorClock vectorClock)

      Marks this CRDT as migrated. A migrated CRDT can no longer be mutated. For this CRDT to be marked as migrated, the provided `vectorClock` must be equal to the current vector clock.
      Parameters:
        `vectorClock` - a vector clock to compare the current clock to
      Returns:
        `true` if this CRDT has been marked as migrated, `false` otherwise

    - #### markMigrated

          public void markMigrated()

      Unconditionally marks this CRDT as migrated. A migrated CRDT can no longer be mutated.

Copyright © 2018. All rights reserved.