Interface WorkflowSemaphore
-
public interface WorkflowSemaphoreWorkflow semaphore is an alternative toSemaphorethat is deterministic and compatible with Temporal's concurrency model. API is designed to be used in a workflow code only. It is not allowed to be used in an activity code.In Temporal concurrency model, only one thread in a workflow code can execute at a time.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidacquire()Acquires a permit from this semaphore, blocking until one is available.voidacquire(int permits)Acquires the given number of permits from this semaphore, blocking until all are available.voidrelease()Releases a permit, returning it to the semaphore.voidrelease(int permits)Releases the given number of permits, returning them to the semaphore.booleantryAcquire()Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.booleantryAcquire(int permits)Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.booleantryAcquire(int permits, java.time.Duration timeout)Acquires the given number of permits from this semaphore, if all become available within the given waiting time.booleantryAcquire(java.time.Duration timeout)Acquires a permit from this semaphore, if one becomes available within the given waiting time.
-
-
-
Method Detail
-
acquire
void acquire()
Acquires a permit from this semaphore, blocking until one is available.Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).
-
acquire
void acquire(int permits)
Acquires the given number of permits from this semaphore, blocking until all are available.Acquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.
- Parameters:
permits- the number of permits to acquire- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).java.lang.IllegalArgumentException- if permits is negative
-
tryAcquire
boolean tryAcquire()
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.Acquires a permit, if one is available and returns immediately, with the value true, reducing the number of available permits by one.
- Returns:
- true if the permit was acquired and false otherwise
-
tryAcquire
boolean tryAcquire(java.time.Duration timeout)
Acquires a permit from this semaphore, if one becomes available within the given waiting time.Acquires a permit, if one is available and returns immediately, with the value true, reducing the number of available permits by one.
- Parameters:
timeout- the maximum time to wait for a permit- Returns:
- true if a permit was acquired and false if the waiting time elapsed before a permit was acquired
- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).
-
tryAcquire
boolean tryAcquire(int permits)
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.Acquires the given number of permits, if they are available, and returns immediately, with the value true, reducing the number of available permits by the given amount.
If insufficient permits are available then this method will return immediately with the value false and the number of available permits is unchanged.
- Parameters:
permits- the number of permits to acquire- Returns:
- true if the permits were acquired and false otherwise
- Throws:
java.lang.IllegalArgumentException- if permits is negative
-
tryAcquire
boolean tryAcquire(int permits, java.time.Duration timeout)Acquires the given number of permits from this semaphore, if all become available within the given waiting time.Acquires the given number of permits, if they are available and returns immediately, with the value true, reducing the number of available permits by the given amount.
- Parameters:
permits- the number of permits to acquiretimeout- the maximum duration to wait for a permit- Returns:
- true if the permits was acquired and false if the waiting time elapsed before a permit was acquired
- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).java.lang.IllegalArgumentException- if permits is negative
-
release
void release()
Releases a permit, returning it to the semaphore.There is no requirement that a coroutine that releases a permit must have acquired that permit by calling
acquire(). Correct usage of a semaphore is established by programming convention in the application.
-
release
void release(int permits)
Releases the given number of permits, returning them to the semaphore.There is no requirement that a coroutine that releases a permit must have acquired that permit by calling
acquire(). Correct usage of a semaphore is established by programming convention in the application.- Parameters:
permits- the number of permits to release- Throws:
java.lang.IllegalArgumentException- if permits is negative
-
-