001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006
007package org.fcrepo.kernel.api.observer;
008
009import org.fcrepo.kernel.api.Transaction;
010import org.fcrepo.kernel.api.identifiers.FedoraId;
011import org.fcrepo.kernel.api.operations.ResourceOperation;
012
013/**
014 * Accumulates events for changes made to resources, grouped by transaction. The events are not emitted until after the
015 * transaction has been committed. If a transaction is rolled back, {@link #clearEvents} MUST be called to release the
016 * stored events.
017 *
018 * @author pwinckles
019 */
020public interface EventAccumulator {
021
022    /**
023     * Registers a new event to a transaction.
024     *
025     * @param transaction the transaction
026     * @param fedoraId the id of the affected resource
027     * @param operation the operation affecting the resource
028     */
029    void recordEventForOperation(Transaction transaction, FedoraId fedoraId, ResourceOperation operation);
030
031    /**
032     * Emits all of the events that were accumulated within the transaction. Multiple events affecting the same resource
033     * are combined into a single event.
034     *
035     * <p>This method SHOULD NOT throw an exception if an event fails to be emitted. It should always attempt to emit
036     * all events accumulated within a transaction.
037     *
038     * @param transaction the transaction
039     * @param baseUrl the baseUrl of the requests
040     * @param userAgent the user-agent of the user making the requests
041     */
042    void emitEvents(Transaction transaction, String baseUrl, String userAgent);
043
044    /**
045     * Removes all of a transaction's accumulated events without emitting them. This must be called when a transaction
046     * is rolled back.
047     *
048     * @param transaction the id of the transaction
049     */
050    void clearEvents(Transaction transaction);
051
052}