001package ca.uhn.fhir.interceptor.api; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2020 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import javax.annotation.Nullable; 024import java.util.Collection; 025import java.util.List; 026import java.util.function.Function; 027import java.util.function.Predicate; 028 029public interface IInterceptorService extends IInterceptorBroadcaster { 030 031 /** 032 * Register an interceptor that will be used in a {@link ThreadLocal} context. 033 * This means that events will only be broadcast to the given interceptor if 034 * they were fired from the current thread. 035 * <p> 036 * Note that it is almost always desirable to call this method with a 037 * try-finally statement that removes the interceptor afterwards, since 038 * this can lead to memory leakage, poor performance due to ever-increasing 039 * numbers of interceptors, etc. 040 * </p> 041 * <p> 042 * Note that most methods such as {@link #getAllRegisteredInterceptors()} and 043 * {@link #unregisterAllInterceptors()} do not affect thread local interceptors 044 * as they are kept in a separate list. 045 * </p> 046 * 047 * @param theInterceptor The interceptor 048 * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor 049 */ 050 boolean registerThreadLocalInterceptor(Object theInterceptor); 051 052 /** 053 * Unregisters a ThreadLocal interceptor 054 * 055 * @param theInterceptor The interceptor 056 * @see #registerThreadLocalInterceptor(Object) 057 */ 058 void unregisterThreadLocalInterceptor(Object theInterceptor); 059 060 /** 061 * Register an interceptor. This method has no effect if the given interceptor is already registered. 062 * 063 * @param theInterceptor The interceptor to register 064 * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor 065 */ 066 boolean registerInterceptor(Object theInterceptor); 067 068 /** 069 * Unregister an interceptor. This method has no effect if the given interceptor is not already registered. 070 * 071 * @param theInterceptor The interceptor to unregister 072 * @return Returns <code>true</code> if the interceptor was found and removed 073 */ 074 boolean unregisterInterceptor(Object theInterceptor); 075 076 void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor); 077 078 void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor); 079 080 /** 081 * Returns all currently registered interceptors (excluding any thread local interceptors). 082 */ 083 List<Object> getAllRegisteredInterceptors(); 084 085 /** 086 * Unregisters all registered interceptors. Note that this method does not unregister 087 * any {@link #registerThreadLocalInterceptor(Object) thread local interceptors}. 088 */ 089 void unregisterAllInterceptors(); 090 091 void unregisterInterceptors(@Nullable Collection<?> theInterceptors); 092 093 void registerInterceptors(@Nullable Collection<?> theInterceptors); 094 095 /** 096 * Unregisters all interceptors that are indicated by the given callback function returning <code>true</code> 097 */ 098 void unregisterInterceptorsIf(Predicate<Object> theShouldUnregisterFunction); 099}