This commit is contained in:
Ken Stevens 2019-10-01 10:52:00 -04:00
parent ade9e0316e
commit ca95791d2e
2 changed files with 20 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionLoader;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry;
import ca.uhn.fhir.jpa.subscription.module.channel.SubscriptionChannelRegistry;
import com.google.common.annotations.VisibleForTesting;
import org.hl7.fhir.dstu2.model.Subscription;
import org.slf4j.Logger;
@ -47,6 +48,8 @@ public class SubscriptionInterceptorLoader {
@Autowired
private SubscriptionRegistry mySubscriptionRegistry;
@Autowired
private SubscriptionChannelRegistry mySubscriptionChannelRegistry;
@Autowired
private ApplicationContext myApplicationContext;
@Autowired
private IInterceptorService myInterceptorRegistry;
@ -69,8 +72,10 @@ public class SubscriptionInterceptorLoader {
private void loadSubscriptions() {
ourLog.info("Loading subscriptions into the SubscriptionRegistry...");
// Activate scheduled subscription loads into the SubscriptionRegistry
myApplicationContext.getBean(SubscriptionLoader.class);
SubscriptionLoader loader = myApplicationContext.getBean(SubscriptionLoader.class);
loader.syncSubscriptions();
ourLog.info("...{} subscriptions loaded", mySubscriptionRegistry.size());
ourLog.info("...{} subscription channels started", mySubscriptionChannelRegistry.size());
}
@VisibleForTesting

View File

@ -1,9 +1,9 @@
package ca.uhn.fhir.jpa.subscription.module.channel;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import org.slf4j.Logger;
@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageHandler;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Optional;
@Component
@ -58,7 +59,7 @@ public class SubscriptionChannelRegistry {
String channelName = theActiveSubscription.getChannelName();
boolean removed = myActiveSubscriptionByChannelName.remove(channelName, theActiveSubscription.getId());
if (!removed) {
ourLog.warn("Request to remove subscription {} that was not added", theActiveSubscription.getId());
ourLog.warn("Failed to remove subscription {} from channel {}", theActiveSubscription.getId() ,channelName);
}
// This was the last one. Shut down the channel
@ -78,4 +79,15 @@ public class SubscriptionChannelRegistry {
public int size() {
return mySubscriptionChannelCache.size();
}
@VisibleForTesting
public void logForUnitTest() {
ourLog.info("Channels: {}", size());
for (String key : myActiveSubscriptionByChannelName.keySet()) {
Collection<String> list = myActiveSubscriptionByChannelName.get(key);
for (String value : list) {
ourLog.info("{}: {}", key, value);
}
}
}
}