org.objectweb.dream.synchro
Class MutexReEntrantImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.synchro.MutexReEntrantImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, Mutex, MutexReEntrant, BindingController, LifeCycleController

public class MutexReEntrantImpl
extends AbstractComponent
implements MutexReEntrant

Basic implementation of the MutexReEntrant interface: this mutex is reentrant.

Note: inspired by Doug Lea's implementation.


Field Summary
protected  boolean inuse
          The lock status.
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, fcNeedAsyncStart, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.synchro.MutexReEntrant
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
MutexReEntrantImpl()
           
 
Method Summary
 void forceLock(Object o)
          Acquires the mutex with parameters that have been returned by a previous call to forceUnlock().
 Object forceUnlock()
          Releases the mutex even if it has been acquired several times (by multiple calls to the lock() function).
 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
beforeFirstStart, bindFc, bindFc, getFcNeedAsyncStart, getFcState, initComponent, lookupFc, prepareStopFc, 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

MutexReEntrantImpl

public MutexReEntrantImpl()
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()

forceUnlock

public Object forceUnlock()
Description copied from interface: MutexReEntrant
Releases the mutex even if it has been acquired several times (by multiple calls to the lock() function). The returned object represents the state of the lock. It must be given as parameter to the forceLock() method if the mutex is to be reacquired later (with the same state).

Specified by:
forceUnlock in interface MutexReEntrant
Returns:
o an object representing the state of the lock.
See Also:
MutexReEntrant.forceUnlock()

forceLock

public void forceLock(Object o)
               throws InterruptedException
Description copied from interface: MutexReEntrant
Acquires the mutex with parameters that have been returned by a previous call to forceUnlock().

Specified by:
forceLock in interface MutexReEntrant
Parameters:
o - parameters that have been returned by a previous call to forceUnlock().
Throws:
InterruptedException - the thread is interrupted.
See Also:
MutexReEntrant.forceLock(Object)

listFc

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


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