001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.fcrepo.kernel.api.observer;
020
021import org.fcrepo.kernel.api.identifiers.FedoraId;
022import org.fcrepo.kernel.api.operations.ResourceOperation;
023
024/**
025 * Accumulates events for changes made to resources, grouped by transaction. The events are not emitted until after the
026 * transaction has been committed. If a transaction is rolled back, {@link #clearEvents} MUST be called to release the
027 * stored events.
028 *
029 * @author pwinckles
030 */
031public interface EventAccumulator {
032
033    /**
034     * Registers a new event to a transaction.
035     *
036     * @param transactionId the id of the transaction
037     * @param fedoraId the id of the affected resource
038     * @param operation the operation affecting the resource
039     */
040    void recordEventForOperation(String transactionId, FedoraId fedoraId, ResourceOperation operation);
041
042    /**
043     * Emits all of the events that were accumulated within the transaction. Multiple events affecting the same resource
044     * are combined into a single event.
045     *
046     * <p>This method SHOULD NOT throw an exception if an event fails to be emitted. It should always attempt to emit
047     * all events accumulated within a transaction.
048     *
049     * @param transactionId the id of the transaction
050     * @param baseUrl the baseUrl of the requests
051     * @param userAgent the user-agent of the user making the requests
052     */
053    void emitEvents(String transactionId, String baseUrl, String userAgent);
054
055    /**
056     * Removes all of a transaction's accumulated events without emitting them. This must be called when a transaction
057     * is rolled back.
058     *
059     * @param transactionId the id of the transaction
060     */
061    void clearEvents(String transactionId);
062
063}