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.Transaction; 022import org.fcrepo.kernel.api.identifiers.FedoraId; 023import org.fcrepo.kernel.api.operations.ResourceOperation; 024 025/** 026 * Accumulates events for changes made to resources, grouped by transaction. The events are not emitted until after the 027 * transaction has been committed. If a transaction is rolled back, {@link #clearEvents} MUST be called to release the 028 * stored events. 029 * 030 * @author pwinckles 031 */ 032public interface EventAccumulator { 033 034 /** 035 * Registers a new event to a transaction. 036 * 037 * @param transaction the transaction 038 * @param fedoraId the id of the affected resource 039 * @param operation the operation affecting the resource 040 */ 041 void recordEventForOperation(Transaction transaction, FedoraId fedoraId, ResourceOperation operation); 042 043 /** 044 * Emits all of the events that were accumulated within the transaction. Multiple events affecting the same resource 045 * are combined into a single event. 046 * 047 * <p>This method SHOULD NOT throw an exception if an event fails to be emitted. It should always attempt to emit 048 * all events accumulated within a transaction. 049 * 050 * @param transaction the transaction 051 * @param baseUrl the baseUrl of the requests 052 * @param userAgent the user-agent of the user making the requests 053 */ 054 void emitEvents(Transaction transaction, String baseUrl, String userAgent); 055 056 /** 057 * Removes all of a transaction's accumulated events without emitting them. This must be called when a transaction 058 * is rolled back. 059 * 060 * @param transaction the id of the transaction 061 */ 062 void clearEvents(Transaction transaction); 063 064}