Search in sources :

Example 31 with ClientInvocation

use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method isDone.

@Override
public boolean isDone() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorIsDoneFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            return ScheduledExecutorIsDoneFromAddressCodec.decodeResponse(response).response;
        } else {
            ClientMessage request = ScheduledExecutorIsDoneFromPartitionCodec.encodeRequest(schedulerName, taskName);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            return ScheduledExecutorIsDoneFromPartitionCodec.decodeResponse(response).response;
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 32 with ClientInvocation

use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method get0.

private V get0(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    if (address != null) {
        ClientMessage request = ScheduledExecutorGetResultFromAddressCodec.encodeRequest(schedulerName, taskName, address);
        ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get(timeout, unit);
        Data data = ScheduledExecutorGetResultFromAddressCodec.decodeResponse(response).response;
        return getSerializationService().toObject(data);
    } else {
        ClientMessage request = ScheduledExecutorGetResultFromPartitionCodec.encodeRequest(schedulerName, taskName);
        ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get(timeout, unit);
        Data data = ScheduledExecutorGetResultFromPartitionCodec.decodeResponse(response).response;
        return getSerializationService().toObject(data);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 33 with ClientInvocation

use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method dispose.

public void dispose() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorDisposeFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            new ClientInvocation(getClient(), request, address).invoke().get();
        } else {
            ClientMessage request = ScheduledExecutorDisposeFromPartitionCodec.encodeRequest(schedulerName, taskName);
            new ClientInvocation(getClient(), request, partitionId).invoke().get();
        }
        handler = null;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 34 with ClientInvocation

use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientTxnProxy method invoke.

final ClientMessage invoke(ClientMessage request) {
    try {
        HazelcastClientInstanceImpl client = transactionContext.getClient();
        ClientConnection connection = transactionContext.getConnection();
        ClientInvocation invocation = new ClientInvocation(client, request, connection);
        Future<ClientMessage> future = invocation.invoke();
        return future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 35 with ClientInvocation

use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class AbstractClientInternalCacheProxy method invoke.

protected ClientInvocationFuture invoke(ClientMessage req, int partitionId, int completionId) {
    boolean completionOperation = completionId != -1;
    if (completionOperation) {
        registerCompletionLatch(completionId, 1);
    }
    try {
        HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
        ClientInvocation clientInvocation = new ClientInvocation(client, req, partitionId);
        ClientInvocationFuture f = clientInvocation.invoke();
        if (completionOperation) {
            waitCompletionLatch(completionId, f);
        }
        return f;
    } catch (Throwable e) {
        if (e instanceof IllegalStateException) {
            close();
        }
        if (completionOperation) {
            deregisterCompletionLatch(completionId);
        }
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)52 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)25 Address (com.hazelcast.nio.Address)13 ExecutionException (java.util.concurrent.ExecutionException)13 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)10 Data (com.hazelcast.nio.serialization.Data)10 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)9 TimeoutException (java.util.concurrent.TimeoutException)9 StaleTaskException (com.hazelcast.scheduledexecutor.StaleTaskException)6 ArrayList (java.util.ArrayList)6 Future (java.util.concurrent.Future)6 Member (com.hazelcast.core.Member)5 SerializationService (com.hazelcast.spi.serialization.SerializationService)5 IOException (java.io.IOException)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 HazelcastException (com.hazelcast.core.HazelcastException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CacheException (javax.cache.CacheException)4