Search in sources :

Example 1 with DataAwareMessage

use of com.hazelcast.topic.impl.DataAwareMessage 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)

Aggregations

ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 Data (com.hazelcast.nio.serialization.Data)1 DataAwareMessage (com.hazelcast.topic.impl.DataAwareMessage)1