Search in sources :

Example 16 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method release.

@Override
public void release(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long sessionId = sessionManager.getSession(groupId);
    if (sessionId == NO_SESSION_ID) {
        throw newIllegalStateException(null);
    }
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    try {
        ClientMessage request = SemaphoreReleaseCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits);
        HazelcastClientInstanceImpl client = getClient();
        new ClientInvocation(client, request, objectName).invoke().joinInternal();
    } catch (SessionExpiredException e) {
        sessionManager.invalidateSession(this.groupId, sessionId);
        throw newIllegalStateException(e);
    } finally {
        sessionManager.releaseSession(this.groupId, sessionId, permits);
    }
}
Also used : 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 17 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy 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 18 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method drainPermits.

@Override
public int drainPermits() {
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = sessionManager.acquireSession(this.groupId, DRAIN_SESSION_ACQ_COUNT);
        try {
            ClientMessage request = SemaphoreDrainCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid);
            HazelcastClientInstanceImpl client = getClient();
            ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
            int count = SemaphoreDrainCodec.decodeResponse(response);
            sessionManager.releaseSession(groupId, sessionId, DRAIN_SESSION_ACQ_COUNT - count);
            return count;
        } catch (SessionExpiredException e) {
            sessionManager.invalidateSession(this.groupId, sessionId);
        } catch (RuntimeException e) {
            sessionManager.releaseSession(this.groupId, sessionId, DRAIN_SESSION_ACQ_COUNT);
            throw e;
        }
    }
}
Also used : 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 19 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientMapQueryPartitionIterator method fetch.

@Override
protected List<Data> fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    ClientMessage request = MapFetchWithQueryCodec.encodeRequest(mapProxy.getName(), encodePointers(pointers), fetchSize, getSerializationService().toData(query.getProjection()), getSerializationService().toData(query.getPredicate()));
    ClientInvocation clientInvocation = new ClientInvocation(client, request, mapProxy.getName(), partitionId);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        MapFetchWithQueryCodec.ResponseParameters responseParameters = MapFetchWithQueryCodec.decodeResponse(f.get());
        List<Data> results = responseParameters.results;
        IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
        setLastTableIndex(results, pointers);
        return results;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : IterationPointer(com.hazelcast.internal.iteration.IterationPointer) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapFetchWithQueryCodec(com.hazelcast.client.impl.protocol.codec.MapFetchWithQueryCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 20 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractListenersOnReconnectTest method testListenersTerminateRandomNode.

private void testListenersTerminateRandomNode(boolean isSmartClient) {
    factory.newInstances(null, 3);
    ClientConfig clientConfig = createClientConfig(isSmartClient);
    client = factory.newHazelcastClient(clientConfig);
    setupListener();
    terminateRandomNode();
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final CountDownLatch memberAddedLatch = new CountDownLatch(1);
    clientInstanceImpl.getClientClusterService().addMembershipListener(new MembershipListener() {

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
            memberAddedLatch.countDown();
        }

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
        }
    });
    factory.newHazelcastInstance();
    assertOpenEventually(memberAddedLatch);
    validateRegistrationsAndListenerFunctionality();
}
Also used : MembershipEvent(com.hazelcast.cluster.MembershipEvent) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.cluster.MembershipListener)

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