Add synchronization to SP registry

This commit is contained in:
James 2017-04-24 07:40:53 -04:00
parent 091fd18c00
commit f21ab8bfe6
1 changed files with 71 additions and 65 deletions

View File

@ -56,15 +56,17 @@ public class SearchParamRegistryDstu3 extends BaseSearchParamRegistry {
@Autowired @Autowired
private DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
private long myLastRefresh; private volatile long myLastRefresh;
@Autowired @Autowired
private IFhirResourceDao<SearchParameter> mySpDao; private IFhirResourceDao<SearchParameter> mySpDao;
@Override @Override
public void forceRefresh() { public void forceRefresh() {
synchronized (this) {
myLastRefresh = 0; myLastRefresh = 0;
} }
}
@Override @Override
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() { public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
@ -89,6 +91,8 @@ public class SearchParamRegistryDstu3 extends BaseSearchParamRegistry {
private void refreshCacheIfNeccesary() { private void refreshCacheIfNeccesary() {
long refreshInterval = 60 * DateUtils.MILLIS_PER_MINUTE; long refreshInterval = 60 * DateUtils.MILLIS_PER_MINUTE;
if (System.currentTimeMillis() - refreshInterval > myLastRefresh) {
synchronized (this) {
if (System.currentTimeMillis() - refreshInterval > myLastRefresh) { if (System.currentTimeMillis() - refreshInterval > myLastRefresh) {
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
@ -163,6 +167,8 @@ public class SearchParamRegistryDstu3 extends BaseSearchParamRegistry {
ourLog.info("Refreshed search parameter cache in {}ms", sw.getMillis()); ourLog.info("Refreshed search parameter cache in {}ms", sw.getMillis());
} }
} }
}
}
private RuntimeSearchParam toRuntimeSp(SearchParameter theNextSp) { private RuntimeSearchParam toRuntimeSp(SearchParameter theNextSp) {
String name = theNextSp.getCode(); String name = theNextSp.getCode();