Search in sources :

Example 1 with CachePutAllEvent

use of com.alicp.jetcache.event.CachePutAllEvent in project jetcache by alibaba.

the class DefaultCacheMonitorManager method addCacheUpdateMonitor.

protected void addCacheUpdateMonitor(String area, String cacheName, Cache cache) {
    if (cacheMessagePublisher != null) {
        CacheMonitor monitor = event -> {
            if (event instanceof CachePutEvent) {
                CacheMessage m = new CacheMessage();
                CachePutEvent e = (CachePutEvent) event;
                m.setType(CacheMessage.TYPE_PUT);
                m.setKeys(new Object[] { e.getKey() });
                cacheMessagePublisher.publish(area, cacheName, m);
            } else if (event instanceof CacheRemoveEvent) {
                CacheMessage m = new CacheMessage();
                CacheRemoveEvent e = (CacheRemoveEvent) event;
                m.setType(CacheMessage.TYPE_REMOVE);
                m.setKeys(new Object[] { e.getKey() });
                cacheMessagePublisher.publish(area, cacheName, m);
            } else if (event instanceof CachePutAllEvent) {
                CacheMessage m = new CacheMessage();
                CachePutAllEvent e = (CachePutAllEvent) event;
                m.setType(CacheMessage.TYPE_PUT_ALL);
                if (e.getMap() != null) {
                    m.setKeys(e.getMap().keySet().toArray());
                }
                cacheMessagePublisher.publish(area, cacheName, m);
            } else if (event instanceof CacheRemoveAllEvent) {
                CacheMessage m = new CacheMessage();
                CacheRemoveAllEvent e = (CacheRemoveAllEvent) event;
                m.setType(CacheMessage.TYPE_REMOVE_ALL);
                if (e.getKeys() != null) {
                    m.setKeys(e.getKeys().toArray());
                }
                cacheMessagePublisher.publish(area, cacheName, m);
            }
        };
        cache.config().getMonitors().add(monitor);
    }
}
Also used : Cache(com.alicp.jetcache.Cache) CacheRemoveEvent(com.alicp.jetcache.event.CacheRemoveEvent) Resource(javax.annotation.Resource) Autowired(org.springframework.beans.factory.annotation.Autowired) CachePutAllEvent(com.alicp.jetcache.event.CachePutAllEvent) CacheUtil(com.alicp.jetcache.CacheUtil) CachePutEvent(com.alicp.jetcache.event.CachePutEvent) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CacheMonitor(com.alicp.jetcache.CacheMonitor) MultiLevelCache(com.alicp.jetcache.MultiLevelCache) CacheRemoveAllEvent(com.alicp.jetcache.event.CacheRemoveAllEvent) com.alicp.jetcache.support(com.alicp.jetcache.support) CacheMonitor(com.alicp.jetcache.CacheMonitor) CachePutEvent(com.alicp.jetcache.event.CachePutEvent) CacheRemoveEvent(com.alicp.jetcache.event.CacheRemoveEvent) CachePutAllEvent(com.alicp.jetcache.event.CachePutAllEvent) CacheRemoveAllEvent(com.alicp.jetcache.event.CacheRemoveAllEvent)

Aggregations

Cache (com.alicp.jetcache.Cache)1 CacheMonitor (com.alicp.jetcache.CacheMonitor)1 CacheUtil (com.alicp.jetcache.CacheUtil)1 MultiLevelCache (com.alicp.jetcache.MultiLevelCache)1 CachePutAllEvent (com.alicp.jetcache.event.CachePutAllEvent)1 CachePutEvent (com.alicp.jetcache.event.CachePutEvent)1 CacheRemoveAllEvent (com.alicp.jetcache.event.CacheRemoveAllEvent)1 CacheRemoveEvent (com.alicp.jetcache.event.CacheRemoveEvent)1 com.alicp.jetcache.support (com.alicp.jetcache.support)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Resource (javax.annotation.Resource)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1