|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.dream.AbstractComponent
org.objectweb.dream.synchro.SemaphoreImpl
public class SemaphoreImpl
Basic implementation of the Semaphore
interface.
Note: Inspired by Doug Lea's implementation.
Field Summary | |
---|---|
protected long |
permits
current number of available 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 |
Constructor Summary | |
---|---|
SemaphoreImpl()
|
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. |
long |
getInitialPermits()
Returns the initial number of permits of the semaphore. |
String[] |
listFc()
|
long |
permits()
Returns the current number of available permits. |
void |
release()
Release a permit |
void |
release(long n)
Releases N permits. |
void |
setInitialPermits(long initialPermits)
Sets the initial number of permits of the semaphore. |
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 |
---|
protected long permits
Constructor Detail |
---|
public SemaphoreImpl()
Method Detail |
---|
public void acquire() throws InterruptedException
Semaphore
acquire
in interface Semaphore
InterruptedException
- if the thread is interrupted while trying to
acquire the permit.Semaphore.acquire()
public boolean attempt(long msecs) throws InterruptedException
Semaphore
attempt
in interface Semaphore
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.
InterruptedException
- if the thread is interrupted while waiting for
the permit.Semaphore.attempt(long)
public void release()
Semaphore
release
in interface Semaphore
Semaphore.release()
public void release(long n)
Semaphore
release
in interface Semaphore
n
- the number of permits to be released.Semaphore.release(long)
public long permits()
Semaphore
permits
in interface Semaphore
Semaphore.permits()
public void setInitialPermits(long initialPermits)
SemaphoreAttributeController
initialPermits
to one makes the semaphore act as a mutual
exclusion lock. Negative seeds are also allowed, in which case no acquires
will proceed until the number of releases has pushed the number of permits
past 0.
setInitialPermits
in interface SemaphoreAttributeController
initialPermits
- the initial number of permits to set.SemaphoreAttributeController.setInitialPermits(long)
public long getInitialPermits()
SemaphoreAttributeController
getInitialPermits
in interface SemaphoreAttributeController
SemaphoreAttributeController.getInitialPermits()
public String[] listFc()
listFc
in interface BindingController
BindingController.listFc()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |