mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-09 06:24:55 +00:00
named interceptor registries (#1259)
This commit is contained in:
commit
e9c1e39ea5
@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.config;
|
|||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.i18n.HapiLocalizer;
|
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.provider.SubscriptionTriggeringProvider;
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
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.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
|
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||||
@ -169,6 +169,11 @@ public abstract class BaseConfig implements SchedulingConfigurer {
|
|||||||
return new PersistenceExceptionTranslationPostProcessor();
|
return new PersistenceExceptionTranslationPostProcessor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public InterceptorService interceptorRegistry() {
|
||||||
|
return new InterceptorService("hapi-fhir-jpa");
|
||||||
|
}
|
||||||
|
|
||||||
public static void configureEntityManagerFactory(LocalContainerEntityManagerFactoryBean theFactory, FhirContext theCtx) {
|
public static void configureEntityManagerFactory(LocalContainerEntityManagerFactoryBean theFactory, FhirContext theCtx) {
|
||||||
theFactory.setJpaDialect(hibernateJpaDialect(theCtx.getLocalizer()));
|
theFactory.setJpaDialect(hibernateJpaDialect(theCtx.getLocalizer()));
|
||||||
theFactory.setPackagesToScan("ca.uhn.fhir.jpa.model.entity", "ca.uhn.fhir.jpa.entity");
|
theFactory.setPackagesToScan("ca.uhn.fhir.jpa.model.entity", "ca.uhn.fhir.jpa.entity");
|
||||||
|
@ -32,7 +32,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -41,19 +40,21 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
|
||||||
public class InterceptorService implements IInterceptorRegistry, IInterceptorBroadcaster {
|
public class InterceptorService implements IInterceptorRegistry, IInterceptorBroadcaster {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(InterceptorService.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(InterceptorService.class);
|
||||||
private final List<Object> myInterceptors = new ArrayList<>();
|
private final List<Object> myInterceptors = new ArrayList<>();
|
||||||
private final ListMultimap<Pointcut, BaseInvoker> myInvokers = ArrayListMultimap.create();
|
private final ListMultimap<Pointcut, BaseInvoker> myInvokers = ArrayListMultimap.create();
|
||||||
private final ListMultimap<Pointcut, BaseInvoker> myAnonymousInvokers = ArrayListMultimap.create();
|
private final ListMultimap<Pointcut, BaseInvoker> myAnonymousInvokers = ArrayListMultimap.create();
|
||||||
private final Object myRegistryMutex = new Object();
|
private final Object myRegistryMutex = new Object();
|
||||||
|
private String myName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
* @param theName
|
||||||
*/
|
*/
|
||||||
public InterceptorService() {
|
public InterceptorService(String theName) {
|
||||||
super();
|
super();
|
||||||
|
myName = theName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@ -68,6 +69,10 @@ public class InterceptorService implements IInterceptorRegistry, IInterceptorBro
|
|||||||
registerAnonymousHookForUnitTest(thePointcut, DEFAULT_ORDER, theHook);
|
registerAnonymousHookForUnitTest(thePointcut, DEFAULT_ORDER, theHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String theName) {
|
||||||
|
myName = theName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerAnonymousHookForUnitTest(Pointcut thePointcut, int theOrder, IAnonymousLambdaHook theHook) {
|
public void registerAnonymousHookForUnitTest(Pointcut thePointcut, int theOrder, IAnonymousLambdaHook theHook) {
|
||||||
Validate.notNull(thePointcut);
|
Validate.notNull(thePointcut);
|
||||||
|
@ -201,8 +201,10 @@ public class InterceptorServiceTest {
|
|||||||
@ComponentScan(basePackages = "ca.uhn.fhir.jpa.model")
|
@ComponentScan(basePackages = "ca.uhn.fhir.jpa.model")
|
||||||
static class InterceptorRegistryTestCtxConfig {
|
static class InterceptorRegistryTestCtxConfig {
|
||||||
|
|
||||||
@Autowired
|
@Bean
|
||||||
private IInterceptorRegistry myInterceptorRegistry;
|
public InterceptorService interceptorService() {
|
||||||
|
return new InterceptorService("test");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: Orders are deliberately reversed to make sure we get the orders right
|
* Note: Orders are deliberately reversed to make sure we get the orders right
|
||||||
@ -211,7 +213,7 @@ public class InterceptorServiceTest {
|
|||||||
@Bean
|
@Bean
|
||||||
public MyTestInterceptorTwo interceptor1() {
|
public MyTestInterceptorTwo interceptor1() {
|
||||||
MyTestInterceptorTwo retVal = new MyTestInterceptorTwo();
|
MyTestInterceptorTwo retVal = new MyTestInterceptorTwo();
|
||||||
myInterceptorRegistry.registerInterceptor(retVal);
|
interceptorService().registerInterceptor(retVal);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +224,7 @@ public class InterceptorServiceTest {
|
|||||||
@Bean
|
@Bean
|
||||||
public MyTestInterceptorOne interceptor2() {
|
public MyTestInterceptorOne interceptor2() {
|
||||||
MyTestInterceptorOne retVal = new MyTestInterceptorOne();
|
MyTestInterceptorOne retVal = new MyTestInterceptorOne();
|
||||||
myInterceptorRegistry.registerInterceptor(retVal);
|
interceptorService().registerInterceptor(retVal);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.module.config;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
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.ISubscribableChannelFactory;
|
||||||
import ca.uhn.fhir.jpa.subscription.module.cache.LinkedBlockingQueueSubscribableChannelFactory;
|
import ca.uhn.fhir.jpa.subscription.module.cache.LinkedBlockingQueueSubscribableChannelFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -38,4 +39,11 @@ public abstract class BaseSubscriptionConfig {
|
|||||||
public ISubscribableChannelFactory blockingQueueSubscriptionDeliveryChannelFactory() {
|
public ISubscribableChannelFactory blockingQueueSubscriptionDeliveryChannelFactory() {
|
||||||
return new LinkedBlockingQueueSubscribableChannelFactory();
|
return new LinkedBlockingQueueSubscribableChannelFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public InterceptorService interceptorRegistry() {
|
||||||
|
return new InterceptorService("hapi-fhir-jpa-subscription");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user