001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.ecm.core.event;
020
021import java.io.Serializable;
022import java.rmi.dgc.VMID;
023
024/**
025 * An ordered set of events raised during an user operation.
026 * <p>
027 * The bundle is used collects any events that is raised during an user operation. The bundle will be send after the
028 * operation commit to any registered {@link PostCommitEventListener}.
029 * <p>
030 * The bundle implementation is free to ignore some events. This is the case for events marked as inline or for
031 * duplicate events.
032 *
033 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
034 */
035public interface EventBundle extends Iterable<Event>, Serializable {
036
037    /**
038     * Gets the bundle name.
039     * <p>
040     * This is usually the first event repository name in the bundle but the implementation may decide to change this
041     * behavior.
042     *
043     * @return the bundle name. Can be null only if the bundle is empty.
044     */
045    String getName();
046
047    /**
048     * Adds an event in that bundle at the end of the list.
049     * <p>
050     * The bundle implementation must ignore redundant events and events marked as inline.
051     *
052     * @param event the event to append.
053     */
054    void push(Event event);
055
056    /**
057     * Gets the first event in that bundle.
058     *
059     * @return the first event. Can be null if the bundle is empty
060     */
061    Event peek();
062
063    /**
064     * Tests whether or not this bundle is empty.
065     */
066    boolean isEmpty();
067
068    /**
069     * Gets the size of that bundle.
070     *
071     * @return the number of events in that bundle
072     */
073    int size();
074
075    /**
076     * Tests whether or not this event bundle was created on a remote machine.
077     *
078     * @return true if the event bundle was fired from a remote machine, false otherwise
079     */
080    boolean hasRemoteSource();
081
082    /**
083     * Returns the VMID of the JVM where the bundle was created.
084     */
085    VMID getSourceVMID();
086
087    /**
088     * Check is bundle contains the specified event.
089     */
090    boolean containsEventName(String eventName);
091
092}