[jboss-cvs] JBossAS SVN: r63975 - trunk/cluster/src/main/org/jboss/ha/framework/server.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 11 12:49:09 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-07-11 12:49:09 -0400 (Wed, 11 Jul 2007)
New Revision: 63975
Modified:
trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
Log:
[JBAS-4535] Convert to the notification API introduced in 2.0.0.CR3
Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java 2007-07-11 15:24:00 UTC (rev 63974)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java 2007-07-11 16:49:09 UTC (rev 63975)
@@ -32,11 +32,14 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.logging.Logger;
import org.jboss.system.ServiceMBeanSupport;
@@ -49,6 +52,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
+ at CacheListener
public class DistributedStateImpl
extends ServiceMBeanSupport
implements DistributedStateImplMBean
@@ -68,7 +72,6 @@
// protected MBeanServer mbeanServer = null;
protected String name = null;
protected Cache cache;
- private DSCacheListener cacheListener;
public static final String ROOT = "__DISTRIBUTED_STATE__";
@@ -84,7 +87,6 @@
{
super();
this.log = Logger.getLogger (this.getClass ());
- this.cacheListener = new DSCacheListener();
}
// Public --------------------------------------------------------
@@ -144,7 +146,7 @@
public void destroyService() throws Exception
{
super.destroyService();
- cache.removeCacheListener(cacheListener);
+ cache.removeCacheListener(this);
// Registry.unbind (this.name);
// ObjectName jmxName = new ObjectName(this.name);
// mbeanServer.unregisterMBean (jmxName);
@@ -224,7 +226,8 @@
public void setClusteredCache(Cache cache)
{
this.cache = cache;
- this.cache.addCacheListener(cacheListener);
+ if (this.cache != null)
+ this.cache.addCacheListener(this);
}
// DistributedState implementation ----------------------------------------------
@@ -508,35 +511,39 @@
return cache.getRoot().getChild(buildFqn(category));
}
- // Inner classes -------------------------------------------------
+ // @CacheListener -------------------------------------------------
- private class DSCacheListener extends AbstractCacheListener
+ @NodeModified
+ public void nodeModified(NodeModifiedEvent event)
{
- public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data) {
-
- // we don't want pre-notifications or changes for other roots in a shared cache
- if (pre || !fqn.isChildOf(ROOTFQN))
- return;
-
- // we're only interested in put and remove data operations
- if (!modType.equals(ModificationType.PUT_DATA) && !modType.equals(ModificationType.REMOVE_DATA))
- return;
-
- Serializable key = null;
- Serializable value = null;
-
- // there should be exactly one key/value pair in the map
- if (data != null && !data.isEmpty())
- {
- key = (Serializable)data.keySet().iterator().next();
- value = (Serializable)data.get(key);
- }
-
- if (modType.equals(ModificationType.PUT_DATA))
- DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), key, value, isLocal);
- else
- DistributedStateImpl.this.notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), key, value, isLocal);
- }
+ if (event.isPre())
+ return;
+
+ // ignore changes for other roots in a shared cache
+ Fqn fqn = event.getFqn();
+ if (!fqn.isChildOf(ROOTFQN))
+ return;
+
+ // we're only interested in put and remove data operations
+ ModificationType modType = event.getModificationType();
+ if (!modType.equals(ModificationType.PUT_DATA) && !modType.equals(ModificationType.REMOVE_DATA))
+ return;
+
+ Serializable key = null;
+ Serializable value = null;
+
+ // there should be exactly one key/value pair in the map
+ Map data = event.getData();
+ if (data != null && !data.isEmpty())
+ {
+ key = (Serializable)data.keySet().iterator().next();
+ value = (Serializable)data.get(key);
+ }
+
+ if (modType.equals(ModificationType.PUT_DATA))
+ DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), key, value, event.isOriginLocal());
+ else
+ DistributedStateImpl.this.notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), key, value, event.isOriginLocal());
}
}
More information about the jboss-cvs-commits
mailing list