Search in sources :

Example 36 with ClientInvocation

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

the class ClientMapPartitionIterator method fetchWithoutPrefetchValues.

private List fetchWithoutPrefetchValues(HazelcastClientInstanceImpl client) {
    ClientMessage request = MapFetchKeysCodec.encodeRequest(mapProxy.getName(), partitionId, lastTableIndex, fetchSize);
    ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        MapFetchKeysCodec.ResponseParameters responseParameters = MapFetchKeysCodec.decodeResponse(f.get());
        setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
        return responseParameters.keys;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) MapFetchKeysCodec(com.hazelcast.client.impl.protocol.codec.MapFetchKeysCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 37 with ClientInvocation

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

the class ClientMapMetaDataFetcher method assignAndGetUuids.

@Override
public List<Map.Entry<Integer, UUID>> assignAndGetUuids() throws Exception {
    ClientMessage request = MapAssignAndGetUuidsCodec.encodeRequest();
    ClientInvocation invocation = new ClientInvocation(clientImpl, request);
    MapAssignAndGetUuidsCodec.ResponseParameters responseParameters = MapAssignAndGetUuidsCodec.decodeResponse(invocation.invoke().get());
    return responseParameters.partitionUuidList;
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapAssignAndGetUuidsCodec(com.hazelcast.client.impl.protocol.codec.MapAssignAndGetUuidsCodec)

Example 38 with ClientInvocation

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

the class ClientMapMetaDataFetcher method scanMembers.

@Override
protected List<InternalCompletableFuture> scanMembers(List<String> names) {
    Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    List<InternalCompletableFuture> futures = new ArrayList<InternalCompletableFuture>(members.size());
    for (Member member : members) {
        Address address = member.getAddress();
        ClientMessage message = encodeRequest(names, address);
        ClientInvocation invocation = new ClientInvocation(clientImpl, message, address);
        try {
            futures.add(invocation.invoke());
        } catch (Exception e) {
            if (logger.isWarningEnabled()) {
                logger.warning("Cant fetch invalidation meta-data from address + " + address + " + [" + e.getMessage() + "]");
            }
        }
    }
    return futures;
}
Also used : Address(com.hazelcast.nio.Address) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 39 with ClientInvocation

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

the class ClientConnectionManagerImpl method authenticate.

private void authenticate(final Address target, final ClientConnection connection, final boolean asOwner, final AuthenticationFuture callback) {
    SerializationService ss = client.getSerializationService();
    final ClientClusterServiceImpl clusterService = (ClientClusterServiceImpl) client.getClientClusterService();
    final ClientPrincipal principal = clusterService.getPrincipal();
    byte serializationVersion = ((InternalSerializationService) client.getSerializationService()).getVersion();
    String uuid = null;
    String ownerUuid = null;
    if (principal != null) {
        uuid = principal.getUuid();
        ownerUuid = principal.getOwnerUuid();
    }
    ClientMessage clientMessage = encodeAuthenticationRequest(asOwner, ss, serializationVersion, uuid, ownerUuid);
    ClientInvocation clientInvocation = new ClientInvocation(client, clientMessage, connection);
    ClientInvocationFuture future = clientInvocation.invokeUrgent();
    if (asOwner && clientInvocation.getSendConnection() != null) {
        correlationIddOfLastAuthentication.set(clientInvocation.getClientMessage().getCorrelationId());
    }
    future.andThen(new ExecutionCallback<ClientMessage>() {

        @Override
        public void onResponse(ClientMessage response) {
            ClientAuthenticationCodec.ResponseParameters result = ClientAuthenticationCodec.decodeResponse(response);
            AuthenticationStatus authenticationStatus = AuthenticationStatus.getById(result.status);
            switch(authenticationStatus) {
                case AUTHENTICATED:
                    connection.setConnectedServerVersion(result.serverHazelcastVersion);
                    connection.setRemoteEndpoint(result.address);
                    if (asOwner) {
                        if (!(correlationIddOfLastAuthentication.get() == response.getCorrelationId())) {
                            //if not same, client already gave up on this and send another authentication.
                            onFailure(new AuthenticationException("Owner authentication response from address " + target + " is late. Dropping the response. Principal : " + principal));
                            return;
                        }
                        connection.setIsAuthenticatedAsOwner();
                        ClientPrincipal principal = new ClientPrincipal(result.uuid, result.ownerUuid);
                        clusterService.setPrincipal(principal);
                        clusterService.setOwnerConnectionAddress(connection.getEndPoint());
                        logger.info("Setting " + connection + " as owner  with principal " + principal);
                    }
                    onAuthenticated(target, connection);
                    callback.onSuccess(connection, asOwner);
                    break;
                case CREDENTIALS_FAILED:
                    onFailure(new AuthenticationException("Invalid credentials! Principal: " + principal));
                    break;
                default:
                    onFailure(new AuthenticationException("Authentication status code not supported. status: " + authenticationStatus));
            }
        }

        @Override
        public void onFailure(Throwable t) {
            onAuthenticationFailed(target, connection, t);
            callback.onFailure(t);
        }
    });
}
Also used : AuthenticationException(com.hazelcast.client.AuthenticationException) SerializationService(com.hazelcast.spi.serialization.SerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientPrincipal(com.hazelcast.client.impl.client.ClientPrincipal) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) AuthenticationStatus(com.hazelcast.client.impl.protocol.AuthenticationStatus) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientClusterServiceImpl(com.hazelcast.client.spi.impl.ClientClusterServiceImpl)

Example 40 with ClientInvocation

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

the class ClientCacheHelper method enableStatisticManagementOnNodes.

/**
     * Enables/disables statistics or management support of cache on the all servers in the cluster.
     *
     * @param client    the client instance which will send the operation to server
     * @param cacheName full cache name with prefixes
     * @param statOrMan flag that represents which one of the statistics or management will be enabled
     * @param enabled   flag which represents whether it is enable or disable
     */
static void enableStatisticManagementOnNodes(HazelcastClientInstanceImpl client, String cacheName, boolean statOrMan, boolean enabled) {
    Collection<Member> members = client.getClientClusterService().getMemberList();
    Collection<Future> futures = new ArrayList<Future>();
    for (Member member : members) {
        try {
            Address address = member.getAddress();
            ClientMessage request = CacheManagementConfigCodec.encodeRequest(cacheName, statOrMan, enabled, address);
            ClientInvocation clientInvocation = new ClientInvocation(client, request, address);
            Future<ClientMessage> future = clientInvocation.invoke();
            futures.add(future);
        } catch (Exception e) {
            sneakyThrow(e);
        }
    }
    // make sure all configs are created
    FutureUtil.waitWithDeadline(futures, CacheProxyUtil.AWAIT_COMPLETION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
Also used : Address(com.hazelcast.nio.Address) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) IOException(java.io.IOException)

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