org.objectweb.dream.synchro
Class AbstractSemaphoreQueuedImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.synchro.SemaphoreImpl
          extended by org.objectweb.dream.synchro.AbstractSemaphoreQueuedImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, Semaphore, SemaphoreAttributeController, AttributeController, BindingController, LifeCycleController
Direct Known Subclasses:
SemaphoreFIFOImpl

public class AbstractSemaphoreQueuedImpl
extends SemaphoreImpl

Abstract implementation of a semaphore relying on queued wait nodes.

Note: Inspired by Doug Lea's implementation.


Nested Class Summary
static class AbstractSemaphoreQueuedImpl.WaitQueue
          Base class for internal queue classes for semaphores, etc.
 
Field Summary
protected  AbstractSemaphoreQueuedImpl.WaitQueue wq
           
 
Fields inherited from class org.objectweb.dream.synchro.SemaphoreImpl
permits
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, fcNeedAsyncStart, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.synchro.Semaphore
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Method Summary
 void acquire()
          Waits until a permit is available, and take one
 boolean attempt(long msecs)
          Waits at most msecs millisconds for a permit.
protected  AbstractSemaphoreQueuedImpl.WaitQueue.WaitNode getSignallee()
           
 String[] listFc()
           
protected  boolean precheck()
           
protected  boolean recheck(AbstractSemaphoreQueuedImpl.WaitQueue.WaitNode w)
           
 void release()
          Release a permit
 void release(long n)
          Releases N permits.
 
Methods inherited from class org.objectweb.dream.synchro.SemaphoreImpl
getInitialPermits, permits, setInitialPermits
 
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

wq

protected final AbstractSemaphoreQueuedImpl.WaitQueue wq
Method Detail

acquire

public void acquire()
             throws InterruptedException
Description copied from interface: Semaphore
Waits until a permit is available, and take one

Specified by:
acquire in interface Semaphore
Overrides:
acquire in class SemaphoreImpl
Throws:
InterruptedException - if the thread is interrupted while trying to acquire the permit.
See Also:
Semaphore.acquire()

attempt

public boolean attempt(long msecs)
                throws InterruptedException
Description copied from interface: Semaphore
Waits at most msecs millisconds for a permit.

Specified by:
attempt in interface Semaphore
Overrides:
attempt in class SemaphoreImpl
Parameters:
msecs - the number of milleseconds to wait. An argument less than or equal to zero means not to wait at all. However, this may still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention among threads.
Returns:
true if acquired.
Throws:
InterruptedException - if the thread is interrupted while waiting for the permit.
See Also:
Semaphore.attempt(long)

release

public void release()
Description copied from interface: Semaphore
Release a permit

Specified by:
release in interface Semaphore
Overrides:
release in class SemaphoreImpl
See Also:
Semaphore.release()

release

public void release(long n)
Description copied from interface: Semaphore
Releases N permits.

Specified by:
release in interface Semaphore
Overrides:
release in class SemaphoreImpl
Parameters:
n - the number of permits to be released.
See Also:
Semaphore.release(long)

precheck

protected boolean precheck()

recheck

protected boolean recheck(AbstractSemaphoreQueuedImpl.WaitQueue.WaitNode w)

getSignallee

protected AbstractSemaphoreQueuedImpl.WaitQueue.WaitNode getSignallee()

listFc

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


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