Package io.permazen
Class Counter
java.lang.Object
io.permazen.Counter
Represents a 64-bit counter value that can be adjusted concurrently by multiple transactions,
typically without locking (depending on the underlying key/value store).
To define a field of type Counter
, annotate the field's getter method as a normal field using
@PermazenField
. No setter method should be defined.
Counter fields do not support indexing or change listeners.
Note: during schema change notifications, counter field values appear as plain Long
values.
-
Method Summary
-
Method Details
-
get
public long get()Read this counter's current value. Invoking this method will typically disable the lock-free behavior ofadjust()
in the current transaction.- Returns:
- current value of the counter
- Throws:
StaleTransactionException
- if the transaction from which this instance was read is no longer usableDeletedObjectException
- if the object from which this instance was read no longer exists
-
set
public void set(long value) Set this counter's value. Invoking this method will typically disable the lock-free behavior ofadjust()
in the current transaction.- Parameters:
value
- new value for the counter- Throws:
StaleTransactionException
- if the transaction from which this instance was read is no longer usableDeletedObjectException
- if the object from which this instance was read no longer exists
-
adjust
public void adjust(long offset) Adjust this counter's value by the specified amount.- Parameters:
offset
- amount to add to counter- Throws:
StaleTransactionException
- if the transaction from which this instance was read is no longer usableDeletedObjectException
- if the object from which this instance was read no longer exists
-
increment
public void increment()Increment this counter's value by one.- Throws:
StaleTransactionException
- if the transaction from which this instance was read is no longer usableDeletedObjectException
- if the object from which this instance was read no longer exists
-
decrement
public void decrement()Decrement this counter's value by one.- Throws:
StaleTransactionException
- if the transaction from which this instance was read is no longer usableDeletedObjectException
- if the object from which this instance was read no longer exists
-