Search in sources :

Example 11 with ClientInvocationFuture

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

the class TcpClientConnectionManager method authenticateOnCluster.

private ClientAuthenticationCodec.ResponseParameters authenticateOnCluster(TcpClientConnection connection) {
    Address memberAddress = connection.getInitAddress();
    ClientMessage request = encodeAuthenticationRequest(memberAddress);
    ClientInvocationFuture future = new ClientInvocation(client, request, null, connection).invokeUrgent();
    try {
        return ClientAuthenticationCodec.decodeResponse(future.get(authenticationTimeout, MILLISECONDS));
    } catch (Exception e) {
        connection.close("Failed to authenticate connection", e);
        throw rethrow(e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) EOFException(java.io.EOFException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 12 with ClientInvocationFuture

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

the class ClientScheduledExecutorProxy method getAllScheduledFutures.

@Nonnull
@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
    ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
    ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName()).invoke();
    ClientMessage response;
    try {
        response = future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
    Collection<ScheduledTaskHandler> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response);
    Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<>();
    for (ScheduledTaskHandler scheduledTaskHandler : urnsPerMember) {
        UUID memberUuid = scheduledTaskHandler.getUuid();
        Member member = getContext().getClusterService().getMember(memberUuid);
        tasksMap.compute(member, (BiFunctionEx<Member, List<IScheduledFuture<V>>, List<IScheduledFuture<V>>>) (m, iScheduledFutures) -> {
            if (iScheduledFutures == null) {
                iScheduledFutures = new LinkedList<>();
            }
            iScheduledFutures.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
            return iScheduledFutures;
        });
    }
    return tasksMap;
}
Also used : ScheduledExecutorShutdownCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorShutdownCodec) AutoDisposableTask(com.hazelcast.scheduledexecutor.AutoDisposableTask) FutureUtil(com.hazelcast.internal.util.FutureUtil) Member(com.hazelcast.cluster.Member) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) Level(java.util.logging.Level) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Future(java.util.concurrent.Future) ExceptionUtil.sneakyThrow(com.hazelcast.internal.util.ExceptionUtil.sneakyThrow) PartitionAware(com.hazelcast.partition.PartitionAware) ILogger(com.hazelcast.logging.ILogger) ClientContext(com.hazelcast.client.impl.spi.ClientContext) Map(java.util.Map) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) UuidUtil(com.hazelcast.internal.util.UuidUtil) ClientMessageDecoder(com.hazelcast.client.impl.clientside.ClientMessageDecoder) LinkedList(java.util.LinkedList) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Nonnull(javax.annotation.Nonnull) ScheduledExecutorGetAllScheduledFuturesCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorGetAllScheduledFuturesCodec) Logger(com.hazelcast.logging.Logger) AbstractTaskDecorator(com.hazelcast.scheduledexecutor.impl.AbstractTaskDecorator) Collection(java.util.Collection) FutureUtil.waitWithDeadline(com.hazelcast.internal.util.FutureUtil.waitWithDeadline) Data(com.hazelcast.internal.serialization.Data) TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition) UUID(java.util.UUID) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) ScheduledTaskHandlerImpl(com.hazelcast.scheduledexecutor.impl.ScheduledTaskHandlerImpl) ScheduledExecutorSubmitToPartitionCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorSubmitToPartitionCodec) TimeUnit(java.util.concurrent.TimeUnit) NamedTask(com.hazelcast.scheduledexecutor.NamedTask) List(java.util.List) SplitBrainProtectionException(com.hazelcast.splitbrainprotection.SplitBrainProtectionException) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ScheduledRunnableAdapter(com.hazelcast.scheduledexecutor.impl.ScheduledRunnableAdapter) ScheduledExecutorSubmitToMemberCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorSubmitToMemberCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) Collections(java.util.Collections) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SplitBrainProtectionException(com.hazelcast.splitbrainprotection.SplitBrainProtectionException) LinkedList(java.util.LinkedList) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Nonnull(javax.annotation.Nonnull)

Example 13 with ClientInvocationFuture

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

the class IExecutorDelegatingFuture method invokeCancelRequest.

private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException, ExecutionException {
    waitForRequestToBeSend();
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    if (partitionId > -1) {
        ClientMessage request = ExecutorServiceCancelOnPartitionCodec.encodeRequest(uuid, mayInterruptIfRunning);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, objectName, partitionId);
        ClientInvocationFuture f = clientInvocation.invoke();
        return ExecutorServiceCancelOnPartitionCodec.decodeResponse(f.get());
    } else {
        ClientMessage request = ExecutorServiceCancelOnMemberCodec.encodeRequest(uuid, member.getUuid(), mayInterruptIfRunning);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, objectName, member.getUuid());
        ClientInvocationFuture f = clientInvocation.invoke();
        return ExecutorServiceCancelOnMemberCodec.decodeResponse(f.get());
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 14 with ClientInvocationFuture

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

the class ClientRingbufferProxy method addAllAsync.

@Override
public InternalCompletableFuture<Long> addAllAsync(@Nonnull Collection<? extends E> collection, @Nonnull OverflowPolicy overflowPolicy) {
    checkNotNull(collection, "collection can't be null");
    checkNotNull(overflowPolicy, "overflowPolicy can't be null");
    checkFalse(collection.isEmpty(), "collection can't be empty");
    checkTrue(collection.size() <= MAX_BATCH_SIZE, "collection can't be larger than " + MAX_BATCH_SIZE);
    Collection<Data> dataCollection = objectToDataCollection(collection, getSerializationService());
    ClientMessage request = RingbufferAddAllCodec.encodeRequest(name, dataCollection, overflowPolicy.getId());
    try {
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(future, getSerializationService(), RingbufferAddAllCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) RingbufferAddAllCodec(com.hazelcast.client.impl.protocol.codec.RingbufferAddAllCodec) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 15 with ClientInvocationFuture

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

the class ClientRingbufferProxy method readManyAsync.

@Override
public InternalCompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, int minCount, int maxCount, IFunction<E, Boolean> filter) {
    checkSequence(startSequence);
    checkNotNegative(minCount, "minCount can't be smaller than 0");
    checkTrue(maxCount >= minCount, "maxCount should be equal or larger than minCount");
    try {
        capacity();
    } catch (Throwable e) {
        return completedExceptionally(e);
    }
    checkTrue(maxCount <= capacity, "the maxCount should be smaller than or equal to the capacity");
    checkTrue(maxCount <= MAX_BATCH_SIZE, "maxCount can't be larger than " + MAX_BATCH_SIZE);
    ClientMessage request = RingbufferReadManyCodec.encodeRequest(name, startSequence, minCount, maxCount, toData(filter));
    try {
        ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(invocationFuture, getSerializationService(), readManyAsyncResponseDecoder);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)65 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)44 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)34 Data (com.hazelcast.internal.serialization.Data)22 UUID (java.util.UUID)11 Nonnull (javax.annotation.Nonnull)6 ILogger (com.hazelcast.logging.ILogger)5 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 IterationPointer (com.hazelcast.internal.iteration.IterationPointer)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 CachePutCodec (com.hazelcast.client.impl.protocol.codec.CachePutCodec)3 DurableExecutorRetrieveResultCodec (com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec)3 Member (com.hazelcast.cluster.Member)3 ExecutionCallbackAdapter (com.hazelcast.executor.impl.ExecutionCallbackAdapter)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 AccessControlException (java.security.AccessControlException)3 List (java.util.List)3