public class RaftSessionAwareSemaphoreProxy extends ClientProxy implements ISemaphore
ISemaphore
name
Constructor and Description |
---|
RaftSessionAwareSemaphoreProxy(ClientContext context,
RaftGroupId groupId,
String proxyName,
String objectName) |
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 available at invocation time.
|
CPGroupId |
getGroupId() |
String |
getPartitionKey()
Returns the key of the partition that this DistributedObject is assigned to.
|
void |
increasePermits(int increase)
Increases the number of available permits by the indicated amount.
|
boolean |
init(int permits)
Tries to initialize this ISemaphore instance with the given permit count
|
void |
onDestroy()
Called before proxy is destroyed.
|
void |
reducePermits(int reduction)
Reduces the number of available permits by the indicated amount.
|
void |
release()
Releases a permit and increases the number of available permits by one.
|
void |
release(int permits)
Releases the given number of permits and increases the number of
available permits by that amount.
|
boolean |
tryAcquire()
Acquires a permit if one is available, and returns
true
immediately. |
boolean |
tryAcquire(int permits)
Acquires the given number of permits if they are available, and
returns
true immediately. |
boolean |
tryAcquire(int permits,
long timeout,
TimeUnit unit)
Acquires the given number of permits and returns
true , if they
become available during the given waiting time. |
boolean |
tryAcquire(long timeout,
TimeUnit unit)
Acquires a permit and returns
true , if one becomes available
during the given waiting time and the current thread has not been
interrupted. |
deregisterListener, destroy, destroyLocally, destroyRemotely, equals, getClient, getConnectedServerVersion, getContext, getDistributedObjectName, getId, getName, getSerializationService, getServiceName, hashCode, invoke, invoke, invokeOnAddress, invokeOnPartition, invokeOnPartitionInterruptibly, onInitialize, onShutdown, postDestroy, preDestroy, registerListener, setContext, toData, toObject
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getName
destroy, getServiceName
public RaftSessionAwareSemaphoreProxy(ClientContext context, RaftGroupId groupId, String proxyName, String objectName)
public boolean init(int permits)
ISemaphore
init
in interface ISemaphore
permits
- the given permit countpublic void acquire()
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
public void acquire(int permits)
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 acquirepublic boolean tryAcquire()
ISemaphore
true
immediately. If no permit is available, returns false
immediately.tryAcquire
in interface ISemaphore
true
if a permit was acquired, false
otherwisepublic boolean tryAcquire(int permits)
ISemaphore
true
immediately. If the requested number of permits are
not available, returns false
immediately.tryAcquire
in interface ISemaphore
permits
- the number of permits to acquiretrue
if the permits were acquired, false
otherwisepublic boolean tryAcquire(long timeout, TimeUnit unit)
ISemaphore
true
, if one becomes available
during the given waiting time and the current thread has not been
interrupted. If a permit is acquired,
the number of available permits in the ISemaphore
instance is
also reduced 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:
Returns true
if a permit is successfully acquired.
Returns false
if the specified waiting time elapses without
acquiring a permit. 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 acquiredpublic boolean tryAcquire(int permits, long timeout, TimeUnit unit)
ISemaphore
true
, if they
become available during the given waiting time. If permits are acquired,
the number of available permits in the ISemaphore
instance is
also reduced by the given amount.
If no sufficient permits are available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
true
if requested permits are successfully acquired.
Returns false
if the specified waiting time elapses without
acquiring permits. 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 acquiredpublic void release()
ISemaphore
If the underlying ISemaphore
impl is the non-JDK compatible
CP impl that is configured via CPSemaphoreConfig
and fetched
via CPSubsystem
, then a HazelcastInstance can only release a permit which
it has acquired before. In other words, a HazelcastInstance cannot release a permit
without acquiring it first.
Otherwise, which means the underlying impl is either the JDK compatible
CP impl configured via CPSemaphoreConfig
and fetched
via CPSubsystem
, or it is the old impl fetched via
HazelcastInstance.getSemaphore(String)
, there is no requirement
that a HazelcastInstance that releases a permit must have acquired that permit by
calling one of the ISemaphore.acquire()
methods. A HazelcastInstance can freely
release a permit without acquiring it first. In this case, correct usage
of a semaphore is established by programming convention in the application.
release
in interface ISemaphore
public void release(int permits)
ISemaphore
If the underlying ISemaphore
impl is the non-JDK compatible
CP impl that is configured via CPSemaphoreConfig
and fetched
via CPSubsystem
, then a HazelcastInstance can only release a permit which
it has acquired before. In other words, a HazelcastInstance cannot release a permit
without acquiring it first.
Otherwise, which means the underlying impl is either the JDK compatible
CP impl configured via CPSemaphoreConfig
and fetched
via CPSubsystem
, or it is the old impl fetched via
HazelcastInstance.getSemaphore(String)
, there is no requirement
that a HazelcastInstance that releases a permit must have acquired that permit by
calling one of the ISemaphore.acquire()
methods. A HazelcastInstance can freely
release a permit without acquiring it first. In this case, correct usage
of a semaphore is established by programming convention in the application.
release
in interface ISemaphore
permits
- the number of permits to releasepublic 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
acquire
as it does not block until permits
become available. Similarly, if the caller has acquired some permits,
they are not released with this call.reducePermits
in interface ISemaphore
reduction
- the number of permits to reducepublic void increasePermits(int increase)
ISemaphore
increasePermits
in interface ISemaphore
increase
- the number of permits to increasepublic String getPartitionKey()
DistributedObject
IAtomicLong
. For a partitioned data structure like an IMap
,
the returned value will not be null, but otherwise undefined.getPartitionKey
in interface DistributedObject
getPartitionKey
in class ClientProxy
public void onDestroy()
ClientProxy
onDestroy
in class ClientProxy
public CPGroupId getGroupId()
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.