use of com.hazelcast.collection.ItemEvent in project hazelcast by hazelcast.
the class QueueAddListenerMessageTask method processInternal.
@Override
protected CompletableFuture<UUID> processInternal() {
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);
}
}
};
if (parameters.localOnly) {
return newCompletedFuture(service.addLocalItemListener(parameters.name, listener, parameters.includeValue));
}
return service.addItemListenerAsync(parameters.name, listener, parameters.includeValue);
}
use of com.hazelcast.collection.ItemEvent in project hazelcast by hazelcast.
the class SetAddListenerMessageTask method createItemListener.
private ItemListener createItemListener(final ClientEndpoint endpoint, final Data partitionKey) {
return 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 = SetAddListenerCodec.encodeItemEvent(item, event.getMember().getUuid(), event.getEventType().getType());
sendClientMessage(partitionKey, clientMessage);
}
}
};
}
Aggregations