Kanzi Framework  3.9.0
Java API
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...
 
interface  LoadTask
 Load task allows implementing custom asynchronous resource loading. More...
 
interface  ProtocolHandler
 ProtocolHandler allows implementing custom resource loading for a specific protocol. More...
 

Public Member Functions

AcquireTask acquireResourcesAsync (String[] urls, AcquireTask.Callback callback)
 Creates a background task that loads and deploys all resources from a set of URLs. More...
 
void addKzbFile (String fileName) throws FileNotFoundException
 Opens a kzb file from the file system and adds it to the list of files. More...
 
void collectAndAcquirePrefabAsync (Node node, String id, AcquireTask.Callback callback)
 Creates a background task that collects all resources within a prefab and loads them asynchronously. More...
 
Domain getDomain ()
 Returns the domain associated with the resource manager. More...
 
void purge ()
 Deletes unreferenced resources. More...
 
void registerProtocolHandler (String protocol, ProtocolHandler handler)
 Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name). More...
 
boolean supportsProtocolHandler (String protocol)
 Checks whether the given resource URL protocol (scheme name) is registered as a protocol handler for the resource manager. More...
 
void unregisterProtocolHandler (String protocol)
 Unregisters the protocol handler with the given resource URL protocol (scheme name). More...
 
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). More...
 

Detailed Description

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

Member Function Documentation

◆ 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 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.

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.

◆ 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()

void registerProtocolHandler ( String  protocol,
ProtocolHandler  handler 
)

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

Parameters
protocolThe protocol name. For example, "http".
handlerThe 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.

◆ 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.

◆ unregisterProtocolHandler()

void unregisterProtocolHandler ( String  protocol)

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

Parameters
protocolThe protocol name.

◆ 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 ResourceManager#acquireResourcesAsync.