001/*- 002 * #%L 003 * HAPI FHIR Subscription Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.subscription.match.registry; 021 022import ca.uhn.fhir.jpa.subscription.match.matcher.subscriber.SubscriptionCriteriaParser; 023import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; 024import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; 025import ca.uhn.fhir.jpa.subscription.model.ChannelRetryConfiguration; 026 027import java.util.concurrent.atomic.AtomicLong; 028 029public class ActiveSubscription { 030 031 private SubscriptionCriteriaParser.SubscriptionCriteria myCriteria; 032 033 private final String myChannelName; 034 private final String myId; 035 private CanonicalSubscription mySubscription; 036 private boolean flagForDeletion; 037 038 private ChannelRetryConfiguration myRetryConfigurationParameters; 039 private final AtomicLong myDeliveriesCount = new AtomicLong(); 040 041 public ActiveSubscription(CanonicalSubscription theSubscription, String theChannelName) { 042 myChannelName = theChannelName; 043 myId = theSubscription.getIdPart(); 044 setSubscription(theSubscription); 045 } 046 047 public SubscriptionCriteriaParser.SubscriptionCriteria getCriteria() { 048 return myCriteria; 049 } 050 051 public CanonicalSubscription getSubscription() { 052 return mySubscription; 053 } 054 055 public final void setSubscription(CanonicalSubscription theSubscription) { 056 mySubscription = theSubscription; 057 myCriteria = SubscriptionCriteriaParser.parse(theSubscription.getCriteriaString()); 058 } 059 060 public String getChannelName() { 061 return myChannelName; 062 } 063 064 public boolean isFlagForDeletion() { 065 return flagForDeletion; 066 } 067 068 public void setFlagForDeletion(boolean theFlagForDeletion) { 069 flagForDeletion = theFlagForDeletion; 070 } 071 072 public String getId() { 073 return myId; 074 } 075 076 public CanonicalSubscriptionChannelType getChannelType() { 077 return mySubscription.getChannelType(); 078 } 079 080 public void setRetryConfiguration(ChannelRetryConfiguration theParams) { 081 myRetryConfigurationParameters = theParams; 082 } 083 084 public ChannelRetryConfiguration getRetryConfigurationParameters() { 085 return myRetryConfigurationParameters; 086 } 087 088 public long getDeliveriesCount() { 089 return myDeliveriesCount.get(); 090 } 091 092 public long incrementDeliveriesCount() { 093 return myDeliveriesCount.incrementAndGet(); 094 } 095}