001/*
002 *  Copyright 2013 Anyware Services
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 */
016package org.ametys.core.observation;
017
018import java.util.Map;
019import java.util.Set;
020
021import org.ametys.runtime.plugin.component.Prioritizable;
022import org.ametys.runtime.plugin.component.Supporter;
023
024/**
025 * Observer for consuming events.
026 */
027public interface Observer extends Prioritizable, Supporter<Event>
028{
029    /** Minimum priority. */
030    public static final int MIN_PRIORITY = Integer.MAX_VALUE;
031    /** Maximum priority. */
032    public static final int MAX_PRIORITY = 0;
033    
034    /**
035     * Observes an event.
036     * @param event the event.
037     * @param transientVars transientVars passed from one Observer to another when processing a single Event.
038     * This may allow optimizations between observers.
039     * @throws Exception if an error occurs.
040     * All exceptions will be logged but not propagated, as the observation mechanism should never fail.
041     */
042    public void observe(Event event, Map<String, Object> transientVars) throws Exception;
043    
044    /**
045     * Get the traits of the observer
046     * @return the traits of the observer
047     */
048    public default Set<String> getTraits()
049    {
050        return Set.of();
051    }
052}