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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations