package com.atlassian.bitbucket.mesh.coordination;

import javax.annotation.Nonnull;

/**
 * Handler to receive a granted {@link WriteToken}
 */
public interface WriteTokenHandler {

    /**
     * Called by the system when the token is granted
     *
     * @param token the granted token
     */
    void onGranted(@Nonnull WriteToken token);

    /**
     * Called by the system when it detects that another process or thread has a higher priority request for
     * the token (i.e. with a lower logical timestamp). When called the token holder should immediately
     * {@link WriteToken#yieldToken() release} the token, unless it has already acquired the write lock.
     */
    void yieldToken();
}
