null check

This commit is contained in:
Ken Stevens 2019-09-30 17:15:35 -04:00
parent 6196f528d9
commit 6867a57625
3 changed files with 19 additions and 4 deletions

View File

@ -233,7 +233,7 @@ public class SubscriptionActivatingInterceptor {
private void submitResourceModified(final ResourceModifiedMessage theMsg) { private void submitResourceModified(final ResourceModifiedMessage theMsg) {
switch (theMsg.getOperationType()) { switch (theMsg.getOperationType()) {
case DELETE: case DELETE:
mySubscriptionRegistry.unregisterSubscription(theMsg.getId(myFhirContext)); mySubscriptionRegistry.unregisterSubscription(theMsg.getId(myFhirContext).getIdPart());
break; break;
case CREATE: case CREATE:
case UPDATE: case UPDATE:

View File

@ -30,6 +30,8 @@ import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Subscription; import org.hl7.fhir.r4.model.Subscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -48,7 +50,7 @@ import java.util.Optional;
// TODO KHS Does jpa need a subscription registry if matching is disabled? // TODO KHS Does jpa need a subscription registry if matching is disabled?
@Component @Component
public class SubscriptionRegistry { public class SubscriptionRegistry {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionRegistry.class); private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionRegistry.class);
private final ActiveSubscriptionCache myActiveSubscriptionCache = new ActiveSubscriptionCache(); private final ActiveSubscriptionCache myActiveSubscriptionCache = new ActiveSubscriptionCache();
@Autowired @Autowired
SubscriptionCanonicalizer<IBaseResource> mySubscriptionCanonicalizer; SubscriptionCanonicalizer<IBaseResource> mySubscriptionCanonicalizer;

View File

@ -1,9 +1,13 @@
package ca.uhn.fhir.jpa.subscription.module.channel; 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.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionRegistry;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder; import com.google.common.collect.MultimapBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -12,6 +16,8 @@ import java.util.Optional;
@Component @Component
public class SubscriptionChannelRegistry { public class SubscriptionChannelRegistry {
private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionRegistry.class);
private final SubscriptionChannelCache mySubscriptionChannelCache = new SubscriptionChannelCache(); private final SubscriptionChannelCache mySubscriptionChannelCache = new SubscriptionChannelCache();
// This map is a reference count so we know to destroy the channel when there are no more active subscriptions using it // This map is a reference count so we know to destroy the channel when there are no more active subscriptions using it
private final Multimap<String, ActiveSubscription> myActiveSubscriptionByChannelName = MultimapBuilder.hashKeys().arrayListValues().build(); private final Multimap<String, ActiveSubscription> myActiveSubscriptionByChannelName = MultimapBuilder.hashKeys().arrayListValues().build();
@ -22,6 +28,8 @@ public class SubscriptionChannelRegistry {
SubscriptionChannelFactory mySubscriptionDeliveryChannelFactory; SubscriptionChannelFactory mySubscriptionDeliveryChannelFactory;
@Autowired @Autowired
ModelConfig myModelConfig; ModelConfig myModelConfig;
@Autowired
FhirContext myFhirContext;
public void add(ActiveSubscription theActiveSubscription) { public void add(ActiveSubscription theActiveSubscription) {
if (!myModelConfig.isSubscriptionMatchingEnabled()) { if (!myModelConfig.isSubscriptionMatchingEnabled()) {
@ -47,12 +55,17 @@ public class SubscriptionChannelRegistry {
public void remove(ActiveSubscription theActiveSubscription) { public void remove(ActiveSubscription theActiveSubscription) {
String channelName = theActiveSubscription.getChannelName(); String channelName = theActiveSubscription.getChannelName();
myActiveSubscriptionByChannelName.remove(channelName, theActiveSubscription); boolean removed = myActiveSubscriptionByChannelName.remove(channelName, theActiveSubscription);
if (!removed) {
ourLog.warn("Removing unregistered subscription {}", theActiveSubscription.getIdElement(myFhirContext).getIdPart());
}
// This was the last one. Shut down the channel // This was the last one. Shut down the channel
if (!myActiveSubscriptionByChannelName.containsKey(channelName)) { if (!myActiveSubscriptionByChannelName.containsKey(channelName)) {
SubscriptionChannelWithHandlers channel = mySubscriptionChannelCache.get(channelName); SubscriptionChannelWithHandlers channel = mySubscriptionChannelCache.get(channelName);
channel.close(); if (channel != null) {
channel.close();
}
mySubscriptionChannelCache.remove(channelName); mySubscriptionChannelCache.remove(channelName);
} }
} }