Next: Future Improvements
Up: The Basic Services
Previous: Future Improvements
Although it is possible to implement synchronized methods within the
context of a single Java VM by means of the synchronized key word, it
is impossible to guarantee locks outside that scope. To allow for
locking, Haystack includes a resource control service,
HsResourceControlService. This service allows for locking
and unlocking of arbitrarily named resources. Locks are held for a
preset amount of time (currently 5 minutes).
The methods currently implemented by HsResourceControlService
are:
- testResource(n) which returns true if the resource
n is locked, and false otherwise.
- unlockResource(n) forces an unlock of the resource
n. HsResourceControlService doesn't verify that the
caller has the ``right'' to do this.
- lockResource(n) tries to lock the resource n. If
the lock was successful it returns true, if the attempt to lock
times out, false is returned.
- nonBlockLock(n) tries to lock the resource, and
immediately returns (i.e. there is no timeout).
The HsResourceControlService internally maintains an
extension to the Hashtable class called
ResourceControlHash. The ResourceControlHash
maintains a list of current resources as well as a list of their
timeouts. The ResourceControlHash manages the
synchronization necessary to ensure atomic lock functionality.
Copyright 1998, Eytan Adar (eytan@alum.mit.edu)