simplified api

This commit is contained in:
Ken Stevens 2019-11-25 20:59:40 -05:00
parent 4c7c574eef
commit a89bb6c411
6 changed files with 32 additions and 54 deletions

View File

@ -15,8 +15,7 @@ import ca.uhn.fhir.jpa.interceptor.JpaConsentContextServices;
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.HapiSchedulerFactory;
import ca.uhn.fhir.jpa.sched.SchedulerServiceImpl;
import ca.uhn.fhir.jpa.sched.HapiSchedulerServiceImpl;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
@ -36,7 +35,6 @@ 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.rest.server.interceptor.consent.IConsentContextServices;
import ca.uhn.fhir.rest.server.sched.ISchedulerFactory;
import ca.uhn.fhir.rest.server.sched.ISchedulerService;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
@ -251,11 +249,7 @@ public abstract class BaseConfig {
@Bean
public ISchedulerService schedulerService() {
return new SchedulerServiceImpl(hapiSchedulerFactory());
}
@Bean
public ISchedulerFactory hapiSchedulerFactory() {
return new HapiSchedulerFactory();
return new HapiSchedulerServiceImpl();
}
@Bean

View File

@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.sched;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.model.api.ISmartLifecyclePhase;
import ca.uhn.fhir.rest.server.sched.IHapiScheduler;
import ca.uhn.fhir.rest.server.sched.ISchedulerFactory;
import ca.uhn.fhir.rest.server.sched.ISchedulerService;
import ca.uhn.fhir.rest.server.sched.ScheduledJobDefinition;
import org.quartz.SchedulerException;
@ -54,38 +53,29 @@ import java.util.concurrent.atomic.AtomicBoolean;
* </li>
* </ul>
*/
public class SchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
public abstract class BaseSchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
public static final String SCHEDULING_DISABLED = "scheduling_disabled";
public static final String SCHEDULING_DISABLED_EQUALS_TRUE = SCHEDULING_DISABLED + "=true";
private static final Logger ourLog = LoggerFactory.getLogger(SchedulerServiceImpl.class);
private static final Logger ourLog = LoggerFactory.getLogger(BaseSchedulerServiceImpl.class);
private IHapiScheduler myLocalScheduler;
private IHapiScheduler myClusteredScheduler;
private boolean myLocalSchedulingEnabled;
private boolean myClusteredSchedulingEnabled;
private AtomicBoolean myStopping = new AtomicBoolean(false);
private final ISchedulerFactory mySchedulerFactory;
@Autowired
private Environment myEnvironment;
@Autowired
private ApplicationContext myApplicationContext;
@Autowired
protected AutowiringSpringBeanJobFactory mySchedulerJobFactory;
/**
* Constructor
* @param theSchedulerFactory
*/
public SchedulerServiceImpl(ISchedulerFactory theSchedulerFactory) {
mySchedulerFactory = theSchedulerFactory;
public BaseSchedulerServiceImpl() {
setLocalSchedulingEnabled(true);
setClusteredSchedulingEnabled(true);
}
public ISchedulerFactory getSchedulerFactory() {
return mySchedulerFactory;
}
public boolean isLocalSchedulingEnabled() {
return myLocalSchedulingEnabled;
}
@ -116,15 +106,19 @@ public class SchedulerServiceImpl implements ISchedulerService, SmartLifecycle {
IHapiScheduler retval;
if (theClustered) {
ourLog.info("Creating Clustered Scheduler");
retval = mySchedulerFactory.newClusteredHapiScheduler();
retval = getClusteredScheduler();
} else {
ourLog.info("Creating Local Scheduler");
retval = mySchedulerFactory.newLocalHapiScheduler();
retval = getLocalHapiScheduler();
}
retval.init();
return retval;
}
protected abstract IHapiScheduler getLocalHapiScheduler();
protected abstract IHapiScheduler getClusteredScheduler();
/**
* We defer startup of executing started tasks until we're sure we're ready for it
* and the startup is completely done

View File

@ -1,20 +0,0 @@
package ca.uhn.fhir.jpa.sched;
import ca.uhn.fhir.rest.server.sched.IHapiScheduler;
import ca.uhn.fhir.rest.server.sched.ISchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
public class HapiSchedulerFactory implements ISchedulerFactory {
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

@ -0,0 +1,17 @@
package ca.uhn.fhir.jpa.sched;
import ca.uhn.fhir.rest.server.sched.IHapiScheduler;
public class HapiSchedulerServiceImpl extends BaseSchedulerServiceImpl {
public static final String THREAD_NAME_PREFIX = "hapi-fhir-jpa-scheduler";
@Override
protected IHapiScheduler getLocalHapiScheduler() {
return new LocalHapiScheduler(THREAD_NAME_PREFIX, mySchedulerJobFactory);
}
@Override
protected IHapiScheduler getClusteredScheduler() {
return new ClusteredHapiScheduler(THREAD_NAME_PREFIX, mySchedulerJobFactory);
}
}

View File

@ -65,7 +65,7 @@ public class SchedulerServiceImplTest {
.setId(CountingJob.class.getName())
.setJobClass(CountingJob.class);
SchedulerServiceImpl svc = AopTestUtils.getTargetObject(mySvc);
BaseSchedulerServiceImpl svc = AopTestUtils.getTargetObject(mySvc);
svc.stop();
svc.create();
svc.start();
@ -186,7 +186,7 @@ public class SchedulerServiceImplTest {
@Bean
public ISchedulerService schedulerService() {
return new SchedulerServiceImpl(new HapiSchedulerFactory());
return new HapiSchedulerServiceImpl();
}
@Bean

View File

@ -1,7 +0,0 @@
package ca.uhn.fhir.rest.server.sched;
public interface ISchedulerFactory {
IHapiScheduler newClusteredHapiScheduler();
IHapiScheduler newLocalHapiScheduler();
}