001package ca.uhn.fhir.interceptor.api; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 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.Predicate; 027 028public interface IBaseInterceptorService<POINTCUT extends IPointcut> extends IBaseInterceptorBroadcaster<POINTCUT> { 029 030 /** 031 * Register an interceptor that will be used in a {@link ThreadLocal} context. 032 * This means that events will only be broadcast to the given interceptor if 033 * they were fired from the current thread. 034 * <p> 035 * Note that it is almost always desirable to call this method with a 036 * try-finally statement that removes the interceptor afterwards, since 037 * this can lead to memory leakage, poor performance due to ever-increasing 038 * numbers of interceptors, etc. 039 * </p> 040 * <p> 041 * Note that most methods such as {@link #getAllRegisteredInterceptors()} and 042 * {@link #unregisterAllInterceptors()} do not affect thread local interceptors 043 * as they are kept in a separate list. 044 * </p> 045 * <p> 046 * ThreadLocal interceptors are now disabled by default as of HAPI FHIR 6.2.0 and must be manually 047 * enabled by calling {@link ca.uhn.fhir.interceptor.executor.BaseInterceptorService#setThreadlocalInvokersEnabled(boolean)}. 048 * They are now deprecated. Registering a threadlocal interceptor without enabling this feature will 049 * result in a {@link IllegalArgumentException}. 050 * </p> 051 * 052 * @param theInterceptor The interceptor 053 * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor 054 * @deprecated Threadlocal interceptors have been deprecated as of HAPI FHIR 6.2.0 and will be removed in a future release due to lack of use. If you feel that this is a bad decision, please speak up on the HAPI FHIR mailing list. 055 */ 056 @Deprecated 057 boolean registerThreadLocalInterceptor(Object theInterceptor); 058 059 /** 060 * Unregisters a ThreadLocal interceptor 061 * <p> 062 * ThreadLocal interceptors are now disabled by default as of HAPI FHIR 6.2.0 and must be manually 063 * enabled by calling {@link ca.uhn.fhir.interceptor.executor.BaseInterceptorService#setThreadlocalInvokersEnabled(boolean)}. 064 * They are now deprecated. Registering a threadlocal interceptor without enabling this feature will 065 * result in a {@link IllegalArgumentException}. 066 * </p> 067 * 068 * @param theInterceptor The interceptor 069 * @see #registerThreadLocalInterceptor(Object) 070 * @deprecated Threadlocal interceptors have been deprecated as of HAPI FHIR 6.2.0 and will be removed in a future release due to lack of use. If you feel that this is a bad decision, please speak up on the HAPI FHIR mailing list. 071 */ 072 @Deprecated 073 void unregisterThreadLocalInterceptor(Object theInterceptor); 074 075 /** 076 * Register an interceptor. This method has no effect if the given interceptor is already registered. 077 * 078 * @param theInterceptor The interceptor to register 079 * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor 080 */ 081 boolean registerInterceptor(Object theInterceptor); 082 083 /** 084 * Unregister an interceptor. This method has no effect if the given interceptor is not already registered. 085 * 086 * @param theInterceptor The interceptor to unregister 087 * @return Returns <code>true</code> if the interceptor was found and removed 088 */ 089 boolean unregisterInterceptor(Object theInterceptor); 090 091 /** 092 * Returns all currently registered interceptors (excluding any thread local interceptors). 093 */ 094 List<Object> getAllRegisteredInterceptors(); 095 096 /** 097 * Unregisters all registered interceptors. Note that this method does not unregister 098 * any {@link #registerThreadLocalInterceptor(Object) thread local interceptors}. 099 */ 100 void unregisterAllInterceptors(); 101 102 void unregisterInterceptors(@Nullable Collection<?> theInterceptors); 103 104 void registerInterceptors(@Nullable Collection<?> theInterceptors); 105 106 /** 107 * Unregisters all interceptors that are indicated by the given callback function returning <code>true</code> 108 */ 109 void unregisterInterceptorsIf(Predicate<Object> theShouldUnregisterFunction); 110 111 /** 112 * Unregisters all anonymous interceptors (i.e. all interceptors registered with <code>registerAnonymousInterceptor</code>) 113 */ 114 void unregisterAllAnonymousInterceptors(); 115}