SunSPOT API V5.0


com.sun.spot.resourcesharing
Interface IResource

All Known Implementing Classes:
SimpleResource

public interface IResource

This interface must be implemented by any object that is to be a shared resource. Only objects that implement this interface can be registered with the resource registry. To make a shared resource available it must be registered in every isolate in which it is to be available using IResourceRegistry.register(String, IResource). When access to a resource is requested using IResourceRegistry.getResource(String, ResourceSharingScheme) the registry will check across all isolates that the requested access is compatible with the current locks and if so it will call getHandle(ResourceSharingScheme, boolean). SimpleResource is an implementation of this interface that can used for simple cases, or extended for more complex ones.


Method Summary
 IResourceHandle getHandle(ResourceSharingScheme scheme, boolean isLockedInADifferentIsolate)
          Generate a handle for this resource.
 String getResourceName()
           
 IResourceHandle lockAdjusted(IResourceHandle handle, ResourceSharingScheme oldScheme, ResourceSharingScheme newScheme)
          A previously generated handle is adjusting its ResourceSharingScheme.
 void unlocked(IResourceHandle handle)
          A previously generated handle has been unlocked, and the handle can be reused.
 

Method Detail

getHandle

IResourceHandle getHandle(ResourceSharingScheme scheme,
                          boolean isLockedInADifferentIsolate)
                          throws ResourceSharingException,
                                 ResourceUnavailableException
Generate a handle for this resource. This method is called on the resource by the resource registry when the registry has determined that a handle should be generated according to the rules of the requested scheme, taking into account locks held in all isolates. The receiver should generate a handle or throw an exception if it is unable to do so. The handle generated should not be the same object as any other handle for this resource that is still in use.

Parameters:
scheme - The scheme that the requestor intends to follow for this handle
isLockedInADifferentIsolate - true if a lock for this resource already exists in another isolate
Returns:
the new handle
Throws:
ResourceSharingException - if the scheme is not supported or there is some other problem
ResourceUnavailableException - if, despite the checks already performed by the registry, the resource still thinks the handle shouldn't be generated because it would conflict with other usage

unlocked

void unlocked(IResourceHandle handle)
              throws ResourceSharingException
A previously generated handle has been unlocked, and the handle can be reused. This method is called by the registry when it receives the unlock(handle) call.

Parameters:
handle - The handle that has been unlocked.
Throws:
ResourceSharingException - if the handle is not recognised or there is some other problem

getResourceName

String getResourceName()
Returns:
the name of the this resource

lockAdjusted

IResourceHandle lockAdjusted(IResourceHandle handle,
                             ResourceSharingScheme oldScheme,
                             ResourceSharingScheme newScheme)
                             throws ResourceSharingException,
                                    ResourceUnavailableException
A previously generated handle is adjusting its ResourceSharingScheme. Returns a handle that has the new lock status (which might or might not be the same handle passed as the input parameter).

Parameters:
handle -
oldScheme -
newScheme -
Returns:
the handle that reflects the adjusted lock
Throws:
ResourceSharingException - if the scheme is not supported or there is some other problem
ResourceUnavailableException - if, despite the checks already performed by the registry, the resource still thinks the scheme shouldn't be adjusted because it would conflict with other usage

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.