package com.atlassian.bitbucket.concurrent;

import javax.annotation.Nonnull;
import java.io.Serializable;

/**
 * Tracks a version against a key. This can be used in a cluster to help track changes to entities across the cluster.
 *
 * @param <K> the type of the key
 */
public interface VersionTracker<K extends Serializable> {
    /**
     * @return retrieves the current version for the supplied key
     */
    int get(@Nonnull K key);

    /**
     * Increments the version for the supplied key
     */
    void increment(@Nonnull K key);

    /**
     * @return the incremented version for the supplied key
     */
    int incrementAndGet(@Nonnull K key);

    /**
     * Increments all versions for all known keys.
     * <p>
     * <b>Note</b>: This is potentially an expensive operation, especially in a cluster.
     */
    void incrementAll();
}
