SunSPOT API V3.0


com.sun.spot.resourcesharing
Interface IResourceRegistry

All Known Implementing Classes:
ResourceRegistryChild

public interface IResourceRegistry

The interface to the resource registry that controls access to shared resources. A reference to the registry is obtained by calling Spot.getInstance().getResourceRegistry(). The resource registry is used to control access to shared resources. First, resources that are to be made available are registered with the resource registry by calling register(String, IResource). Then an application that wants to use a resource asks the registry for a handle to it by calling getResource(String, ResourceSharingScheme). A list of registered resources can be obtained by calling getResourceNames(). When requesting access to a resource the requestor must specify their intended or required usage by nominating a ResourceSharingScheme. See IResource for information about implementing a shared resource.


Method Summary
 IResourceHandle adjustLock(IResourceHandle handle, ResourceSharingScheme scheme)
          Attempt to change the ResourceSharingScheme associated with the handle.
 IResourceHandle getResource(String resourceName, ResourceSharingScheme scheme)
          Request access to a resource.
 String[] getResourceNames()
           
 void register(String resourceName, IResource resource)
          Inform the registry of a resource that is available for sharing.
 void unlock(IResourceHandle handle)
          Notify the registry that that access to the resource, as defined by the specified handle, is no longer required.
 

Method Detail

register

void register(String resourceName,
              IResource resource)
              throws ResourceSharingException
Inform the registry of a resource that is available for sharing. Note that this call must be made in the same isolate in which users of the resource reside. If a resource is to be available in multiple isolates then this call must be made - using the same resource name - in each isolate.

Parameters:
resourceName - The name of the resource
resource - The resource object
Throws:
ResourceSharingException - If the resource has already been registered.

getResourceNames

String[] getResourceNames()
Returns:
An array of the names of the resources available to be shared.

getResource

IResourceHandle getResource(String resourceName,
                            ResourceSharingScheme scheme)
                            throws ResourceSharingException,
                                   ResourceUnavailableException
Request access to a resource. The caller intends to use the resource in accordance with the scheme specified in the request.

Parameters:
resourceName - The name of the resource.
scheme - The scheme that defines the intended or required usage.
Returns:
A handle that provides access to the resource.
Throws:
ResourceSharingException - If the resource is unknown or there is some other problem
ResourceUnavailableException - If the resource is currently unavailable

unlock

void unlock(IResourceHandle handle)
            throws ResourceSharingException
Notify the registry that that access to the resource, as defined by the specified handle, is no longer required.

Parameters:
handle - The handle being unlocked
Throws:
ResourceSharingException

adjustLock

IResourceHandle adjustLock(IResourceHandle handle,
                           ResourceSharingScheme scheme)
                           throws ResourceUnavailableException
Attempt to change the ResourceSharingScheme associated with the handle. Returns a handle that has the new lock status (which might or might not be the same handle passed as the input parameter). If the existence of other locks make the change impossible, throw ResourceUnavailableException.

Parameters:
handle - The handle to adjust the lock of
scheme - The required resource sharing scheme
Returns:
the handle that reflects the adjusted lock
Throws:
ResourceUnavailableException

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.