named interceptor registries (#1259)

This commit is contained in:
James Agnew 2019-03-29 15:22:11 -04:00 committed by GitHub
commit e9c1e39ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 8 deletions

View File

@ -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");

View File

@ -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<Object> myInterceptors = new ArrayList<>();
private final ListMultimap<Pointcut, BaseInvoker> myInvokers = ArrayListMultimap.create();
private final ListMultimap<Pointcut, BaseInvoker> 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);

View File

@ -201,8 +201,10 @@ public class InterceptorServiceTest {
@ComponentScan(basePackages = "ca.uhn.fhir.jpa.model")
static class InterceptorRegistryTestCtxConfig {
@Autowired
private IInterceptorRegistry myInterceptorRegistry;
@Bean
public InterceptorService interceptorService() {
return new InterceptorService("test");
}
/**
* Note: Orders are deliberately reversed to make sure we get the orders right
@ -211,7 +213,7 @@ public class InterceptorServiceTest {
@Bean
public MyTestInterceptorTwo interceptor1() {
MyTestInterceptorTwo retVal = new MyTestInterceptorTwo();
myInterceptorRegistry.registerInterceptor(retVal);
interceptorService().registerInterceptor(retVal);
return retVal;
}
@ -222,7 +224,7 @@ public class InterceptorServiceTest {
@Bean
public MyTestInterceptorOne interceptor2() {
MyTestInterceptorOne retVal = new MyTestInterceptorOne();
myInterceptorRegistry.registerInterceptor(retVal);
interceptorService().registerInterceptor(retVal);
return retVal;
}

View File

@ -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");
}
}