From b1d41a8211aefaaf1816a227849e80b8feb76ddd Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Fri, 29 Mar 2019 14:29:36 -0400 Subject: [PATCH] named interceptor registries --- .../main/java/ca/uhn/fhir/jpa/config/BaseConfig.java | 7 ++++++- .../interceptor/executor/InterceptorService.java | 11 ++++++++--- .../module/config/BaseSubscriptionConfig.java | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index c00e5f76537..dcb35b414d8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.config; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.i18n.HapiLocalizer; +import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService; import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc; @@ -23,7 +24,6 @@ import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaDialect; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.SchedulingConfigurer; @@ -169,6 +169,11 @@ public abstract class BaseConfig implements SchedulingConfigurer { return new PersistenceExceptionTranslationPostProcessor(); } + @Bean + public InterceptorService interceptorRegistry() { + return new InterceptorService("hapi-fhir-jpa"); + } + public static void configureEntityManagerFactory(LocalContainerEntityManagerFactoryBean theFactory, FhirContext theCtx) { theFactory.setJpaDialect(hibernateJpaDialect(theCtx.getLocalizer())); theFactory.setPackagesToScan("ca.uhn.fhir.jpa.model.entity", "ca.uhn.fhir.jpa.entity"); diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/executor/InterceptorService.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/executor/InterceptorService.java index 0df3ef841de..f3315f14ff6 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/executor/InterceptorService.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/executor/InterceptorService.java @@ -32,7 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; import javax.annotation.Nonnull; import java.lang.reflect.InvocationTargetException; @@ -41,19 +40,21 @@ import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -@Component public class InterceptorService implements IInterceptorRegistry, IInterceptorBroadcaster { private static final Logger ourLog = LoggerFactory.getLogger(InterceptorService.class); private final List myInterceptors = new ArrayList<>(); private final ListMultimap myInvokers = ArrayListMultimap.create(); private final ListMultimap myAnonymousInvokers = ArrayListMultimap.create(); private final Object myRegistryMutex = new Object(); + private String myName; /** * Constructor + * @param theName */ - public InterceptorService() { + public InterceptorService(String theName) { super(); + myName = theName; } @VisibleForTesting @@ -68,6 +69,10 @@ public class InterceptorService implements IInterceptorRegistry, IInterceptorBro registerAnonymousHookForUnitTest(thePointcut, DEFAULT_ORDER, theHook); } + public void setName(String theName) { + myName = theName; + } + @Override public void registerAnonymousHookForUnitTest(Pointcut thePointcut, int theOrder, IAnonymousLambdaHook theHook) { Validate.notNull(thePointcut); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java index b484886ab18..078133af408 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/BaseSubscriptionConfig.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.module.config; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService; import ca.uhn.fhir.jpa.subscription.module.cache.ISubscribableChannelFactory; import ca.uhn.fhir.jpa.subscription.module.cache.LinkedBlockingQueueSubscribableChannelFactory; import org.springframework.context.annotation.Bean; @@ -38,4 +39,11 @@ public abstract class BaseSubscriptionConfig { public ISubscribableChannelFactory blockingQueueSubscriptionDeliveryChannelFactory() { return new LinkedBlockingQueueSubscribableChannelFactory(); } + + @Bean + public InterceptorService interceptorRegistry() { + return new InterceptorService("hapi-fhir-jpa-subscription"); + } + + }