@Override public boolean loadSubscription(IBaseResource theResource) { return mySubscriptionRegistry.registerSubscriptionUnlessAlreadyRegistered(theResource); } }
public boolean unregisterSubscriptionIfRegistered(IBaseResource theSubscription, String theStatusString) { if (hasSubscription(theSubscription.getIdElement()).isPresent()) { ourLog.info("Removing {} subscription {}", theStatusString, theSubscription.getIdElement().toUnqualified().getValue()); unregisterSubscription(theSubscription.getIdElement()); return true; } return false; }
private void loadSubscriptions() { ourLog.info("Loading subscriptions into the SubscriptionRegistry..."); // Activate scheduled subscription loads into the SubscriptionRegistry myAppicationContext.getBean(SubscriptionLoader.class); ourLog.info("...{} subscriptions loaded", mySubscriptionRegistry.size()); }
public synchronized boolean registerSubscriptionUnlessAlreadyRegistered(IBaseResource theSubscription) { Optional<CanonicalSubscription> existingSubscription = hasSubscription(theSubscription.getIdElement()); CanonicalSubscription newSubscription = mySubscriptionCanonicalizer.canonicalize(theSubscription); if (existingSubscription.isPresent()) { if (newSubscription.equals(existingSubscription.get())) { // No changes return false; } ourLog.info("Updating already-registered active subscription {}", theSubscription.getIdElement().toUnqualified().getValue()); unregisterSubscription(theSubscription.getIdElement()); } else { ourLog.info("Registering active subscription {}", theSubscription.getIdElement().toUnqualified().getValue()); } if (Subscription.SubscriptionStatus.ACTIVE.equals(newSubscription.getStatus())) { registerSubscription(theSubscription.getIdElement(), theSubscription); return true; } else { return false; } }
return mySubscriptionRegistry.registerSubscriptionUnlessAlreadyRegistered(theSubscription); } else { return mySubscriptionRegistry.unregisterSubscriptionIfRegistered(theSubscription, statusString);
private void submitResourceModified(final ResourceModifiedMessage theMsg) { switch (theMsg.getOperationType()) { case DELETE: mySubscriptionRegistry.unregisterSubscription(theMsg.getId(myFhirContext)); break; case CREATE: case UPDATE: activateAndRegisterSubscriptionIfRequiredInTransaction(theMsg.getNewPayload(myFhirContext)); break; default: break; } }
@PreDestroy public void preDestroy() { unregisterAllSubscriptionsNotInCollection(Collections.emptyList()); }
@Override public void handleMessage(Message theMessage) throws MessagingException { if (!(theMessage.getPayload() instanceof ResourceDeliveryMessage)) { ourLog.warn("Unexpected payload type: {}", theMessage.getPayload()); return; } String subscriptionId = "(unknown?)"; try { ResourceDeliveryMessage msg = (ResourceDeliveryMessage) theMessage.getPayload(); subscriptionId = msg.getSubscription().getIdElement(myFhirContext).getValue(); ActiveSubscription updatedSubscription = mySubscriptionRegistry.get(msg.getSubscription().getIdElement(myFhirContext).getIdPart()); if (updatedSubscription != null) { msg.setSubscription(updatedSubscription.getSubscription()); } handleMessage(msg); } catch (Exception e) { String msg = "Failure handling subscription payload for subscription: " + subscriptionId; ourLog.error(msg, e); throw new MessagingException(theMessage, msg, e); } }
Collection<ActiveSubscription> subscriptions = mySubscriptionRegistry.getAll();
return mySubscriptionRegistry.registerSubscriptionUnlessAlreadyRegistered(theSubscription); } else { return mySubscriptionRegistry.unregisterSubscriptionIfRegistered(theSubscription, statusString);
private void submitResourceModified(final ResourceModifiedMessage theMsg) { switch (theMsg.getOperationType()) { case DELETE: mySubscriptionRegistry.unregisterSubscription(theMsg.getId(myFhirContext)); break; case CREATE: case UPDATE: activateAndRegisterSubscriptionIfRequiredInTransaction(theMsg.getNewPayload(myFhirContext)); break; default: break; } }
private int doSyncSubscriptions() { synchronized (mySyncSubscriptionsLock) { ourLog.debug("Starting sync subscriptions"); SearchParameterMap map = new SearchParameterMap(); map.add(Subscription.SP_STATUS, new TokenOrListParam() // TODO KHS perhaps we should only be requesting ACTIVE subscriptions here?... .addOr(new TokenParam(null, Subscription.SubscriptionStatus.REQUESTED.toCode())) .addOr(new TokenParam(null, Subscription.SubscriptionStatus.ACTIVE.toCode()))); map.setLoadSynchronousUpTo(SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS); IBundleProvider subscriptionBundleList = mySubscriptionProvidor.search(map); if (subscriptionBundleList.size() >= SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS) { ourLog.error("Currently over " + SubscriptionConstants.MAX_SUBSCRIPTION_RESULTS + " subscriptions. Some subscriptions have not been loaded."); } List<IBaseResource> resourceList = subscriptionBundleList.getResources(0, subscriptionBundleList.size()); Set<String> allIds = new HashSet<>(); int changesCount = 0; for (IBaseResource resource : resourceList) { String nextId = resource.getIdElement().getIdPart(); allIds.add(nextId); boolean changed = mySubscriptionProvidor.loadSubscription(resource); if (changed) { changesCount++; } } mySubscriptionRegistry.unregisterAllSubscriptionsNotInCollection(allIds); ourLog.debug("Finished sync subscriptions - found {}", resourceList.size()); return changesCount; } }
private IIdType bindSimple(WebSocketSession theSession, String theBindString) { IdType id = new IdType(theBindString); if (!id.hasIdPart() || !id.isIdPartValid()) { try { String message = "Invalid bind request - No ID included"; ourLog.warn(message); theSession.close(new CloseStatus(CloseStatus.PROTOCOL_ERROR.getCode(), message)); } catch (IOException e) { handleFailure(e); } return null; } if (id.hasResourceType() == false) { id = id.withResourceType("Subscription"); } try { ActiveSubscription activeSubscription = mySubscriptionRegistry.get(id.getIdPart()); myState = new BoundStaticSubscipriptionState( theSession, activeSubscription); } catch (ResourceNotFoundException e) { try { String message = "Invalid bind request - Unknown subscription: " + id.getValue(); ourLog.warn(message); theSession.close(new CloseStatus(CloseStatus.PROTOCOL_ERROR.getCode(), message)); } catch (IOException e1) { handleFailure(e); } return null; } return id; }
public void updateSubscriptionRegistryAndPerformMatching(ResourceModifiedMessage theResourceModifiedMessage) { IBaseResource resource = theResourceModifiedMessage.getNewPayload(myFhirContext); RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(resource); if (resourceDef.getName().equals(ResourceTypeEnum.SUBSCRIPTION.getCode())) { mySubscriptionRegistry.registerSubscriptionUnlessAlreadyRegistered(resource); } mySubscriptionMatchingSubscriber.matchActiveSubscriptionsAndDeliver(theResourceModifiedMessage); } }
private void loadSubscriptions() { ourLog.info("Loading subscriptions into the SubscriptionRegistry..."); // Activate scheduled subscription loads into the SubscriptionRegistry myAppicationContext.getBean(SubscriptionLoader.class); ourLog.info("...{} subscriptions loaded", mySubscriptionRegistry.size()); }