Search in sources :

Example 81 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy method scheduleOnMember.

private <V> IScheduledFuture<V> scheduleOnMember(String name, Member member, TaskDefinition definition) {
    TimeUnit unit = definition.getUnit();
    Data commandData = getSerializationService().toData(definition.getCommand());
    ClientMessage request = ScheduledExecutorSubmitToAddressCodec.encodeRequest(getName(), member.getAddress(), definition.getType().getId(), definition.getName(), commandData, unit.toMillis(definition.getInitialDelay()), unit.toMillis(definition.getPeriod()));
    try {
        new ClientInvocation(getClient(), request, member.getAddress()).invoke().get();
    } catch (Exception e) {
        throw rethrow(e);
    }
    return createFutureProxy(member.getAddress(), name);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 82 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy method getAllScheduledFutures.

@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
    ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
    final ClientInvocationFuture future = new ClientInvocation(getClient(), request).invoke();
    ClientMessage response;
    try {
        response = future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
    Collection<Map.Entry<Member, List<ScheduledTaskHandler>>> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response).handlers;
    Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<Member, List<IScheduledFuture<V>>>();
    for (Map.Entry<Member, List<ScheduledTaskHandler>> entry : urnsPerMember) {
        List<IScheduledFuture<V>> memberTasks = new ArrayList<IScheduledFuture<V>>();
        for (ScheduledTaskHandler scheduledTaskHandler : entry.getValue()) {
            memberTasks.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
        }
        tasksMap.put(entry.getKey(), memberTasks);
    }
    return tasksMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Member(com.hazelcast.core.Member) HashMap(java.util.HashMap) Map(java.util.Map)

Example 83 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method getStats.

@Override
public ScheduledTaskStatistics getStats() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorGetStatsFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
            return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
        } else {
            ClientMessage request = ScheduledExecutorGetStatsFromPartitionCodec.encodeRequest(schedulerName, taskName);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
            return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
        }
    } 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) ScheduledExecutorGetStatsFromAddressCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorGetStatsFromAddressCodec) ScheduledTaskStatisticsImpl(com.hazelcast.scheduledexecutor.impl.ScheduledTaskStatisticsImpl) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 84 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method cancel.

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
    if (mayInterruptIfRunning) {
        // inside the TaskRunner but it adds extra complexity.
        throw new UnsupportedOperationException("mayInterruptIfRunning flag is not supported.");
    }
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorCancelFromAddressCodec.encodeRequest(schedulerName, taskName, address, false);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            return ScheduledExecutorCancelFromAddressCodec.decodeResponse(response).response;
        } else {
            ClientMessage request = ScheduledExecutorCancelFromPartitionCodec.encodeRequest(schedulerName, taskName, false);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            return ScheduledExecutorCancelFromPartitionCodec.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 85 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method isCancelled.

@Override
public boolean isCancelled() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorIsCancelledFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            return ScheduledExecutorIsCancelledFromAddressCodec.decodeResponse(response).response;
        } else {
            ClientMessage request = ScheduledExecutorIsCancelledFromPartitionCodec.encodeRequest(schedulerName, taskName);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            return ScheduledExecutorIsCancelledFromPartitionCodec.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)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)377 Data (com.hazelcast.nio.serialization.Data)140 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)37 SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)29 Address (com.hazelcast.nio.Address)25 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)21 DataInputStream (java.io.DataInputStream)20 InputStream (java.io.InputStream)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 ParallelTest (com.hazelcast.test.annotation.ParallelTest)19 Member (com.hazelcast.core.Member)18 SerializationService (com.hazelcast.spi.serialization.SerializationService)18 ExecutionException (java.util.concurrent.ExecutionException)18 UnmodifiableLazyList (com.hazelcast.spi.impl.UnmodifiableLazyList)16 ArrayList (java.util.ArrayList)16 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)13 CacheException (javax.cache.CacheException)13