Class ObservableSupplierSet<T extends IObservableSupplierSetObserver>

java.lang.Object
ca.uhn.fhir.rest.server.provider.ObservableSupplierSet<T>
Type Parameters:
T - the class of the Observer

A typical usage pattern would be:

  1. Create ObservableSupplierSet in exporter context.
  2. Add all the suppliers in the exporter context.
  3. Attach the importer to the ObservableSupplierSet
  4. Importer calls getSupplierResults() and processes all the beans
  5. Some other service beans may add more suppliers later as a part of their initialization and the observer handlers will process them accordingly
  6. Those other service beans should call removeSupplier(Supplier) in a @PreDestroy method so they are properly cleaned up if those services are shut down or restarted
Direct Known Subclasses:
ResourceProviderFactory

This is a generic implementation of the Observer Design Pattern. We use this to pass sets of beans from exporting Spring application contexts to importing Spring application contexts. We defer resolving the observed beans via a Supplier to give the exporting context a chance to initialize the beans before they are used.
  • Constructor Details

  • Method Details

    • addSupplier

      public void addSupplier(@Nonnull Supplier<Object> theSupplier)
      Add a supplier and notify all observers
      Parameters:
      theSupplier - supplies the object to be observed
    • removeSupplier

      public void removeSupplier(@Nonnull Supplier<Object> theSupplier)
      Remove a supplier and notify all observers. CAUTION, you might think that this code would work, but it does not: observableSupplierSet.addSupplier(() -> myBean); ... observableSupplierSet.removeSupplier(() -> myBean); the removeSupplier in this example would fail because it is a different lambda instance from the first. Instead, you need to store the supplier between the add and remove: mySupplier = () -> myBean; observableSupplierSet.addSupplier(mySupplier); ... observableSupplierSet.removeSupplier(mySupplier);
      Parameters:
      theSupplier - the supplier to be removed
    • attach

      public void attach(T theObserver)
      Attach an observer to this observableSupplierSet. This observer will be notified every time a supplier is added or removed.
      Parameters:
      theObserver - the observer to be notified
    • detach

      public void detach(T theObserver)
      Detach an observer from this observableSupplierSet, so it is no longer notified when suppliers are added and removed.
      Parameters:
      theObserver - the observer to be removed
    • getSupplierResults

      Returns:
      a list of get() being called on all suppliers.