Class ResourceRegistry<T>

  • All Implemented Interfaces:
    ResourceHolder

    public class ResourceRegistry<T>
    extends java.lang.Object
    implements ResourceHolder
    ResourceRegistry keeps track of resources that have been loaded and are in the process of being loaded. The registry maintains only weak references and doesn't prevent resources from being collected.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroyAllResources()
      Removes all cache entries.
      java.util.concurrent.CompletableFuture<T> get​(java.lang.Object id)
      Returns a future to a resource previously registered with the same id.
      long reclaimReleasedResources()
      Polls for garbage collected objects and disposes associated data.
      void register​(java.lang.Object id, java.util.concurrent.CompletableFuture<T> futureResource)
      Registers a future to a resource by an id.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceRegistry

        public ResourceRegistry()
    • Method Detail

      • get

        @Nullable
        public java.util.concurrent.CompletableFuture<T> get​(java.lang.Object id)
        Returns a future to a resource previously registered with the same id. If resource has not yet been registered or was garbage collected, returns null. The future may be to a resource that has already finished loading, in which case CompletableFuture.isDone() will be true.
      • register

        public void register​(java.lang.Object id,
                             java.util.concurrent.CompletableFuture<T> futureResource)
        Registers a future to a resource by an id. If registering a resource that has already finished loading, use CompletableFuture.completedFuture(Object).
      • destroyAllResources

        public void destroyAllResources()
        Removes all cache entries. Cancels any in progress futures. cancel does not interrupt work in progress. It only prevents the final stage from starting.
        Specified by:
        destroyAllResources in interface ResourceHolder
      • reclaimReleasedResources

        public long reclaimReleasedResources()
        Description copied from interface: ResourceHolder
        Polls for garbage collected objects and disposes associated data.
        Specified by:
        reclaimReleasedResources in interface ResourceHolder
        Returns:
        Count of resources in use.