package org.shame.cache; import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.opensymphony.oscache.base.Cache; import com.opensymphony.oscache.base.events.CacheEntryEvent; import com.opensymphony.oscache.base.events.CacheEntryEventListener; import com.opensymphony.oscache.plugins.clustersupport.ClusterNotification; import com.opensymphony.oscache.plugins.clustersupport.JavaGroupsBroadcastingListener; public class UpdatingJavaGroupsListener extends JavaGroupsBroadcastingListener implements CacheEntryEventListener{ private final static Log log = LogFactory.getLog( JavaGroupsBroadcastingListener.class ); public static final int REMOVE_KEY = 1555; public void cacheEntryUpdated( CacheEntryEvent event ) { if( !Cache.NESTED_EVENT.equals( event.getOrigin() ) && !CLUSTER_ORIGIN.equals( event.getOrigin() ) ) { if( log.isDebugEnabled() ) { log.debug( "cacheEntryUpdated called (" + event + ")" ); } sendNotification( new ClusterNotification( REMOVE_KEY, event.getKey() ) ); } } public void handleClusterNotification(ClusterNotification message) { if (cache == null) { log.warn("A cluster notification (" + message + ") was received, but no cache is registered on this machine. Notification ignored."); return; } if (log.isInfoEnabled()) { log.info("Cluster notification (" + message + ") was received."); } switch (message.getType()) { case ClusterNotification.FLUSH_KEY: cache.flushEntry((String) message.getData(), CLUSTER_ORIGIN); break; case ClusterNotification.FLUSH_GROUP: cache.flushGroup((String) message.getData(), CLUSTER_ORIGIN); break; case ClusterNotification.FLUSH_PATTERN: cache.flushPattern((String) message.getData(), CLUSTER_ORIGIN); break; case ClusterNotification.FLUSH_CACHE: cache.flushAll((Date) message.getData(), CLUSTER_ORIGIN); break; case REMOVE_KEY: String key = (String) message.getData(); log.error("!!!remove key "+key); cache.removeEntry(((String) message.getData()),CLUSTER_ORIGIN ); break; default: log.error("The cluster notification (" + message + ") is of an unknown type. Notification ignored."); } } }