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; 019 020/** 021 * Observer for consuming events. 022 */ 023public interface Observer 024{ 025 /** Minimum priority. */ 026 public static final int MIN_PRIORITY = Integer.MAX_VALUE; 027 /** Maximum priority. */ 028 public static final int MAX_PRIORITY = 0; 029 030 /** 031 * Checks if the event is supported. If true, the observe(Event) method will be called. 032 * @param event the event. 033 * @return <code>true</code> for observing this event, <code>false</code> otherwise. 034 */ 035 boolean supports(Event event); 036 037 /** 038 * Retrieves the priority to observe this event.<br> 039 * This can be used to process a supported event before others observers. 040 * @param event the event. 041 * @return the priority where 0 the max priority and Integer.MAX_VALUE the min priority. 042 */ 043 int getPriority(Event event); 044 045 /** 046 * Observes an event. 047 * @param event the event. 048 * @param transientVars transientVars passed from one Observer to another when processing a single Event. 049 * This may allow optimizations between observers. 050 * @throws Exception if an error occurs. 051 * All exceptions will be logged but not propagated, as the observation mechanism should never fail. 052 */ 053 void observe(Event event, Map<String, Object> transientVars) throws Exception; 054}