Brooklyn

brooklyn.util.mutex
[Java] Class SemaphoreWithOwners

java.lang.Object
  java.util.concurrent.Semaphore
      brooklyn.util.mutex.SemaphoreWithOwners

public class SemaphoreWithOwners
extends java.util.concurrent.Semaphore

a subclass of Semaphore which requires the same thread to release as created it, and which tracks who created and released the semaphores


Constructor Summary
SemaphoreWithOwners(java.lang.String name)

SemaphoreWithOwners(java.lang.String name, int permits, boolean fair)

 
Method Summary
void acquire()

void acquire(int permits)

void acquireUninterruptibly()

void acquireUninterruptibly(int permits)

java.lang.String getDescription()

caller supplied description

java.lang.String getName()

constructor-time supplied name

java.util.List getOwningThreads()

unmodifiable view of threads owning the permits; threads with multiple permits listed multiply

java.util.List getRequestingThreads()

unmodifiable view of threads requesting access (blocked or briefly trying to acquire); this is guaranteed to be cleared _after_ getOwners (synchronizing on this class while reading both fields will give canonical access)

void indicateCallingThreadWillRequest()

Indicate that the calling thread is going to acquire or tryAcquire, in order to set up the semaphore's isInUse() value appropriately for certain checks.

boolean isCallingThreadAnOwner()

true iff the calling thread is one of the owners

boolean isInUse()

true iff there are any owners or any requesters (callers blocked trying to acquire)

protected void onAcquired(int permits)

protected void onReleased(int permits)

protected void onRequestFinished()

protected void onRequesting()

void release()

void release(int permits)

void setDescription(java.lang.String description)

java.lang.String toString()

boolean tryAcquire()

boolean tryAcquire(int permits)

boolean tryAcquire(int permits, long timeout, java.util.concurrent.TimeUnit unit)

boolean tryAcquire(long timeout, java.util.concurrent.TimeUnit unit)

 
Methods inherited from class java.util.concurrent.Semaphore
java.util.concurrent.Semaphore#toString(), java.util.concurrent.Semaphore#acquire(int), java.util.concurrent.Semaphore#acquire(), java.util.concurrent.Semaphore#release(int), java.util.concurrent.Semaphore#release(), java.util.concurrent.Semaphore#isFair(), java.util.concurrent.Semaphore#hasQueuedThreads(), java.util.concurrent.Semaphore#getQueueLength(), java.util.concurrent.Semaphore#tryAcquire(long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#tryAcquire(int), java.util.concurrent.Semaphore#tryAcquire(int, long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#tryAcquire(), java.util.concurrent.Semaphore#acquireUninterruptibly(), java.util.concurrent.Semaphore#acquireUninterruptibly(int), java.util.concurrent.Semaphore#availablePermits(), java.util.concurrent.Semaphore#drainPermits(), java.util.concurrent.Semaphore#wait(), java.util.concurrent.Semaphore#wait(long), java.util.concurrent.Semaphore#wait(long, int), java.util.concurrent.Semaphore#equals(java.lang.Object), java.util.concurrent.Semaphore#hashCode(), java.util.concurrent.Semaphore#getClass(), java.util.concurrent.Semaphore#notify(), java.util.concurrent.Semaphore#notifyAll()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Constructor Detail

SemaphoreWithOwners

public SemaphoreWithOwners(java.lang.String name)


SemaphoreWithOwners

public SemaphoreWithOwners(java.lang.String name, int permits, boolean fair)


 
Method Detail

acquire

@Override
public void acquire()


acquire

@Override
public void acquire(int permits)


acquireUninterruptibly

@Override
public void acquireUninterruptibly()


acquireUninterruptibly

@Override
public void acquireUninterruptibly(int permits)


getDescription

public java.lang.String getDescription()
caller supplied description


getName

public java.lang.String getName()
constructor-time supplied name


getOwningThreads

public java.util.List getOwningThreads()
unmodifiable view of threads owning the permits; threads with multiple permits listed multiply


getRequestingThreads

public java.util.List getRequestingThreads()
unmodifiable view of threads requesting access (blocked or briefly trying to acquire); this is guaranteed to be cleared _after_ getOwners (synchronizing on this class while reading both fields will give canonical access)


indicateCallingThreadWillRequest

public void indicateCallingThreadWillRequest()
Indicate that the calling thread is going to acquire or tryAcquire, in order to set up the semaphore's isInUse() value appropriately for certain checks. It *must* do so after invoking this method.


isCallingThreadAnOwner

public boolean isCallingThreadAnOwner()
true iff the calling thread is one of the owners


isInUse

public boolean isInUse()
true iff there are any owners or any requesters (callers blocked trying to acquire)


onAcquired

protected void onAcquired(int permits)


onReleased

protected void onReleased(int permits)


onRequestFinished

protected void onRequestFinished()


onRequesting

protected void onRequesting()


release

@Override
public void release()


release

@Override
public void release(int permits)


setDescription

public void setDescription(java.lang.String description)


toString

@Override
public java.lang.String toString()


tryAcquire

@Override
public boolean tryAcquire()


tryAcquire

@Override
public boolean tryAcquire(int permits)


tryAcquire

@Override
public boolean tryAcquire(int permits, long timeout, java.util.concurrent.TimeUnit unit)


tryAcquire

@Override
public boolean tryAcquire(long timeout, java.util.concurrent.TimeUnit unit)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.