Search in sources :

Example 11 with ClientEndpoint

use of com.hazelcast.client.ClientEndpoint in project hazelcast by hazelcast.

the class AbstractInvocationMessageTask method processMessage.

@Override
protected void processMessage() {
    final ClientEndpoint endpoint = getEndpoint();
    Operation op = prepareOperation();
    op.setCallerUuid(endpoint.getUuid());
    InvocationBuilder builder = getInvocationBuilder(op).setExecutionCallback(this).setResultDeserialized(false);
    builder.invoke();
}
Also used : Operation(com.hazelcast.spi.Operation) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 12 with ClientEndpoint

use of com.hazelcast.client.ClientEndpoint in project hazelcast by hazelcast.

the class QueueAddListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    final QueueService service = getService(QueueService.SERVICE_NAME);
    final Data partitionKey = serializationService.toData(parameters.name);
    ItemListener listener = new ItemListener() {

        @Override
        public void itemAdded(ItemEvent item) {
            send(item);
        }

        @Override
        public void itemRemoved(ItemEvent item) {
            send(item);
        }

        private void send(ItemEvent event) {
            if (endpoint.isAlive()) {
                if (!(event instanceof DataAwareItemEvent)) {
                    throw new IllegalArgumentException("Expecting: DataAwareItemEvent, Found: " + event.getClass().getSimpleName());
                }
                DataAwareItemEvent dataAwareItemEvent = (DataAwareItemEvent) event;
                Data item = dataAwareItemEvent.getItemData();
                ClientMessage clientMessage = QueueAddListenerCodec.encodeItemEvent(item, event.getMember().getUuid(), event.getEventType().getType());
                sendClientMessage(partitionKey, clientMessage);
            }
        }
    };
    String registrationId = service.addItemListener(parameters.name, listener, parameters.includeValue, parameters.localOnly);
    endpoint.addListenerDestroyAction(QueueService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : DataAwareItemEvent(com.hazelcast.collection.impl.common.DataAwareItemEvent) ItemEvent(com.hazelcast.core.ItemEvent) DataAwareItemEvent(com.hazelcast.collection.impl.common.DataAwareItemEvent) QueueService(com.hazelcast.collection.impl.queue.QueueService) Data(com.hazelcast.nio.serialization.Data) ItemListener(com.hazelcast.core.ItemListener) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 13 with ClientEndpoint

use of com.hazelcast.client.ClientEndpoint in project hazelcast by hazelcast.

the class SetAddListenerMessageTask method call.

@Override
protected Object call() {
    ClientEndpoint endpoint = getEndpoint();
    Data partitionKey = serializationService.toData(parameters.name);
    ItemListener listener = createItemListener(endpoint, partitionKey);
    EventService eventService = clientEngine.getEventService();
    CollectionEventFilter filter = new CollectionEventFilter(parameters.includeValue);
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(getServiceName(), parameters.name, filter, listener);
    } else {
        registration = eventService.registerListener(getServiceName(), parameters.name, filter, listener);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(getServiceName(), parameters.name, registrationId);
    return registrationId;
}
Also used : CollectionEventFilter(com.hazelcast.collection.impl.collection.CollectionEventFilter) EventRegistration(com.hazelcast.spi.EventRegistration) Data(com.hazelcast.nio.serialization.Data) ItemListener(com.hazelcast.core.ItemListener) EventService(com.hazelcast.spi.EventService) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 14 with ClientEndpoint

use of com.hazelcast.client.ClientEndpoint in project hazelcast by hazelcast.

the class TopicAddMessageListenerMessageTask method call.

@Override
protected Object call() throws Exception {
    partitionKey = serializationService.toData(parameters.name);
    TopicService service = getService(TopicService.SERVICE_NAME);
    ClientEndpoint endpoint = getEndpoint();
    String registrationId = service.addMessageListener(parameters.name, this, parameters.localOnly);
    endpoint.addListenerDestroyAction(TopicService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : TopicService(com.hazelcast.topic.impl.TopicService) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 15 with ClientEndpoint

use of com.hazelcast.client.ClientEndpoint in project hazelcast by hazelcast.

the class AbstractMultiMapAddEntryListenerMessageTask method call.

@Override
protected Object call() throws Exception {
    final ClientEndpoint endpoint = getEndpoint();
    final MultiMapService service = getService(MultiMapService.SERVICE_NAME);
    EntryAdapter listener = new MultiMapListener();
    final String name = getDistributedObjectName();
    Data key = getKey();
    boolean includeValue = shouldIncludeValue();
    String registrationId = service.addListener(name, listener, key, includeValue, isLocalOnly());
    endpoint.addListenerDestroyAction(MultiMapService.SERVICE_NAME, name, registrationId);
    return registrationId;
}
Also used : MultiMapService(com.hazelcast.multimap.impl.MultiMapService) EntryAdapter(com.hazelcast.core.EntryAdapter) Data(com.hazelcast.nio.serialization.Data) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Aggregations

ClientEndpoint (com.hazelcast.client.ClientEndpoint)21 CacheService (com.hazelcast.cache.impl.CacheService)4 Data (com.hazelcast.nio.serialization.Data)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 ItemListener (com.hazelcast.core.ItemListener)3 EventRegistration (com.hazelcast.spi.EventRegistration)3 EventService (com.hazelcast.spi.EventService)3 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)3 CacheContext (com.hazelcast.cache.impl.CacheContext)2 ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)2 OperationFactoryWrapper (com.hazelcast.client.impl.operations.OperationFactoryWrapper)2 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)2 MapService (com.hazelcast.map.impl.MapService)2 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)2 EventFilter (com.hazelcast.spi.EventFilter)2 InvocationBuilder (com.hazelcast.spi.InvocationBuilder)2 OperationFactory (com.hazelcast.spi.OperationFactory)2 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)1