Search in sources :

Example 16 with ClientInvocation

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

the class TransactionProxy method invoke.

private ClientMessage invoke(ClientMessage request) {
    try {
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, connection);
        final Future<ClientMessage> future = clientInvocation.invoke();
        return future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException)

Example 17 with ClientInvocation

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

the class ClientSmartListenerService method deregisterListener.

@Override
public boolean deregisterListener(final String userRegistrationId) {
    Future<Boolean> future = registrationExecutor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            ClientRegistrationKey key = new ClientRegistrationKey(userRegistrationId);
            Map<Connection, ClientEventRegistration> registrationMap = registrations.get(key);
            if (registrationMap == null) {
                return false;
            }
            boolean successful = true;
            for (ClientEventRegistration registration : registrationMap.values()) {
                Connection subscriber = registration.getSubscriber();
                try {
                    ListenerMessageCodec listenerMessageCodec = registration.getCodec();
                    String serverRegistrationId = registration.getServerRegistrationId();
                    ClientMessage request = listenerMessageCodec.encodeRemoveRequest(serverRegistrationId);
                    new ClientInvocation(client, request, subscriber).invoke().get();
                    removeEventHandler(registration.getCallId());
                    registrationMap.remove(subscriber);
                } catch (Exception e) {
                    successful = false;
                    logger.warning("Deregistration of listener with id " + userRegistrationId + " has failed to address " + subscriber.getEndPoint(), e);
                }
            }
            if (successful) {
                registrations.remove(key);
            }
            return successful;
        }
    });
    try {
        return future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) ListenerMessageCodec(com.hazelcast.client.spi.impl.ListenerMessageCodec) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 18 with ClientInvocation

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

the class ClientAddressCancellableDelegatingFuture method invokeCancelRequest.

private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException {
    waitForRequestToBeSend();
    ClientInvocation clientInvocation;
    final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    ClientMessage request = ExecutorServiceCancelOnAddressCodec.encodeRequest(uuid, target, mayInterruptIfRunning);
    clientInvocation = new ClientInvocation(client, request, target);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        return ExecutorServiceCancelOnAddressCodec.decodeResponse(f.get()).response;
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CancellationException(java.util.concurrent.CancellationException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 19 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 20 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)

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