add factory

This commit is contained in:
Ken Stevens 2019-11-19 17:23:06 -05:00
parent f3535a2bef
commit b73cdbcaf5
4 changed files with 32 additions and 12 deletions

View File

@ -10,13 +10,13 @@ import ca.uhn.fhir.jpa.bulk.BulkDataExportProvider;
import ca.uhn.fhir.jpa.bulk.BulkDataExportSvcImpl;
import ca.uhn.fhir.jpa.bulk.IBulkDataExportSvc;
import ca.uhn.fhir.jpa.dao.DaoRegistry;
import ca.uhn.fhir.jpa.delete.DeleteConflictService;
import ca.uhn.fhir.jpa.graphql.JpaStorageServices;
import ca.uhn.fhir.jpa.interceptor.JpaConsentContextServices;
import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
import ca.uhn.fhir.jpa.sched.AutowiringSpringBeanJobFactory;
import ca.uhn.fhir.jpa.sched.SchedulerFactory;
import ca.uhn.fhir.jpa.sched.SchedulerServiceImpl;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
@ -36,13 +36,6 @@ import ca.uhn.fhir.jpa.subscription.module.cache.LinkedBlockingQueueSubscribable
import ca.uhn.fhir.jpa.subscription.module.channel.ISubscribableChannelFactory;
import ca.uhn.fhir.jpa.subscription.module.matcher.ISubscriptionMatcher;
import ca.uhn.fhir.jpa.subscription.module.matcher.InMemorySubscriptionMatcher;
import ca.uhn.fhir.jpa.term.TermCodeSystemStorageSvcImpl;
import ca.uhn.fhir.jpa.term.TermDeferredStorageSvcImpl;
import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermReindexingSvc;
import ca.uhn.fhir.rest.server.interceptor.consent.IConsentContextServices;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
@ -260,6 +253,11 @@ public abstract class BaseConfig {
return new SchedulerServiceImpl();
}
@Bean
public SchedulerFactory schedulerFactory() {
return new SchedulerFactory();
}
@Bean
public AutowiringSpringBeanJobFactory schedulerJobFactory() {
return new AutowiringSpringBeanJobFactory();

View File

@ -0,0 +1,18 @@
package ca.uhn.fhir.jpa.sched;
import org.springframework.beans.factory.annotation.Autowired;
public class SchedulerFactory {
public static final String THREAD_NAME_PREFIX = "hapi-fhir-jpa-scheduler";
@Autowired
private AutowiringSpringBeanJobFactory mySpringBeanJobFactory;
public IHapiScheduler newClusteredHapiScheduler() {
return new ClusteredHapiScheduler(THREAD_NAME_PREFIX, mySpringBeanJobFactory);
}
public IHapiScheduler newLocalHapiScheduler() {
return new LocalHapiScheduler(THREAD_NAME_PREFIX, mySpringBeanJobFactory);
}
}

View File

@ -57,7 +57,6 @@ public class SchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
public static final String SCHEDULING_DISABLED_EQUALS_TRUE = SCHEDULING_DISABLED + "=true";
private static final Logger ourLog = LoggerFactory.getLogger(SchedulerServiceImpl.class);
public static final String THREAD_NAME_PREFIX = "hapi-fhir-jpa-scheduler";
private IHapiScheduler myLocalScheduler;
private IHapiScheduler myClusteredScheduler;
private boolean myLocalSchedulingEnabled;
@ -65,7 +64,7 @@ public class SchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
private AtomicBoolean myStopping = new AtomicBoolean(false);
@Autowired
private AutowiringSpringBeanJobFactory mySpringBeanJobFactory;
private SchedulerFactory mySchedulerFactory;
@Autowired
private Environment myEnvironment;
@Autowired
@ -108,9 +107,9 @@ public class SchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
}
IHapiScheduler retval;
if (theClustered) {
retval = new ClusteredHapiScheduler(THREAD_NAME_PREFIX, mySpringBeanJobFactory);
retval = mySchedulerFactory.newClusteredHapiScheduler();
} else {
retval = new LocalHapiScheduler(THREAD_NAME_PREFIX, mySpringBeanJobFactory);
retval = mySchedulerFactory.newLocalHapiScheduler();
}
retval.init();
return retval;

View File

@ -191,6 +191,11 @@ public class SchedulerServiceImplTest {
return new SchedulerServiceImpl();
}
@Bean
public SchedulerFactory schedulerFactory() {
return new SchedulerFactory();
}
@Bean
public String stringBean() {
return "String beans are good.";