use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class SessionAwareSemaphoreProxy method onDestroy.
@Override
public void onDestroy() {
ClientMessage request = CPGroupDestroyCPObjectCodec.encodeRequest(groupId, getServiceName(), objectName);
new ClientInvocation(getClient(), request, name).invoke().joinInternal();
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class SessionAwareSemaphoreProxy method tryAcquire.
@Override
public boolean tryAcquire(int permits, long timeout, TimeUnit unit) {
checkPositive(permits, "Permits must be positive!");
long timeoutMs = max(0, unit.toMillis(timeout));
long threadId = getThreadId();
UUID invocationUid = newUnsecureUUID();
long start;
for (; ; ) {
start = Clock.currentTimeMillis();
long sessionId = sessionManager.acquireSession(this.groupId, permits);
try {
ClientMessage request = SemaphoreAcquireCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits, timeoutMs);
HazelcastClientInstanceImpl client = getClient();
ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
boolean acquired = SemaphoreAcquireCodec.decodeResponse(response);
if (!acquired) {
sessionManager.releaseSession(this.groupId, sessionId, permits);
}
return acquired;
} catch (SessionExpiredException e) {
sessionManager.invalidateSession(this.groupId, sessionId);
timeoutMs -= (Clock.currentTimeMillis() - start);
if (timeoutMs <= 0) {
return false;
}
} catch (WaitKeyCancelledException e) {
sessionManager.releaseSession(this.groupId, sessionId, permits);
return false;
} catch (RuntimeException e) {
sessionManager.releaseSession(this.groupId, sessionId, permits);
throw e;
}
}
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation 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.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class AtomicLongProxy method addAndGetAsync.
@Override
public InternalCompletableFuture<Long> addAndGetAsync(long delta) {
ClientMessage request = AtomicLongAddAndGetCodec.encodeRequest(groupId, objectName, delta);
ClientInvocationFuture future = new ClientInvocation(getClient(), request, name).invoke();
return new ClientDelegatingFuture<>(future, getSerializationService(), AtomicLongAddAndGetCodec::decodeResponse);
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class AtomicLongProxy method onDestroy.
@Override
public void onDestroy() {
ClientMessage request = CPGroupDestroyCPObjectCodec.encodeRequest(groupId, getServiceName(), objectName);
new ClientInvocation(getClient(), request, name).invoke().joinInternal();
}
Aggregations