Search in sources :

Example 56 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class AddPartitionLostListenerMessageTask method call.

@Override
protected Object call() throws Exception {
    final IPartitionService partitionService = getService(getServiceName());
    final PartitionLostListener listener = new PartitionLostListener() {

        @Override
        public void partitionLost(PartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), event.getEventSource());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    String registrationId;
    if (parameters.localOnly) {
        registrationId = partitionService.addLocalPartitionLostListener(listener);
    } else {
        registrationId = partitionService.addPartitionLostListener(listener);
    }
    endpoint.addListenerDestroyAction(getServiceName(), PARTITION_LOST_EVENT_TOPIC, registrationId);
    return registrationId;
}
Also used : PartitionLostListener(com.hazelcast.partition.PartitionLostListener) IPartitionService(com.hazelcast.spi.partition.IPartitionService) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 57 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage 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 58 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class TopicAddMessageListenerMessageTask method onMessage.

@Override
public void onMessage(Message message) {
    if (!endpoint.isAlive()) {
        return;
    }
    if (!(message instanceof DataAwareMessage)) {
        throw new IllegalArgumentException("Expecting: DataAwareMessage, Found: " + message.getClass().getSimpleName());
    }
    DataAwareMessage dataAwareMessage = (DataAwareMessage) message;
    Data messageData = dataAwareMessage.getMessageData();
    String publisherUuid = message.getPublishingMember().getUuid();
    ClientMessage eventMessage = TopicAddMessageListenerCodec.encodeTopicEvent(messageData, message.getPublishTime(), publisherUuid);
    boolean isMultithreaded = nodeEngine.getConfig().getTopicConfig(parameters.name).isMultiThreadingEnabled();
    if (isMultithreaded) {
        int key = rand.nextInt();
        int partitionId = hashToIndex(key, nodeEngine.getPartitionService().getPartitionCount());
        eventMessage.setPartitionId(partitionId);
        sendClientMessage(eventMessage);
    } else {
        sendClientMessage(partitionKey, eventMessage);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) DataAwareMessage(com.hazelcast.topic.impl.DataAwareMessage) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 59 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class AbstractReplicatedMapAddEntryListenerMessageTask method handleEvent.

private void handleEvent(EntryEvent<Object, Object> event) {
    if (!shouldSendEvent(event)) {
        return;
    }
    Data key = serializationService.toData(event.getKey());
    Data newValue = serializationService.toData(event.getValue());
    Data oldValue = serializationService.toData(event.getOldValue());
    Data mergingValue = serializationService.toData(event.getMergingValue());
    ClientMessage clientMessage = encodeEvent(key, newValue, oldValue, mergingValue, event.getEventType().getType(), event.getMember().getUuid(), 1);
    sendClientMessage(key, clientMessage);
}
Also used : Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 60 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageSplitter method getSubFrame.

static ClientMessage getSubFrame(int frameSize, int frameIndex, int numberOfSubFrames, ClientMessage originalClientMessage) {
    assert frameIndex > -1;
    assert frameIndex < numberOfSubFrames;
    assert ClientMessage.HEADER_SIZE < frameSize;
    int frameLength = originalClientMessage.getFrameLength();
    if (frameSize > frameLength) {
        assert frameIndex == 0;
        return originalClientMessage;
    }
    int subFrameMaxDataLength = frameSize - ClientMessage.HEADER_SIZE;
    int startOffset = ClientMessage.HEADER_SIZE + frameIndex * subFrameMaxDataLength;
    int subFrameDataLength = numberOfSubFrames != frameIndex + 1 ? subFrameMaxDataLength : frameLength - startOffset;
    ClientMessage subFrame = ClientMessage.createForEncode(ClientMessage.HEADER_SIZE + subFrameDataLength);
    System.arraycopy(originalClientMessage.buffer.byteArray(), startOffset, subFrame.buffer.byteArray(), subFrame.getDataOffset(), subFrameDataLength);
    if (frameIndex == 0) {
        subFrame.addFlag(ClientMessage.BEGIN_FLAG);
    } else if (numberOfSubFrames == frameIndex + 1) {
        subFrame.addFlag(ClientMessage.END_FLAG);
    }
    subFrame.setPartitionId(originalClientMessage.getPartitionId());
    subFrame.setFrameLength(ClientMessage.HEADER_SIZE + subFrameDataLength);
    subFrame.setMessageType(originalClientMessage.getMessageType());
    subFrame.setRetryable(originalClientMessage.isRetryable());
    subFrame.setCorrelationId(originalClientMessage.getCorrelationId());
    return subFrame;
}
Also used : ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)377 Data (com.hazelcast.nio.serialization.Data)140 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)37 SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)29 Address (com.hazelcast.nio.Address)25 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)21 DataInputStream (java.io.DataInputStream)20 InputStream (java.io.InputStream)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 ParallelTest (com.hazelcast.test.annotation.ParallelTest)19 Member (com.hazelcast.core.Member)18 SerializationService (com.hazelcast.spi.serialization.SerializationService)18 ExecutionException (java.util.concurrent.ExecutionException)18 UnmodifiableLazyList (com.hazelcast.spi.impl.UnmodifiableLazyList)16 ArrayList (java.util.ArrayList)16 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)13 CacheException (javax.cache.CacheException)13