use of com.hazelcast.collection.impl.common.DataAwareItemEvent in project hazelcast by hazelcast.
the class CollectionService method dispatchEvent.
@Override
public void dispatchEvent(CollectionEvent event, ItemListener<Data> listener) {
final MemberImpl member = nodeEngine.getClusterService().getMember(event.getCaller());
ItemEvent<Data> itemEvent = new DataAwareItemEvent<Data>(event.getName(), event.getEventType(), event.getData(), member, serializationService);
if (member == null) {
if (logger.isInfoEnabled()) {
logger.info("Dropping event " + itemEvent + " from unknown address:" + event.getCaller());
}
return;
}
if (event.getEventType().equals(ItemEventType.ADDED)) {
listener.itemAdded(itemEvent);
} else {
listener.itemRemoved(itemEvent);
}
}
use of com.hazelcast.collection.impl.common.DataAwareItemEvent in project hazelcast by hazelcast.
the class ListAddListenerMessageTask 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 = ListAddListenerCodec.encodeItemEvent(item, event.getMember().getUuid(), event.getEventType().getType());
sendClientMessage(partitionKey, clientMessage);
}
}
};
}
Aggregations