private void notifyChannels(CacheEntryEvent<Object, Object> event, Event.Type eventType) {
if(event.isPre()) {
return;
}
JsonObject jsonObject;
Cache<Object, Object> cache = event.getCache();
Object key = event.getKey();
Object value;
switch(eventType) {
case CACHE_ENTRY_CREATED:
// TODO: Add optimization ... don't get from cache if non of the channels are interested in creates...
value = cache.get(key);
jsonObject = ChannelUtils.toJSON(key.toString(), value, cache.getName());
break;
case CACHE_ENTRY_MODIFIED:
value = event.getValue();
jsonObject = ChannelUtils.toJSON(key.toString(), value, cache.getName());
break;
case CACHE_ENTRY_REMOVED:
jsonObject = ChannelUtils.toJSON(key.toString(), null, cache.getName());
break;
default:
return;
}
jsonObject.put("eventType", eventType.toString());
String jsonString = jsonObject.toString();
for(ChannelNotifyParams channel : channels) {
if(channel.channel.isOpen() && channel.onEvents.contains(eventType)) {
if(channel.key != null) {
if(event.getKey().equals(channel.key) || channel.key.equals("*")) {
channel.channel.writeAndFlush(new TextWebSocketFrame(jsonString));