package anastore.client;

import anastore.store.NoSuchDatum;
import anastore.util.Bug;

import java.nio.ByteBuffer;

/**
 * A single snapshot in time.  It can be either read-only or
 * read-write, depending on the subclass.  This class represents the
 * combination of the two possibilities, in accordance with the Liskov
 * Substitution Principle.  It supports the intersection of their
 * operations, and the union of their exceptions.
 */
public abstract class Snapshot
{
    /**
     * Retrieves a read-only copy of the requested block from the
     * current snapshot.
     *
     * @throws AbortedException if the transaction has been aborted
     * @throws IllegalStateException if the transaction has been
     * committed or is in the process of committing
     * @throws NoSuchDatum if id refers to a datum that does not exist
     * in the current snapshot
     */
    public abstract ByteBuffer readBlock(long id)
        throws AbortedException, IllegalStateException, NoSuchDatum;

    /**
     * Commit the current transaction.
     *
     * @throws AbortedException if the transaction has been aborted
     * @throws IllegalStateException if the transaction has already
     * been committed or is in the process of committing
     */
    public abstract void commit()
        throws AbortedException, IllegalStateException;
}
