org.apache.felix.deploymentadmin

## Class Semaphore

- java.lang.Object
- - org.apache.felix.deploymentadmin.Semaphore

    public class Semaphore
    extends Object

A semaphore, that maintains one single permit. An `acquire()` blocks until a permit is available, whilst `release()` will unblock it.

### Constructor Summary

Constructors
Constructor and Description
`Semaphore()` Creates a new semaphore that is available.
`Semaphore(boolean isAvailable)` Creates a new semaphore and allows you to specify if it's available or not.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `acquire()` Acquires the semaphore, or blocks until it's available or the thread is interrupted.
`void` `release()` Releases the semaphore.
`boolean` `tryAcquire(long timeout)` Tries to acquire the semaphore and waits for the duration of the specified timeout until it becomes available.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Semaphore

    public Semaphore()

Creates a new semaphore that is available.

#### Semaphore

    public Semaphore(boolean isAvailable)

Creates a new semaphore and allows you to specify if it's available or not.

Parameters:
  `isAvailable` - should the semaphore be available or not

### Method Detail

#### acquire

    public void acquire()
                 throws InterruptedException

Acquires the semaphore, or blocks until it's available or the thread is interrupted.

Throws:
  `InterruptedException` - when the thread is interrupted

#### tryAcquire

    public boolean tryAcquire(long timeout)
                       throws InterruptedException

Tries to acquire the semaphore and waits for the duration of the specified timeout until it becomes available.

Parameters:
  `timeout` - the number of milliseconds to wait
Returns:
  `true` if the semaphore was acquired, `false` if it was not after waiting for the specified amount of time
Throws:
  `InterruptedException` - when the thread is interrupted

#### release

    public void release()

Releases the semaphore. If threads were waiting, one of them is notified.