Interface LiveCounterInstance

All Superinterfaces:
Instance

public interface LiveCounterInstance extends Instance
A Instance bound to a LiveCounter. Provides type-safe access to counter operations such as value(), increment(Number) and decrement(Number).

Spec: RTTS10b

  • Method Details

    • getId

      @NotNull @NotNull String getId()
      Returns the object id of the wrapped LiveCounter.

      Spec: RTINS3a

      Returns:
      the wrapped LiveCounter's object id
    • value

      @NotNull @NotNull Double value()
      Returns the current value of the wrapped LiveCounter.

      Spec: RTINS4 / RTLC5

      Returns:
      the counter value
    • compactJson

      @NotNull @NotNull com.google.gson.JsonPrimitive compactJson()
      Returns the compacted JSON snapshot of the wrapped value, narrowed to a JsonPrimitive: a LiveCounterInstance always compacts to a numeric JSON primitive.

      Spec: RTTS7a

      Specified by:
      compactJson in interface Instance
      Returns:
      the compacted JSON primitive
    • increment

      @NotNull @NotNull CompletableFuture<Void> increment()
      Increments the wrapped LiveCounter by 1. Equivalent to calling increment(Number) with 1.

      Spec: RTINS14a1 (default amount of 1)

      Returns:
      a future that completes when the operation has been acknowledged
    • increment

      @NotNull @NotNull CompletableFuture<Void> increment(@NotNull @NotNull Number amount)
      Increments the wrapped LiveCounter by amount.

      Sends a COUNTER_INC operation to the realtime system; the local state is updated when the operation is echoed back.

      Spec: RTINS14

      Parameters:
      amount - the amount to add (may be negative)
      Returns:
      a future that completes when the operation has been acknowledged
    • decrement

      @NotNull @NotNull CompletableFuture<Void> decrement()
      Decrements the wrapped LiveCounter by 1. Equivalent to calling decrement(Number) with 1.

      Spec: RTINS15a1 (default amount of 1)

      Returns:
      a future that completes when the operation has been acknowledged
    • decrement

      @NotNull @NotNull CompletableFuture<Void> decrement(@NotNull @NotNull Number amount)
      Decrements the wrapped LiveCounter by amount. Equivalent to calling increment(Number) with a negated value.

      Spec: RTINS15

      Parameters:
      amount - the amount to subtract (may be negative)
      Returns:
      a future that completes when the operation has been acknowledged
    • subscribe

      @NonBlocking @NotNull @NotNull Subscription subscribe(@NotNull @NotNull InstanceListener listener)
      Subscribes a listener for updates on the wrapped LiveCounter. The listener is invoked whenever the wrapped counter is changed by a local or remote operation. Call Subscription.unsubscribe() on the returned handle to stop receiving events for this listener.

      The subscription is identity-based: it follows the specific underlying LiveCounter, regardless of where it sits in the LiveObjects graph.

      Spec: RTTS10b / RTINS16

      Parameters:
      listener - the listener to invoke on updates
      Returns:
      a subscription handle that can be used to unsubscribe this listener