SunSPOT host API V6.0


com.sun.spot.resources
Interface ILocking

All Known Implementing Classes:
LockingCompositeResource, LockingResource

public interface ILocking

An interface to support exclusive locking of a resource.

The ILocking Interface allows an Isolate to get exclusive access to a resource. This differs from Java where only one thread at a time can acquire the lock; for SPOT Resource's all threads in an Isolate can access a resource once the Isolate acquires the resource's lock. This seems more useful since a major reason for locks is that the author of one SPOT application (i.e. MIDlet) can do whatever they need to interlock resource use between threads in their Isolate, but needs real locking to protect from usages in other author's applications.

For backwards compatibility SPOT apps can use resources without explicit locking. However if one Isolate acquires the lock for a resource, then any attempt to by another Isolate to access the resource will throw a com.sun.spot.resources.ResourceUnavailableException.

Not every IResource will support locking. Initially none will. The classes LockingResource & LockingCompositeResource provide a basic implementation of the ILocking & IResource (ICompositeResource) methods. Developers can extend them when writing their own locking (composite) resource classes. Developers must make sure that all of the resource's accessing methods first check that either the resource is not locked or that the current Isolate owns the lock.

Author:
Ron

Method Summary
 Isolate getOwner()
          Returns the Isolate that owns this lock.
 void lock()
          Acquires the lock, blocking if necessary
 boolean tryLock()
          Acquires the lock only if it is free.
 boolean tryLock(long time)
          Acquires the lock if it is free within the given wait time.
 void unlock()
          Releases the lock.
 

Method Detail

lock

void lock()
Acquires the lock, blocking if necessary


unlock

void unlock()
Releases the lock.


tryLock

boolean tryLock()
Acquires the lock only if it is free.

Returns:
true if the lock was acquired, false if another Isolate owns the lock.

tryLock

boolean tryLock(long time)
Acquires the lock if it is free within the given wait time.

Parameters:
time - length of time in milliseconds to wait for lock to be free
Returns:
true if the lock was acquired, false if not.

getOwner

Isolate getOwner()
Returns the Isolate that owns this lock.

Returns:
the Isolate that owns this lock or null if lock is free.

SunSPOT host API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.