@Override public void notifyEntryPut(PortalCache<K, V> portalCache, K key, V value, int timeToLive) throws PortalCacheException { if (!_replicatePuts) { return; } PortalCacheManager<K, V> portalCacheManager = portalCache.getPortalCacheManager(); PortalCacheClusterEvent portalCacheClusterEvent = new PortalCacheClusterEvent( portalCacheManager.getName(), portalCache.getName(), key, PortalCacheClusterEventType.PUT); if (_replicatePutsViaCopy) { portalCacheClusterEvent.setElementValue(value); portalCacheClusterEvent.setTimeToLive(timeToLive); } PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent); }
@Override protected void doReceive(Message message) throws Exception { PortalCacheClusterEvent portalCacheClusterEvent = (PortalCacheClusterEvent) message.getPayload(); if (portalCacheClusterEvent == null) { if (_log.isWarnEnabled()) { _log.warn("Payload is null"); } return; } String cacheName = portalCacheClusterEvent.getCacheName(); Ehcache ehcache = _portalCacheManager.getEhcache(cacheName); if (ehcache == null) { ehcache = _hibernateCacheManager.getEhcache(cacheName); } if (ehcache != null) { PortalCacheClusterEventType portalCacheClusterEventType = portalCacheClusterEvent.getEventType(); if (portalCacheClusterEventType.equals(PortalCacheClusterEventType.REMOVEALL)) { ehcache.removeAll(true); } else if (portalCacheClusterEventType.equals(PortalCacheClusterEventType.PUT) || portalCacheClusterEventType.equals(PortalCacheClusterEventType.UPDATE)) { Serializable elementKey = portalCacheClusterEvent.getElementKey(); Serializable elementValue = portalCacheClusterEvent.getElementValue(); if (elementValue == null) { ehcache.remove(portalCacheClusterEvent.getElementKey(), true); } else { Element oldElement = ehcache.get(elementKey); Element newElement = new Element(elementKey, elementValue); if (oldElement != null) { ehcache.replace(newElement); } else { ehcache.put(newElement); } } } else { ehcache.remove(portalCacheClusterEvent.getElementKey(), true); } } }