Search in sources :

Example 1 with ClientInvocation

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

the class HazelcastClientInstanceImpl method getDistributedObjects.

@Override
public Collection<DistributedObject> getDistributedObjects() {
    try {
        ClientMessage request = ClientGetDistributedObjectsCodec.encodeRequest();
        final Future<ClientMessage> future = new ClientInvocation(this, request).invoke();
        ClientMessage response = future.get();
        ClientGetDistributedObjectsCodec.ResponseParameters resultParameters = ClientGetDistributedObjectsCodec.decodeResponse(response);
        Collection<? extends DistributedObject> distributedObjects = proxyManager.getDistributedObjects();
        Set<DistributedObjectInfo> localDistributedObjects = new HashSet<DistributedObjectInfo>();
        for (DistributedObject localInfo : distributedObjects) {
            localDistributedObjects.add(new DistributedObjectInfo(localInfo.getServiceName(), localInfo.getName()));
        }
        Collection<DistributedObjectInfo> newDistributedObjectInfo = resultParameters.response;
        for (DistributedObjectInfo distributedObjectInfo : newDistributedObjectInfo) {
            localDistributedObjects.remove(distributedObjectInfo);
            getDistributedObject(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName());
        }
        for (DistributedObjectInfo distributedObjectInfo : localDistributedObjects) {
            proxyManager.removeProxy(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName());
        }
        return (Collection<DistributedObject>) proxyManager.getDistributedObjects();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) DistributedObjectInfo(com.hazelcast.client.impl.client.DistributedObjectInfo) Collection(java.util.Collection) ClientGetDistributedObjectsCodec(com.hazelcast.client.impl.protocol.codec.ClientGetDistributedObjectsCodec) HashSet(java.util.HashSet)

Example 2 with ClientInvocation

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

the class ClientInvokerWrapper method invoke.

@Override
public Object invoke(Object request) {
    checkNotNull(request, "request cannot be null");
    ClientInvocation invocation = new ClientInvocation(getClient(), (ClientMessage) request);
    ClientInvocationFuture future = invocation.invoke();
    try {
        Object result = future.get();
        return context.toObject(result);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 3 with ClientInvocation

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

the class ClientInvokerWrapper method invokeOnTarget.

@Override
public Future invokeOnTarget(Object request, Address address) {
    checkNotNull(request, "request cannot be null");
    checkNotNull(address, "address cannot be null");
    ClientMessage clientRequest = (ClientMessage) request;
    ClientInvocation invocation = new ClientInvocation(getClient(), clientRequest, address);
    return invocation.invoke();
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 4 with ClientInvocation

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

the class ClientCacheMetaDataFetcher method assignAndGetUuids.

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

Example 5 with ClientInvocation

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

the class ClientCacheMetaDataFetcher 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)

Aggregations

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