001package ca.uhn.fhir.interceptor.api;
002
003/*-
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2019 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;
026
027public interface IInterceptorService extends IInterceptorBroadcaster {
028
029        /**
030         * Register an interceptor that will be used in a {@link ThreadLocal} context.
031         * This means that events will only be broadcast to the given interceptor if
032         * they were fired from the current thread.
033         * <p>
034         * Note that it is almost always desirable to call this method with a
035         * try-finally statement that removes the interceptor afterwards, since
036         * this can lead to memory leakage, poor performance due to ever-increasing
037         * numbers of interceptors, etc.
038         * </p>
039         * <p>
040         * Note that most methods such as {@link #getAllRegisteredInterceptors()} and
041         * {@link #unregisterAllInterceptors()} do not affect thread local interceptors
042         * as they are kept in a separate list.
043         * </p>
044         *
045         * @param theInterceptor The interceptor
046         * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor
047         */
048        boolean registerThreadLocalInterceptor(Object theInterceptor);
049
050        /**
051         * Unregisters a ThreadLocal interceptor
052         *
053         * @param theInterceptor The interceptor
054         * @see #registerThreadLocalInterceptor(Object)
055         */
056        void unregisterThreadLocalInterceptor(Object theInterceptor);
057
058        /**
059         * Register an interceptor. This method has no effect if the given interceptor is already registered.
060         *
061         * @param theInterceptor The interceptor to register
062         * @return Returns <code>true</code> if at least one valid hook method was found on this interceptor
063         */
064        boolean registerInterceptor(Object theInterceptor);
065
066        /**
067         * Unregister an interceptor. This method has no effect if the given interceptor is not already registered.
068         *
069         * @param theInterceptor The interceptor to unregister
070         * @return Returns <code>true</code> if the interceptor was found and removed
071         */
072        boolean unregisterInterceptor(Object theInterceptor);
073
074        void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor);
075
076        void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor);
077
078        /**
079         * Returns all currently registered interceptors (excluding any thread local interceptors).
080         */
081        List<Object> getAllRegisteredInterceptors();
082
083        /**
084         * Unregisters all registered interceptors. Note that this method does not unregister
085         * any {@link #registerThreadLocalInterceptor(Object) thread local interceptors}.
086         */
087        void unregisterAllInterceptors();
088
089        void unregisterInterceptors(@Nullable Collection<?> theInterceptors);
090
091        void registerInterceptors(@Nullable Collection<?> theInterceptors);
092
093}