use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class SessionAwareSemaphoreProxy method acquire.
@Override
public void acquire(int permits) {
checkPositive("permits", permits);
long threadId = getThreadId();
UUID invocationUid = newUnsecureUUID();
for (; ; ) {
long sessionId = sessionManager.acquireSession(this.groupId, permits);
try {
ClientMessage request = SemaphoreAcquireCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits, -1);
HazelcastClientInstanceImpl client = getClient();
new ClientInvocation(client, request, objectName).invoke().joinInternal();
return;
} catch (SessionExpiredException e) {
sessionManager.invalidateSession(this.groupId, sessionId);
} catch (WaitKeyCancelledException e) {
sessionManager.releaseSession(this.groupId, sessionId, permits);
throw new IllegalStateException("Semaphore[" + objectName + "] not acquired because the acquire call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
} catch (RuntimeException e) {
sessionManager.releaseSession(this.groupId, sessionId, permits);
throw e;
}
}
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method init.
@Override
public boolean init(int permits) {
checkNotNegative(permits, "Permits must be non-negative!");
ClientMessage request = SemaphoreInitCodec.encodeRequest(groupId, objectName, permits);
HazelcastClientInstanceImpl client = getClient();
ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
return SemaphoreInitCodec.decodeResponse(response);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method availablePermits.
@Override
public int availablePermits() {
ClientMessage request = SemaphoreAvailablePermitsCodec.encodeRequest(groupId, objectName);
HazelcastClientInstanceImpl client = getClient();
ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
return SemaphoreAvailablePermitsCodec.decodeResponse(response);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method drainPermits.
@Override
public int drainPermits() {
long clusterWideThreadId = sessionManager.getOrCreateUniqueThreadId(groupId);
UUID invocationUid = newUnsecureUUID();
ClientMessage request = SemaphoreDrainCodec.encodeRequest(groupId, objectName, NO_SESSION_ID, clusterWideThreadId, invocationUid);
HazelcastClientInstanceImpl client = getClient();
ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
return SemaphoreDrainCodec.decodeResponse(response);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method release.
@Override
public void release(int permits) {
checkPositive(permits, "Permits must be positive!");
long clusterWideThreadId = sessionManager.getOrCreateUniqueThreadId(groupId);
UUID invocationUid = newUnsecureUUID();
ClientMessage request = SemaphoreReleaseCodec.encodeRequest(groupId, objectName, NO_SESSION_ID, clusterWideThreadId, invocationUid, permits);
HazelcastClientInstanceImpl client = getClient();
new ClientInvocation(client, request, objectName).invoke().joinInternal();
}
Aggregations