From f92c2bb5f921916f005417c7e1c55db1a3634ad6 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Fri, 29 Nov 2019 11:46:03 -0500 Subject: [PATCH] ensure only one @PostConstruct method to make order explicit --- .../fhir/jpa/bulk/BulkDataExportSvcImpl.java | 6 +- .../uhn/fhir/jpa/sched/BaseHapiScheduler.java | 2 +- .../jpa/sched/BaseSchedulerServiceImpl.java | 7 +- .../uhn/fhir/jpa/sched/HapiNullScheduler.java | 2 +- .../search/StaleSearchDeletingSvcImpl.java | 28 ++++---- .../search/cache/BaseSearchCacheSvcImpl.java | 10 +-- .../reindex/ResourceReindexingSvcImpl.java | 34 +++++----- .../jpa/search/warm/CacheWarmingSvcImpl.java | 5 +- .../SubscriptionTriggeringSvcImpl.java | 5 +- .../fhir/jpa/term/BaseTermReadSvcImpl.java | 66 +++++++++---------- .../jpa/term/TermDeferredStorageSvcImpl.java | 3 +- .../fhir/jpa/term/TermReindexingSvcImpl.java | 3 +- .../uhn/fhir/jpa/util/ResourceCountCache.java | 10 +-- .../registry/SearchParamRegistryImpl.java | 29 ++++---- .../module/cache/SubscriptionLoader.java | 5 +- .../interceptor/AnalyticsInterceptor.java | 20 +++--- .../rest/server/sched/IHapiScheduler.java | 2 +- 17 files changed, 116 insertions(+), 121 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImpl.java index 28eef3ca134..379f5877e2e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImpl.java @@ -78,7 +78,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class BulkDataExportSvcImpl implements IBulkDataExportSvc { - private static final long JOB_INTERVAL_MILLIS = 10 * DateUtils.MILLIS_PER_SECOND; private static final Logger ourLog = LoggerFactory.getLogger(BulkDataExportSvcImpl.class); private int myReuseBulkExportForMillis = (int) (60 * DateUtils.MILLIS_PER_MINUTE); @@ -311,13 +310,12 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { @PostConstruct public void start() { - ourLog.info("Bulk export service starting with refresh interval {}", StopWatch.formatMillis(JOB_INTERVAL_MILLIS)); myTxTemplate = new TransactionTemplate(myTxManager); ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(this.getClass().getName()); + jobDetail.setId(getClass().getName()); jobDetail.setJobClass(Job.class); - mySchedulerService.scheduleClusteredJob(JOB_INTERVAL_MILLIS, jobDetail); + mySchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseHapiScheduler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseHapiScheduler.java index aa52534d0d7..b08faf872aa 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseHapiScheduler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseHapiScheduler.java @@ -113,7 +113,7 @@ public abstract class BaseHapiScheduler implements IHapiScheduler { } @Override - public void scheduleFixedDelay(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { + public void scheduleJob(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { Validate.isTrue(theIntervalMillis >= 100); Validate.notNull(theJobDefinition); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java index 63890c79ef4..a96887bf93b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.model.api.ISmartLifecyclePhase; import ca.uhn.fhir.rest.server.sched.IHapiScheduler; import ca.uhn.fhir.rest.server.sched.ISchedulerService; import ca.uhn.fhir.rest.server.sched.ScheduledJobDefinition; +import ca.uhn.fhir.util.StopWatch; import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -173,12 +174,14 @@ public abstract class BaseSchedulerServiceImpl implements ISchedulerService, Sma @Override public void scheduleLocalJob(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { - myLocalScheduler.scheduleFixedDelay(theIntervalMillis, theJobDefinition); + ourLog.info("Scheduling local job {} with interval {}", theJobDefinition.getId(), StopWatch.formatMillis(theIntervalMillis)); + myLocalScheduler.scheduleJob(theIntervalMillis, theJobDefinition); } @Override public void scheduleClusteredJob(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { - myClusteredScheduler.scheduleFixedDelay(theIntervalMillis, theJobDefinition); + ourLog.info("Scheduling clustered job {} with interval {}", theJobDefinition.getId(), StopWatch.formatMillis(theIntervalMillis)); + myClusteredScheduler.scheduleJob(theIntervalMillis, theJobDefinition); } private boolean isSchedulingDisabledForUnitTests() { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/HapiNullScheduler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/HapiNullScheduler.java index 1a24907098b..672820e80d5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/HapiNullScheduler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/sched/HapiNullScheduler.java @@ -40,7 +40,7 @@ public class HapiNullScheduler implements IHapiScheduler { } @Override - public void scheduleFixedDelay(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { + public void scheduleJob(long theIntervalMillis, ScheduledJobDefinition theJobDefinition) { ourLog.debug("Skipping scheduling job {} since scheduling is disabled", theJobDefinition.getId()); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java index 344aa567cc2..72390b808f7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java @@ -21,10 +21,10 @@ package ca.uhn.fhir.jpa.search; */ import ca.uhn.fhir.jpa.dao.DaoConfig; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.search.cache.ISearchCacheSvc; import ca.uhn.fhir.rest.server.sched.ISchedulerService; import ca.uhn.fhir.rest.server.sched.ScheduledJobDefinition; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Propagation; @@ -58,13 +58,23 @@ public class StaleSearchDeletingSvcImpl implements IStaleSearchDeletingSvc { } @PostConstruct - public void registerScheduledJob() { + public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(StaleSearchDeletingSvcImpl.class.getName()); - jobDetail.setJobClass(StaleSearchDeletingSvcImpl.SubmitJob.class); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); mySchedulerService.scheduleClusteredJob(DEFAULT_CUTOFF_SLACK, jobDetail); } + public static class Job implements HapiJob { + @Autowired + private IStaleSearchDeletingSvc myTarget; + + @Override + public void execute(JobExecutionContext theContext) { + myTarget.schedulePollForStaleSearches(); + } + } + @Transactional(propagation = Propagation.NEVER) @Override public synchronized void schedulePollForStaleSearches() { @@ -72,14 +82,4 @@ public class StaleSearchDeletingSvcImpl implements IStaleSearchDeletingSvc { pollForStaleSearchesAndDeleteThem(); } } - - public static class SubmitJob implements Job { - @Autowired - private IStaleSearchDeletingSvc myTarget; - - @Override - public void execute(JobExecutionContext theContext) { - myTarget.schedulePollForStaleSearches(); - } - } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchCacheSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchCacheSvcImpl.java index 8498e2f2aa4..4716a8e9aad 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchCacheSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchCacheSvcImpl.java @@ -21,10 +21,10 @@ package ca.uhn.fhir.jpa.search.cache; */ import ca.uhn.fhir.jpa.entity.Search; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.rest.server.sched.ISchedulerService; import ca.uhn.fhir.rest.server.sched.ScheduledJobDefinition; import org.apache.commons.lang3.time.DateUtils; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.PlatformTransactionManager; @@ -51,10 +51,10 @@ public abstract class BaseSearchCacheSvcImpl implements ISearchCacheSvc { } @PostConstruct - public void registerScheduledJob() { + public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(BaseSearchCacheSvcImpl.class.getName()); - jobDetail.setJobClass(BaseSearchCacheSvcImpl.SubmitJob.class); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); mySchedulerService.scheduleLocalJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); } @@ -73,7 +73,7 @@ public abstract class BaseSearchCacheSvcImpl implements ISearchCacheSvc { protected abstract void flushLastUpdated(Long theSearchId, Date theLastUpdated); - public static class SubmitJob implements Job { + public static class Job implements HapiJob { @Autowired private ISearchCacheSvc myTarget; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImpl.java index 9f1dd642c34..98506cfae57 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImpl.java @@ -33,6 +33,7 @@ import ca.uhn.fhir.jpa.dao.data.IResourceTableDao; import ca.uhn.fhir.jpa.entity.ResourceReindexJobEntity; import ca.uhn.fhir.jpa.model.entity.ForcedId; import ca.uhn.fhir.jpa.model.entity.ResourceTable; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; @@ -46,7 +47,6 @@ import org.apache.commons.lang3.time.DateUtils; import org.hibernate.search.util.impl.Executors; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.InstantType; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,6 +146,7 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc { public void start() { myTxTemplate = new TransactionTemplate(myTxManager); initExecutor(); + scheduleJob(); } public void initExecutor() { @@ -160,6 +161,13 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc { ); } + public void scheduleJob() { + ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); + mySchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); + } + @Override @Transactional(Transactional.TxType.REQUIRED) public Long markAllResourcesForReindexing() { @@ -187,12 +195,14 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc { return job.getId(); } - @PostConstruct - public void registerScheduledJob() { - ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(ResourceReindexingSvcImpl.class.getName()); - jobDetail.setJobClass(ResourceReindexingSvcImpl.SubmitJob.class); - mySchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); + public static class Job implements HapiJob { + @Autowired + private IResourceReindexingSvc myTarget; + + @Override + public void execute(JobExecutionContext theContext) { + myTarget.runReindexingPass(); + } } @VisibleForTesting @@ -545,14 +555,4 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc { return myUpdated; } } - - public static class SubmitJob implements Job { - @Autowired - private IResourceReindexingSvc myTarget; - - @Override - public void execute(JobExecutionContext theContext) { - myTarget.runReindexingPass(); - } - } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/warm/CacheWarmingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/warm/CacheWarmingSvcImpl.java index 1be81f136b1..f5b42d451e3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/warm/CacheWarmingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/warm/CacheWarmingSvcImpl.java @@ -45,7 +45,6 @@ import java.util.*; @Component public class CacheWarmingSvcImpl implements ICacheWarmingSvc { - public static final long JOB_INTERVAL_MILLIS = 10 * DateUtils.MILLIS_PER_SECOND; private static final Logger ourLog = LoggerFactory.getLogger(CacheWarmingSvcImpl.class); @Autowired private DaoConfig myDaoConfig; @@ -108,9 +107,9 @@ public class CacheWarmingSvcImpl implements ICacheWarmingSvc { public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(this.getClass().getName()); + jobDetail.setId(getClass().getName()); jobDetail.setJobClass(Job.class); - mySchedulerService.scheduleClusteredJob(JOB_INTERVAL_MILLIS, jobDetail); + mySchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionTriggeringSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionTriggeringSvcImpl.java index a2b8195550b..7c77954356d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionTriggeringSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionTriggeringSvcImpl.java @@ -75,7 +75,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; @Service public class SubscriptionTriggeringSvcImpl implements ISubscriptionTriggeringSvc { - public static final long JOB_INTERVAL_MILLIS = DateUtils.MILLIS_PER_SECOND; private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionTriggeringProvider.class); private static final int DEFAULT_MAX_SUBMIT = 10000; private final List myActiveJobs = new ArrayList<>(); @@ -385,9 +384,9 @@ public class SubscriptionTriggeringSvcImpl implements ISubscriptionTriggeringSvc private void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(this.getClass().getName()); + jobDetail.setId(getClass().getName()); jobDetail.setJobClass(Job.class); - mySchedulerService.scheduleLocalJob(JOB_INTERVAL_MILLIS, jobDetail); + mySchedulerService.scheduleLocalJob(DateUtils.MILLIS_PER_SECOND, jobDetail); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java index c1571dbcc13..a9417069e3d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java @@ -30,6 +30,7 @@ import ca.uhn.fhir.jpa.entity.*; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId; import ca.uhn.fhir.jpa.model.entity.ResourceTable; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; @@ -69,7 +70,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -206,23 +206,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc, ApplicationCo return retVal; } - @PostConstruct - public void buildTranslationCaches() { - Long timeout = myDaoConfig.getTranslationCachesExpireAfterWriteInMinutes(); - - myTranslationCache = - Caffeine.newBuilder() - .maximumSize(10000) - .expireAfterWrite(timeout, TimeUnit.MINUTES) - .build(); - - myTranslationWithReverseCache = - Caffeine.newBuilder() - .maximumSize(10000) - .expireAfterWrite(timeout, TimeUnit.MINUTES) - .build(); - } - /** * This method is present only for unit tests, do not call from client code */ @@ -1300,18 +1283,46 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc, ApplicationCo RuleBasedTransactionAttribute rules = new RuleBasedTransactionAttribute(); rules.getRollbackRules().add(new NoRollbackRuleAttribute(ExpansionTooCostlyException.class)); myTxTemplate = new TransactionTemplate(myTransactionManager, rules); + buildTranslationCaches(); + scheduleJob(); } - @PostConstruct - public void registerScheduledJob() { + private void buildTranslationCaches() { + Long timeout = myDaoConfig.getTranslationCachesExpireAfterWriteInMinutes(); + + myTranslationCache = + Caffeine.newBuilder() + .maximumSize(10000) + .expireAfterWrite(timeout, TimeUnit.MINUTES) + .build(); + + myTranslationWithReverseCache = + Caffeine.newBuilder() + .maximumSize(10000) + .expireAfterWrite(timeout, TimeUnit.MINUTES) + .build(); + } + + public void scheduleJob() { + // FIXME KHS what does this mean? // Register scheduled job to pre-expand ValueSets // In the future it would be great to make this a cluster-aware task somehow ScheduledJobDefinition vsJobDefinition = new ScheduledJobDefinition(); - vsJobDefinition.setId(BaseTermReadSvcImpl.class.getName() + "_preExpandValueSets"); - vsJobDefinition.setJobClass(PreExpandValueSetsJob.class); + vsJobDefinition.setId(getClass().getName()); + vsJobDefinition.setJobClass(Job.class); mySchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_MINUTE, vsJobDefinition); } + public static class Job implements HapiJob { + @Autowired + private ITermReadSvc myTerminologySvc; + + @Override + public void execute(JobExecutionContext theContext) { + myTerminologySvc.preExpandDeferredValueSetsToTerminologyTables(); + } + } + @Override @Transactional public void storeTermConceptMapAndChildren(ResourceTable theResourceTable, ConceptMap theConceptMap) { @@ -1865,17 +1876,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc, ApplicationCo .findFirst(); } - public static class PreExpandValueSetsJob implements Job { - - @Autowired - private ITermReadSvc myTerminologySvc; - - @Override - public void execute(JobExecutionContext theContext) { - myTerminologySvc.preExpandDeferredValueSetsToTerminologyTables(); - } - } - static List toPersistedConcepts(List theConcept, TermCodeSystemVersion theCodeSystemVersion) { ArrayList retVal = new ArrayList<>(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java index d2bfe93a0d8..ccda37d2a51 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java @@ -53,7 +53,6 @@ import java.util.List; public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc { - private static final int JOB_INTERVAL_MILLIS = 5000; private static final Logger ourLog = LoggerFactory.getLogger(TermDeferredStorageSvcImpl.class); @Autowired protected ITermConceptDao myConceptDao; @@ -267,7 +266,7 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc { ScheduledJobDefinition jobDefinition = new ScheduledJobDefinition(); jobDefinition.setId(this.getClass().getName()); jobDefinition.setJobClass(Job.class); - mySchedulerService.scheduleLocalJob(JOB_INTERVAL_MILLIS, jobDefinition); + mySchedulerService.scheduleLocalJob(5000, jobDefinition); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermReindexingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermReindexingSvcImpl.java index 3b9ab65bb8f..01746cd0b0c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermReindexingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermReindexingSvcImpl.java @@ -54,7 +54,6 @@ import static org.apache.commons.lang3.StringUtils.isBlank; public class TermReindexingSvcImpl implements ITermReindexingSvc { private static final Logger ourLog = LoggerFactory.getLogger(TermReindexingSvcImpl.class); - private static final long JOB_INTERVAL_MILLIS = DateUtils.MILLIS_PER_MINUTE; private static boolean ourForceSaveDeferredAlwaysForUnitTest; @Autowired protected ITermConceptDao myConceptDao; @@ -157,7 +156,7 @@ public class TermReindexingSvcImpl implements ITermReindexingSvc { ScheduledJobDefinition jobDefinition = new ScheduledJobDefinition(); jobDefinition.setId(this.getClass().getName()); jobDefinition.setJobClass(Job.class); - mySchedulerService.scheduleLocalJob(JOB_INTERVAL_MILLIS, jobDefinition); + mySchedulerService.scheduleLocalJob(DateUtils.MILLIS_PER_MINUTE, jobDefinition); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ResourceCountCache.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ResourceCountCache.java index cdda4d28c50..27ef82db650 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ResourceCountCache.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ResourceCountCache.java @@ -20,12 +20,12 @@ package ca.uhn.fhir.jpa.util; * #L% */ +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.sched.ISchedulerService; import ca.uhn.fhir.rest.server.sched.ScheduledJobDefinition; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.time.DateUtils; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,14 +92,14 @@ public class ResourceCountCache { } @PostConstruct - public void registerScheduledJob() { + public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(ResourceCountCache.class.getName()); - jobDetail.setJobClass(ResourceCountCache.SubmitJob.class); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); mySchedulerService.scheduleLocalJob(10 * DateUtils.MILLIS_PER_MINUTE, jobDetail); } - public static class SubmitJob implements Job { + public static class Job implements HapiJob { @Autowired private ResourceCountCache myTarget; diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImpl.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImpl.java index 88ce3f0ef8a..8926a84495f 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImpl.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImpl.java @@ -27,6 +27,7 @@ import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.model.entity.ModelConfig; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage; import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam; import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; @@ -49,7 +50,6 @@ import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.SearchParameter; import org.hl7.fhir.instance.model.api.*; import org.hl7.fhir.r4.model.Reference; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -724,13 +724,23 @@ public class SearchParamRegistryImpl implements ISearchParamRegistry { } @PostConstruct - public void registerScheduledJob() { + public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(SearchParamRegistryImpl.class.getName()); - jobDetail.setJobClass(SubmitJob.class); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); mySchedulerService.scheduleLocalJob(10 * DateUtils.MILLIS_PER_SECOND, jobDetail); } + public static class Job implements HapiJob { + @Autowired + private ISearchParamRegistry myTarget; + + @Override + public void execute(JobExecutionContext theContext) { + myTarget.refreshCacheIfNecessary(); + } + } + @Override public boolean refreshCacheIfNecessary() { if (myActiveSearchParams == null || System.currentTimeMillis() - REFRESH_INTERVAL > myLastRefresh) { @@ -767,17 +777,6 @@ public class SearchParamRegistryImpl implements ISearchParamRegistry { } } - - public static class SubmitJob implements Job { - @Autowired - private ISearchParamRegistry myTarget; - - @Override - public void execute(JobExecutionContext theContext) { - myTarget.refreshCacheIfNecessary(); - } - } - public static Map> createBuiltInSearchParamMap(FhirContext theFhirContext) { Map> resourceNameToSearchParams = new HashMap<>(); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoader.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoader.java index 6456d2d6e5b..1b3144a91f4 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoader.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoader.java @@ -50,7 +50,6 @@ import java.util.concurrent.Semaphore; @Service @Lazy public class SubscriptionLoader { - public static final long JOB_INTERVAL_MILLIS = DateUtils.MILLIS_PER_MINUTE; private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionLoader.class); private static final int MAX_RETRIES = 60; // 60 * 5 seconds = 5 minutes private final Object mySyncSubscriptionsLock = new Object(); @@ -90,9 +89,9 @@ public class SubscriptionLoader { @PostConstruct public void scheduleJob() { ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(this.getClass().getName()); + jobDetail.setId(getClass().getName()); jobDetail.setJobClass(Job.class); - mySchedulerService.scheduleLocalJob(JOB_INTERVAL_MILLIS, jobDetail); + mySchedulerService.scheduleLocalJob(DateUtils.MILLIS_PER_MINUTE, jobDetail); } public static class Job implements HapiJob { diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/interceptor/AnalyticsInterceptor.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/interceptor/AnalyticsInterceptor.java index 6d6a5a699c6..ca950f33160 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/interceptor/AnalyticsInterceptor.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/interceptor/AnalyticsInterceptor.java @@ -1,5 +1,6 @@ package ca.uhn.fhirtest.interceptor; +import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; @@ -13,7 +14,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; -import org.quartz.Job; import org.quartz.JobExecutionContext; import org.springframework.beans.factory.annotation.Autowired; @@ -55,7 +55,15 @@ public class AnalyticsInterceptor extends InterceptorAdapter { } } - public static class SubmitJob implements Job { + @PostConstruct + public void start() { + ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); + jobDetail.setId(getClass().getName()); + jobDetail.setJobClass(Job.class); + mySchedulerService.scheduleLocalJob(5000, jobDetail); + } + + public static class Job implements HapiJob { @Autowired private AnalyticsInterceptor myAnalyticsInterceptor; @@ -65,14 +73,6 @@ public class AnalyticsInterceptor extends InterceptorAdapter { } } - @PostConstruct - public void start() { - ScheduledJobDefinition jobDetail = new ScheduledJobDefinition(); - jobDetail.setId(getClass().getName()); - jobDetail.setJobClass(SubmitJob.class); - mySchedulerService.scheduleLocalJob(5000, jobDetail); - } - @PreDestroy public void stop() throws IOException { if (myHttpClient instanceof CloseableHttpClient) { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/sched/IHapiScheduler.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/sched/IHapiScheduler.java index 6c40bd0b3fe..6caca26282e 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/sched/IHapiScheduler.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/sched/IHapiScheduler.java @@ -15,5 +15,5 @@ public interface IHapiScheduler { void logStatusForUnitTest(); - void scheduleFixedDelay(long theIntervalMillis, ScheduledJobDefinition theJobDefinition); + void scheduleJob(long theIntervalMillis, ScheduledJobDefinition theJobDefinition); }