org.objectweb.dream.synchro
Class BasicMutexImpl

java.lang.Object
  extended byorg.objectweb.dream.AbstractComponent
      extended byorg.objectweb.dream.synchro.BasicMutexImpl
All Implemented Interfaces:
BindingController, LifeCycleController, Loggable, Mutex

public class BasicMutexImpl
extends AbstractComponent
implements Mutex

Basic implementation of the Mutexinterface. This implementation is unsafe, i.e. the identity of components acquiring/releasing the Mutex is unknown. As a consequence, the acquired mutex can be released by every component.
Inspired by Doug Lea's implementation.


Field Summary
protected  boolean inuse
          The lock status.
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, componentDesc, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.synchro.Mutex
MUTEX_ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
BasicMutexImpl()
           
 
Method Summary
 String[] listFc()
           
 void lock()
          Acquires the mutex.
 boolean timedLock(long msecs)
          Tries to acquire the mutex.
 void unlock()
          Releases the mutex.
 
Methods inherited from class org.objectweb.dream.AbstractComponent
bindFc, getFcState, initComponent, lookupFc, setLogger, startFc, stopFc, unbindFc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inuse

protected boolean inuse
The lock status.

Constructor Detail

BasicMutexImpl

public BasicMutexImpl()
Method Detail

lock

public void lock()
          throws InterruptedException
Description copied from interface: Mutex
Acquires the mutex.

Specified by:
lock in interface Mutex
Throws:
InterruptedException - the thread is interrupted.
See Also:
Mutex.lock()

timedLock

public boolean timedLock(long msecs)
                  throws InterruptedException
Description copied from interface: Mutex
Tries to acquire the mutex.

Specified by:
timedLock in interface Mutex
Parameters:
msecs - the number of milliseconds to wait for the lock.
Returns:
true if the lock is acquired, false otherwise.
Throws:
InterruptedException - if the thread is interrupted.
See Also:
Mutex.timedLock(long)

unlock

public void unlock()
Description copied from interface: Mutex
Releases the mutex.

Specified by:
unlock in interface Mutex
See Also:
Mutex.unlock()

listFc

public String[] listFc()
Specified by:
listFc in interface BindingController
See Also:
BindingController.listFc()


Copyright © 2003, 2004 - INRIA Rhone-Alpes - All Rights Reserved.