Search in sources :

Example 31 with HazelcastClientInstanceImpl

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;
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 32 with HazelcastClientInstanceImpl

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);
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 33 with HazelcastClientInstanceImpl

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);
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 34 with HazelcastClientInstanceImpl

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);
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 35 with HazelcastClientInstanceImpl

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();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)59 Test (org.junit.Test)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)19 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)15 UUID (java.util.UUID)14 ClientConfig (com.hazelcast.client.config.ClientConfig)11 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)9 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)7 ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)6 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 TcpClientConnectionManager (com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager)4 Address (com.hazelcast.cluster.Address)4 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)4 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)4 LoadBalancer (com.hazelcast.client.LoadBalancer)3 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)3