public class ClientSemaphoreProxy extends ClientProxy implements ISemaphore
ISemaphore
.name
Constructor and Description |
---|
ClientSemaphoreProxy(String serviceName,
String objectId,
ClientContext context) |
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.
|
int |
availablePermits()
Returns the current number of permits currently available in this semaphore.
|
int |
drainPermits()
Acquires and returns all permits that are immediately available.
|
void |
increasePermits(int increase)
Increases the number of available permits by the indicated
amount.
|
boolean |
init(int permits)
Try to initialize this ISemaphore instance with the given permit count
|
protected com.hazelcast.client.impl.protocol.ClientMessage |
invokeOnPartition(com.hazelcast.client.impl.protocol.ClientMessage req) |
protected <T> ClientDelegatingFuture<T> |
invokeOnPartitionAsync(com.hazelcast.client.impl.protocol.ClientMessage clientMessage,
com.hazelcast.client.impl.ClientMessageDecoder clientMessageDecoder) |
protected <T> T |
invokeOnPartitionInterruptibly(com.hazelcast.client.impl.protocol.ClientMessage clientMessage) |
protected void |
onInitialize()
Called when proxy is created.
|
void |
reducePermits(int reduction)
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.
|
String |
toString() |
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.
|
deregisterListener, destroy, destroyLocally, destroyRemotely, equals, getClient, getConnectedServerVersion, getContext, getDistributedObjectName, getId, getName, getPartitionKey, getSerializationService, getServiceName, hashCode, invoke, invoke, invokeOnAddress, invokeOnPartition, invokeOnPartitionInterruptibly, onDestroy, onShutdown, postDestroy, preDestroy, registerListener, setContext, toData, toObject
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getName
destroy, getPartitionKey, getServiceName
public ClientSemaphoreProxy(String serviceName, String objectId, ClientContext context)
public boolean init(int permits)
ISemaphore
init
in interface ISemaphore
permits
- the given permit countpublic void acquire() throws InterruptedException
ISemaphore
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 current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.acquire
in interface ISemaphore
InterruptedException
- if the current thread is interruptedpublic void acquire(int permits) throws InterruptedException
ISemaphore
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,InterruptedException
is thrown and the current thread's
interrupted status is cleared.acquire
in interface ISemaphore
permits
- the number of permits to acquireInterruptedException
- if the current thread is interruptedpublic int availablePermits()
ISemaphore
This method is typically used for debugging and testing purposes.
availablePermits
in interface ISemaphore
public int drainPermits()
ISemaphore
drainPermits
in interface ISemaphore
public void reducePermits(int reduction)
ISemaphore
This method differs from acquire
in that it does not block
waiting for permits to become available.
reducePermits
in interface ISemaphore
reduction
- the number of permits to removepublic void increasePermits(int increase)
ISemaphore
release
in that it does not
effect the amount of permits this caller has attached.increasePermits
in interface ISemaphore
increase
- the number of permits to addpublic void release()
ISemaphore
There is no requirement that a thread that releases a permit must
have acquired that permit by calling one of the acquire
methods. Correct usage of a semaphore is established by programming
convention in the application.
release
in interface ISemaphore
public void release(int permits)
ISemaphore
There is no requirement that a thread that releases a permit must have
acquired that permit by calling one of the acquire
methods.
Correct usage of a semaphore is established by programming convention
in the application.
release
in interface ISemaphore
permits
- the number of permits to releasepublic boolean tryAcquire()
ISemaphore
true
, 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 ISemaphore
true
if a permit was acquired and false
otherwisepublic boolean tryAcquire(int permits)
ISemaphore
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.
tryAcquire
in interface ISemaphore
permits
- the number of permits to acquiretrue
if the permits were acquired and
false
otherwisepublic boolean tryAcquire(long timeout, TimeUnit unit) throws InterruptedException
ISemaphore
Acquires a permit if one is available and returns immediately
with the value true
,
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
If a permit is acquired then the value 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 current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.tryAcquire
in interface ISemaphore
timeout
- 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 acquiredInterruptedException
- if the current thread is interruptedpublic boolean tryAcquire(int permits, long timeout, TimeUnit unit) throws InterruptedException
ISemaphore
true
,
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, ortrue
is returned.
If the specified waiting time elapses then false
is returned. If the time is less than or equal to zero, the method
will not wait at all.
If the current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.tryAcquire
in interface ISemaphore
permits
- 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,
false
if the waiting time elapsed before all permits could be acquiredInterruptedException
- if the current thread is interruptedprotected void onInitialize()
ClientProxy
onInitialize
in class ClientProxy
protected com.hazelcast.client.impl.protocol.ClientMessage invokeOnPartition(com.hazelcast.client.impl.protocol.ClientMessage req)
protected <T> T invokeOnPartitionInterruptibly(com.hazelcast.client.impl.protocol.ClientMessage clientMessage) throws InterruptedException
InterruptedException
protected <T> ClientDelegatingFuture<T> invokeOnPartitionAsync(com.hazelcast.client.impl.protocol.ClientMessage clientMessage, com.hazelcast.client.impl.ClientMessageDecoder clientMessageDecoder)
Copyright © 2018 Hazelcast, Inc.. All rights reserved.