public class SemaphoreClientProxy extends Object implements ISemaphore
Instance.InstanceType| Constructor and Description |
|---|
SemaphoreClientProxy(HazelcastClient hazelcastClient,
String name) |
| Modifier and Type | Method and Description |
|---|---|
void |
acquire()
Acquires a permit, if one is available and returns immediately,
reducing the number of available permits by one.
|
void |
acquire(int permits)
Acquires the given number of permits, if they are available,
and returns immediately, reducing the number of available permits
by the given amount.
|
Future |
acquireAsync()
Asynchronously acquires a permit.
|
Future |
acquireAsync(int permits)
Asynchronously acquires a given number of permits.
|
void |
acquireAttach()
Acquires and attaches a permit to the caller's address.
|
void |
acquireAttach(int permits)
Acquires and attaches the given number of permits to the caller's
address.
|
Future |
acquireAttachAsync()
Asynchronously acquires and attaches a permit to the caller's address.
|
Future |
acquireAttachAsync(int permits)
Asynchronously acquires and attaches the given number of permits
to the caller's address.
|
void |
attach()
Attaches a permit to the caller's address.
|
void |
attach(int permits)
Attaches the given number of permits to the caller's address.
|
int |
attachedPermits()
Returns the current number of permits attached to the caller's address.
|
int |
availablePermits()
Returns the current number of permits currently available in this semaphore.
|
void |
destroy()
Destroys this instance cluster-wide.
|
void |
detach()
Detaches a permit from the caller's address.
|
void |
detach(int permits)
Detaches the given number of permits from the caller's address.
|
int |
drainPermits()
Acquires and returns all permits that are immediately available.
|
Object |
getId()
Returns the unique id for this instance.
|
Instance.InstanceType |
getInstanceType()
Returns instance type such as map, set, list, lock, topic, multimap, id generator
|
LocalSemaphoreStats |
getLocalSemaphoreStats() |
String |
getName()
Returns the name of this ISemaphore instance.
|
void |
reducePermits(int permits)
Shrinks the number of available permits by the indicated
reduction.
|
void |
release()
Releases a permit, increasing the number of available permits by
one.
|
void |
release(int permits)
Releases the given number of permits, increasing the number of
available permits by that amount.
|
void |
releaseDetach()
Detaches a permit from the caller's address and returns it to the semaphore.
|
void |
releaseDetach(int permits)
Detaches the given number of permits from the caller's address and returns
them to the semaphore.
|
boolean |
tryAcquire()
Acquires a permit, if one is available and returns immediately,
with the value
true,
reducing the number of available permits by one. |
boolean |
tryAcquire(int permits)
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. |
boolean |
tryAcquire(int permits,
long timeout,
TimeUnit unit)
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. |
boolean |
tryAcquire(long timeout,
TimeUnit unit)
Acquires a permit from this semaphore, if one becomes available
within the given waiting time and the current thread has not
been interrupted.
|
boolean |
tryAcquireAttach()
Acquires a permit from this semaphore and attaches it to the
calling member, only if one is available at the time of invocation.
|
boolean |
tryAcquireAttach(int permits)
Acquires the given number of permits from this semaphore and
attaches them to the calling member, only if all are available
at the time of invocation.
|
boolean |
tryAcquireAttach(int permits,
long timeout,
TimeUnit unit)
Acquires the given number of permits from this semaphore and
attaches them to the calling member, only if all become available
within the given waiting time and the current thread has not
been interrupted or the instance
destroyed.
|
boolean |
tryAcquireAttach(long timeout,
TimeUnit unit)
Acquires a permit from this semaphore and attaches it to the calling
member, only if one becomes available within the given waiting
time and the current thread has not been interrupted
or the instance destroyed.
|
public SemaphoreClientProxy(HazelcastClient hazelcastClient, String name)
public void acquire()
throws InstanceDestroyedException,
InterruptedException
ISemaphoreAcquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
ISemaphore.release() methods for this
semaphore and the current thread is next to be assigned a permit;
If the ISemaphore instance is destroyed while the thread is waiting
then InstanceDestroyedException will be thrown.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.acquire in interface ISemaphoreInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic void acquire(int permits)
throws InstanceDestroyedException,
InterruptedException
ISemaphoreAcquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.
If insufficient permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
release
methods for this semaphore, the current thread is next to be assigned
permits and the number of available permits satisfies this request;
InstanceDestroyedException will be thrown.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.acquire in interface ISemaphorepermits - the number of permits to acquireInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic Future acquireAsync()
ISemaphoreFuture future = semaphore.acquireAsync(); // do some other stuff, when ready get the result Object value = future.get();Future.get() will block until the actual acquire() completes. If the application requires timely response, then Future.get(timeout, timeunit) can be used.
Future future = semaphore.acquireAsync();
try{
Object value = future.get(40, TimeUnit.MILLISECOND);
}catch (TimeoutException t) {
// time wasn't enough
}
This method itself does not throw any exceptions. Exceptions occur during
the future.get() operation.
If insufficient permits are available when calling
future.get() then the current
thread becomes disabled for thread scheduling purposes and lies dormant until
one of four things happens:
release
methods for this semaphore, the current thread is next to be assigned
permits and the number of available permits satisfies this request;
future.get() is waiting then
ExecutionException will be thrown with
InstanceDestroyedException set as it's cause.
If the Hazelcast instance is shutdows while the
future.get() is waiting then
IllegalStateException will be thrown.
If when calling future.get()
a timeout is specified and the a permit cannot be acquired within the
timeout period TimeoutException will be thrown.
If when calling future.get()
the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.
If the thread future.get() throws an
InterruptedException, the acquire request is still outstanding and
future.get()
may be called again. To cancel the actual acquire,
future.cancel()
must be called. If the cancel method returns false then
it was too late to cancel the request and the permit was acquired.
The future.cancel()
mayInterruptIfRunning argument is ignored.
acquireAsync in interface ISemaphoreFuturepublic Future acquireAsync(int permits)
ISemaphoreISemaphore.acquireAsync().acquireAsync in interface ISemaphorepermits - the number of permits to acquirepublic void acquireAttach()
throws InstanceDestroyedException,
InterruptedException
ISemaphoreISemaphore.acquire() and ISemaphore.attach().acquireAttach in interface ISemaphoreInstanceDestroyedExceptionInterruptedExceptionpublic void acquireAttach(int permits)
throws InstanceDestroyedException,
InterruptedException
ISemaphoreISemaphore.acquire() and ISemaphore.attach().acquireAttach in interface ISemaphorepermits - the number of permits to acquire and attachInstanceDestroyedExceptionInterruptedExceptionpublic Future acquireAttachAsync()
ISemaphoreISemaphore.acquireAsync() and ISemaphore.attach().acquireAttachAsync in interface ISemaphorepublic Future acquireAttachAsync(int permits)
ISemaphoreISemaphore.acquireAsync() and ISemaphore.attach().acquireAttachAsync in interface ISemaphorepermits - the number of permits to acquire and attachpublic void attach()
ISemaphoreISemaphore.attachedPermits().attach in interface ISemaphorepublic void attach(int permits)
ISemaphoreISemaphore.attachedPermits().attach in interface ISemaphorepermits - the number of permits to attachpublic int attachedPermits()
ISemaphorereleased to the semaphore if the caller address becomes
disconnected from the cluster.
Negative value represents the number of permits that the semaphore will
automatically be reduced by if the caller address
becomes disconnected from the cluster.
attachedPermits in interface ISemaphorepublic int availablePermits()
ISemaphoreavailablePermits in interface ISemaphorepublic void detach()
ISemaphoreISemaphore.attachedPermits().detach in interface ISemaphorepublic void detach(int permits)
ISemaphoreISemaphore.attachedPermits().detach in interface ISemaphorepermits - the number of permits to detachpublic int drainPermits()
ISemaphoredrainPermits in interface ISemaphorepublic void reducePermits(int permits)
ISemaphoreacquire in that it does not
block waiting for permits to become available.reducePermits in interface ISemaphorepermits - the number of permits to removepublic void release()
ISemaphoreacquire methods.
Correct usage of a semaphore is established by programming convention
in the application.release in interface ISemaphorepublic void release(int permits)
ISemaphoreacquire methods.
Correct usage of a semaphore is established by programming convention
in the application.release in interface ISemaphorepermits - the number of permits to releasepublic void releaseDetach()
ISemaphoreISemaphore.release() and ISemaphore.detach().releaseDetach in interface ISemaphorepublic void releaseDetach(int permits)
ISemaphoreISemaphore.release(int) and ISemaphore.detach().releaseDetach in interface ISemaphorepermits - the number of permits to release and detachpublic boolean tryAcquire()
ISemaphoretrue,
reducing the number of available permits by one.
If no permit is available then this method will return
immediately with the value false.tryAcquire in interface ISemaphoretrue if a permit was acquired and false
otherwisepublic boolean tryAcquire(int permits)
ISemaphoretrue,
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.
tryAcquire in interface ISemaphorepermits - the number of permits to acquiretrue if the permits were acquired and
false otherwisepublic boolean tryAcquire(long timeout,
TimeUnit unit)
throws InstanceDestroyedException,
InterruptedException
ISemaphoretrue,
reducing the number of available permits by one.
If no permit is available then the current thread becomes
disabled for thread scheduling purposes and lies dormant until
one of three things happens:
ISemaphore.release() method for this
semaphore and the current thread is next to be assigned a permit; or
true is returned.
If the specified waiting time elapses then the value false
is returned. If the time is less than or equal to zero, the method
will not wait at all.
If the ISemaphore instance is destroyed while the thread is waiting
then InstanceDestroyedException will be thrown.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.tryAcquire in interface ISemaphoretimeout - the maximum time to wait for a permitunit - the time unit of the timeout argumenttrue if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic boolean tryAcquire(int permits,
long timeout,
TimeUnit unit)
throws InstanceDestroyedException,
InterruptedException
ISemaphoretrue,
reducing the number of available permits by the given amount.
If insufficient permits are available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until one of three things happens:
release
methods for this semaphore, the current thread is next to be assigned
permits and the number of available permits satisfies this request; or
true is returned.
If the specified waiting time elapses then the value false
is returned. If the time is less than or equal to zero, the method
will not wait at all.
If the ISemaphore instance is destroyed while the thread is waiting
then InstanceDestroyedException will be thrown.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.tryAcquire in interface ISemaphorepermits - the number of permits to acquiretimeout - the maximum time to wait for the permitsunit - the time unit of the timeout argumenttrue if all permits were acquired and false
if the waiting time elapsed before all permits could be acquiredInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic boolean tryAcquireAttach()
ISemaphoreISemaphore.tryAcquire() and ISemaphore.attach().tryAcquireAttach in interface ISemaphoretrue if permit was acquired and attached to
the caller's addresspublic boolean tryAcquireAttach(int permits)
ISemaphoreISemaphore.tryAcquire(int permits) and ISemaphore.attach(int).tryAcquireAttach in interface ISemaphorepermits - the number of permits to try to acquire and attachtrue if permit(s) were acquired and attached to
the caller's addresspublic boolean tryAcquireAttach(long timeout,
TimeUnit unit)
throws InstanceDestroyedException,
InterruptedException
ISemaphoreInstanceDestroyedException will be thrown.
See ISemaphore.tryAcquire(long timeout, TimeUnit unit) and ISemaphore.attach().tryAcquireAttach in interface ISemaphoretimeout - the maximum time to wait for a permitunit - unit the time unit of the timeout argumenttrue if a permit was acquired and false
if the waiting time elapsed before a permit could be acquiredInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic boolean tryAcquireAttach(int permits,
long timeout,
TimeUnit unit)
throws InstanceDestroyedException,
InterruptedException
ISemaphoreISemaphore.tryAcquire(int permits, long timeout, TimeUnit unit) and ISemaphore.attach(int).tryAcquireAttach in interface ISemaphorepermits - the number of permits to try to acquire and attachtimeout - the maximum time to wait for the permitsunit - unit the time unit of the timeout argumenttrue if permit(s) were acquired and attached to
the caller's address and false if the waiting
time elapsed before the permits could be acquiredInstanceDestroyedException - if the instance is destroyed while waitingInterruptedException - if the current thread is interruptedpublic Instance.InstanceType getInstanceType()
InstancegetInstanceType in interface Instancepublic void destroy()
Instancepublic Object getId()
Instancepublic String getName()
ISemaphoregetName in interface ISemaphorepublic LocalSemaphoreStats getLocalSemaphoreStats()
getLocalSemaphoreStats in interface ISemaphoreCopyright © 2013 Hazelcast, Inc.. All rights reserved.