Kanzi 3.9.10
ResourceManager Class Reference

The resource manager maintains kzb files and provides mechanisms to load resources from kzb files. More...

Classes

class  AcquireTask
 Load task for a group of resources. More...
 
class  LoadTask
 Load task allows implementing custom asynchronous resource loading. More...
 
interface  ProtocolHandler
 ProtocolHandler allows implementing custom resource loading for a specific protocol. More...
 
interface  ReloadProtocolHandler
 ReloadProtocolHandler allows implementing custom resource reloading for a specific protocol. More...
 
class  ResourceUsage
 

Public Member Functions

ObjectRef< TResourceTypeacquireLoadedResource (String url)
 Acquires a resource associated with the given URL.
 
ObjectRef< TResourceTypeacquireResource (String url) throws ObjectNotFoundException
 Acquires a resource associated with the given URL.
 
AcquireTask acquireResourcesAsync (String[] urls, AcquireTask.Callback callback)
 Creates a background task that loads and deploys all resources from a set of URLs.
 
void addKzbFile (String fileName) throws FileNotFoundException
 Opens a kzb file from the file system and adds it to the list of files.
 
void collectAndAcquirePrefabAsync (Node node, String id, AcquireTask.Callback callback)
 Creates a background task that collects all resources within a prefab and loads them asynchronously.
 
MemoryStrategy getDefaultMemoryStrategy ()
 Gets the memory release strategy.
 
Domain getDomain ()
 Returns the domain associated with the resource manager.
 
ResourceUsage getResourceUsage ()
 
void purge ()
 Deletes unreferenced resources.
 
void registerProtocolHandler (String protocol, ProtocolHandler loadHandler)
 Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).
 
void registerProtocolHandler (String protocol, ProtocolHandler loadHandler, ReloadProtocolHandler reloadHandler)
 Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).
 
void setDefaultMemoryStrategy (MemoryStrategy strategy)
 Sets the memory release strategy for new resources.
 
boolean supportsProtocolHandler (String protocol)
 Checks whether the given resource URL protocol (scheme name) is registered as a protocol handler for the resource manager.
 
ObjectRef< TResourceTypetryAcquireResource (String url)
 Acquires a resource associated with the given URL, like com.rightware.kanzi.ResourceManager#acquireResource, but does not throw exceptions on failure.
 
void unregisterProtocolHandler (String protocol)
 Unregisters the protocol handler with the given resource URL protocol (scheme name).
 
void unregisterResource (String url)
 Removes the association of the given URL to a resource or a load task.
 
void wait (AcquireTask acquireTask)
 Blocks the execution until the async acquire task finishes and calls the callback of the task (unless it has been called already).
 

Detailed Description

The resource manager maintains kzb files and provides mechanisms to load resources from kzb files.

Member Function Documentation

◆ acquireLoadedResource()

ObjectRef< TResourceType > acquireLoadedResource ( String url)

Acquires a resource associated with the given URL.

If no resource is associated with the URL, does not try to load the resource.

Parameters
urlURL of the resource.
Returns
The resource that was loaded with the given URL. Null if no resource was loaded with the given URL.

◆ acquireResource()

ObjectRef< TResourceType > acquireResource ( String url) throws ObjectNotFoundException

Acquires a resource associated with the given URL.

If no resource is associated with the URL, tries to load the resource from the location specified by the URL. The URL specifies the location with a protocol and a protocol-specific path. If you already earlier acquired the resource at the given URL, this function returns a shared pointer to the already acquired resource.

Parameters
urlURL of the resource.
Returns
Resource that was loaded.
Exceptions
ObjectNotFoundExceptionThrows a ObjectNotFoundException when the url is not found.

◆ acquireResourcesAsync()

AcquireTask acquireResourcesAsync ( String[] urls,
AcquireTask.Callback callback )

Creates a background task that loads and deploys all resources from a set of URLs.

After Kanzi loads and deploys the resource, the function calls the callback you provide.

Parameters
urlsArray of resource URLs.
callbackCallback function that this function calls when resource loading is completed.
Returns
Handle to the async load task. You can pass the handle to com.rightware.kanzi.ResourceManager#wait(AcquireTask) to wait for the completion of the load.

◆ addKzbFile()

void addKzbFile ( String fileName) throws FileNotFoundException

Opens a kzb file from the file system and adds it to the list of files.

This function adds a new version of the file, even when the file is already loaded.

Parameters
fileNameThe name of the file to open.
Exceptions
InvalidKzbFileExceptionThrows an InvalidKzbFileException when the KZB file is invalid.
FileNotFoundExceptionThrows a FileNotFoundException when the KZB file is not found.

◆ collectAndAcquirePrefabAsync()

void collectAndAcquirePrefabAsync ( Node node,
String id,
AcquireTask.Callback callback )

Creates a background task that collects all resources within a prefab and loads them asynchronously.

After Kanzi loads and deploys all resources, the function calls the callback you provide.

Parameters
nodeNode where to instantiate the prefab, and the node to resolve from.
idResource id of the prefab.
callbackCallback function that this function calls when resource loading is completed.

◆ getDefaultMemoryStrategy()

MemoryStrategy getDefaultMemoryStrategy ( )

Gets the memory release strategy.

Returns
The current memory strategy.

◆ getDomain()

Domain getDomain ( )

Returns the domain associated with the resource manager.

Returns
Reference to associated domain instance.

◆ purge()

void purge ( )

Deletes unreferenced resources.

You can use this function to free memory. Destroys all resources that are referenced only by the resource manager.

◆ registerProtocolHandler() [1/2]

void registerProtocolHandler ( String protocol,
ProtocolHandler loadHandler )

Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).

Parameters
protocolThe protocol name. For example, "http".
loadHandlerThe protocol handler. Kanzi calls this function when you use a URL with the given protocol, and Kanzi does not find an existing resource with that URL. This loader function creates a resource.
Exceptions
IllegalStateExceptionThrows an IllegalStateException when the protocol has already been registered.

◆ registerProtocolHandler() [2/2]

void registerProtocolHandler ( String protocol,
ProtocolHandler loadHandler,
ReloadProtocolHandler reloadHandler )

Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).

Parameters
protocolThe protocol name. For example, "http".
loadHandlerThe protocol handler. Kanzi calls this function when you use a URL with the given protocol, and Kanzi does not find an existing resource with that URL. This loader function creates a resource.
reloadHandlerThe reload protocol handler. Kanzi calls this function to recreate an existing resource. Kanzi uses this function only for GPU resources when an application loses GL context in a pause-resume event.
Exceptions
IllegalStateExceptionThrows an IllegalStateException when the protocol has already been registered.

◆ setDefaultMemoryStrategy()

void setDefaultMemoryStrategy ( MemoryStrategy strategy)

Sets the memory release strategy for new resources.

Parameters
strategyThe new memory strategy.

◆ supportsProtocolHandler()

boolean supportsProtocolHandler ( String protocol)

Checks whether the given resource URL protocol (scheme name) is registered as a protocol handler for the resource manager.

Parameters
protocolThe protocol to check.
Returns
True if the protocol is registered, otherwise False.

◆ tryAcquireResource()

ObjectRef< TResourceType > tryAcquireResource ( String url)

Acquires a resource associated with the given URL, like com.rightware.kanzi.ResourceManager#acquireResource, but does not throw exceptions on failure.

Parameters
urlURL of the resource.
Returns
Resource that was loaded. If the resource does not exist, null.

◆ unregisterProtocolHandler()

void unregisterProtocolHandler ( String protocol)

Unregisters the protocol handler with the given resource URL protocol (scheme name).

Parameters
protocolThe protocol name.

◆ unregisterResource()

void unregisterResource ( String url)

Removes the association of the given URL to a resource or a load task.

You can use this function to force Kanzi to recreate a resource the next time you use this URL.

Parameters
urlURL of the resource.

◆ wait()

void wait ( AcquireTask acquireTask)

Blocks the execution until the async acquire task finishes and calls the callback of the task (unless it has been called already).

Parameters
acquireTaskAcquire task created from com.rightware.kanzi.ResourceManager#acquireResourcesAsync.