Class ResourceRegistry<T>
- java.lang.Object
-
- com.google.ar.sceneform.resources.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.
-
-
Constructor Summary
Constructors Constructor Description ResourceRegistry()
-
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.
-
-
-
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 caseCompletableFuture.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, useCompletableFuture.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 interfaceResourceHolder
-
reclaimReleasedResources
public long reclaimReleasedResources()
Description copied from interface:ResourceHolder
Polls for garbage collected objects and disposes associated data.- Specified by:
reclaimReleasedResources
in interfaceResourceHolder
- Returns:
- Count of resources in use.
-
-