001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.interceptor.api;
021
022import javax.annotation.Nullable;
023import java.util.Collection;
024import java.util.List;
025import java.util.function.Predicate;
026
027public interface IBaseInterceptorService<POINTCUT extends IPointcut> extends IBaseInterceptorBroadcaster<POINTCUT> {
028
029        /**
030         * Register an interceptor. This method has no effect if the given interceptor is already registered.
031         *
032         * @param theInterceptor The interceptor to register
033         * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor
034         */
035        boolean registerInterceptor(Object theInterceptor);
036
037        /**
038         * Unregister an interceptor. This method has no effect if the given interceptor is not already registered.
039         *
040         * @param theInterceptor The interceptor to unregister
041         * @return Returns <code>true</code> if the interceptor was found and removed
042         */
043        boolean unregisterInterceptor(Object theInterceptor);
044
045        /**
046         * Returns all currently registered interceptors (excluding any thread local interceptors).
047         */
048        List<Object> getAllRegisteredInterceptors();
049
050        /**
051         * Unregisters all registered interceptors.
052         */
053        void unregisterAllInterceptors();
054
055        void unregisterInterceptors(@Nullable Collection<?> theInterceptors);
056
057        void registerInterceptors(@Nullable Collection<?> theInterceptors);
058
059        /**
060         * Unregisters all interceptors that are indicated by the given callback function returning <code>true</code>
061         */
062        void unregisterInterceptorsIf(Predicate<Object> theShouldUnregisterFunction);
063
064        /**
065         * Unregisters all anonymous interceptors (i.e. all interceptors registered with <code>registerAnonymousInterceptor</code>)
066         */
067        void unregisterAllAnonymousInterceptors();
068}