001/*-
002 * #%L
003 * HAPI FHIR JPA - Search Parameters
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.cache;
021
022import org.springframework.context.event.ContextClosedEvent;
023import org.springframework.context.event.ContextRefreshedEvent;
024import org.springframework.context.event.EventListener;
025
026/**
027 * This is an internal service and is not intended to be used outside this package.  Implementers should only directly
028 * call the {@link IResourceChangeListenerRegistry}.
029 *
030 * This service refreshes a {@link ResourceChangeListenerCache} cache and notifies its listener when
031 * the cache changes.
032 */
033public interface IResourceChangeListenerCacheRefresher {
034        /**
035         * If the current time is past the next refresh time of the registered listener, then check if any of its
036         * resources have changed and notify the listener accordingly
037         * @return an aggregate of all changes sent to all listeners
038         */
039        ResourceChangeResult refreshExpiredCachesAndNotifyListeners();
040
041        /**
042         * Refresh the cache in this entry and notify the entry's listener if the cache changed
043         * @param theEntry the {@link IResourceChangeListenerCache} with the cache and the listener
044         * @return the number of resources that have been created, updated and deleted since the last time the cache was refreshed
045         */
046        ResourceChangeResult refreshCacheAndNotifyListener(IResourceChangeListenerCache theEntry);
047
048        @EventListener(ContextRefreshedEvent.class)
049        public void start();
050
051        @EventListener(ContextClosedEvent.class)
052        public void shutdown();
053}