package org.jboss.ejb.plugins;
import org.jboss.deployment.DeploymentException;
import org.jboss.ha.framework.interfaces.DistributedState;
import org.jboss.metadata.ClusterConfigMetaData;
import org.jboss.system.Registry;
public class ClusterSyncEntityInstanceCache
extends EntityInstanceCache
implements org.jboss.ha.framework.interfaces.DistributedState.DSListenerEx
{
protected DistributedState ds = null;
protected String DS_CATEGORY = null;
public void create() throws Exception
{
super.create ();
ClusterConfigMetaData config = getContainer().getBeanMetaData().getClusterConfigMetaData();
String partitionName = config.getPartitionName();
String name = "jboss:service=DistributedState,partitionName=" + partitionName;
ds = (DistributedState) Registry.lookup (name);
if( ds == null )
throw new DeploymentException("Failed to find DistributedState service: "+name);
}
public void start() throws Exception
{
super.start ();
String ejbName = this.getContainer ().getBeanMetaData ().getEjbName ();
this.DS_CATEGORY = "CMPClusteredInMemoryPersistenceManager-" + ejbName;
this.ds.registerDSListenerEx (this.DS_CATEGORY, this);
}
public void stop()
{
super.stop ();
this.ds.unregisterDSListenerEx (this.DS_CATEGORY, this);
}
public void keyHasBeenRemoved (String category, java.io.Serializable key, java.io.Serializable previousContent, boolean locallyModified)
{
if (!locallyModified)
this.cacheMiss ((String)key);
}
public void valueHasChanged (String category, java.io.Serializable key, java.io.Serializable value, boolean locallyModified)
{
if (!locallyModified)
this.cacheMiss ((String)key);
}
public void cacheMiss(String key)
{
try
{
this.remove(key);
}
catch (Exception e)
{
log.warn("failed to remove key" ,e);
}
}
}