[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/impl ...
Jason Thomas Greene
jgreene at jboss.com
Sun Apr 22 22:53:22 EDT 2007
User: jgreene
Date: 07/04/22 22:53:22
Modified: src/org/jboss/cache/pojo/impl AdvisedPojoHandler.java
PojoCacheDelegate.java PojoCacheImpl.java
Log:
Introduce new notification API
Remove mixin approach
Revision Changes Path
1.3 +12 -15 JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AdvisedPojoHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AdvisedPojoHandler.java 19 Jan 2007 10:50:42 -0000 1.2
+++ AdvisedPojoHandler.java 23 Apr 2007 02:53:22 -0000 1.3
@@ -7,6 +7,13 @@
package org.jboss.cache.pojo.impl;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -22,22 +29,14 @@
import org.jboss.cache.pojo.PojoUtil;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.memory.FieldPersistentReference;
-import org.jboss.cache.pojo.observable.Observer;
import org.jboss.cache.pojo.util.AopUtil;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* Handling the advised pojo operations. No consideration of object graph here.
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: AdvisedPojoHandler.java,v 1.2 2007/01/19 10:50:42 msurtani Exp $
+ * @version $Id: AdvisedPojoHandler.java,v 1.3 2007/04/23 02:53:22 jgreene Exp $
*/
class AdvisedPojoHandler
{
@@ -45,15 +44,13 @@
private CacheSPI cache_;
private PojoCacheImpl pCache_;
private PojoUtil util_;
- private Observer observer_;
public AdvisedPojoHandler(PojoCacheImpl pCache, InternalHelper internal,
- PojoUtil util, Observer observer)
+ PojoUtil util)
{
pCache_ = pCache;
cache_ = (CacheSPI) pCache_.getCache();
util_ = util;
- observer_ = observer;
}
public Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
@@ -83,7 +80,7 @@
InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
interceptor.setAopInstance(pojoInstance);
- util_.attachInterceptor(obj, advisor, interceptor, observer_);
+ util_.attachInterceptor(obj, advisor, interceptor);
return obj;
}
@@ -125,7 +122,7 @@
// Insert interceptor at runtime
CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
interceptor.setAopInstance(pojoInstance);
- util_.attachInterceptor(obj, advisor, interceptor, observer_);
+ util_.attachInterceptor(obj, advisor, interceptor);
map.put(PojoInstance.KEY, pojoInstance);
pojoInstance.setPojoClass(type.getType());
@@ -241,7 +238,7 @@
{
log.debug("regularRemoveObject(): removed cache interceptor fqn: " + fqn + " interceptor: " + interceptor);
}
- util_.detachInterceptor(advisor, interceptor, observer_);
+ util_.detachInterceptor(advisor, interceptor);
}
return null; // Not really null though.
1.4 +12 -15 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheDelegate.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- PojoCacheDelegate.java 5 Apr 2007 01:29:22 -0000 1.3
+++ PojoCacheDelegate.java 23 Apr 2007 02:53:22 -0000 1.4
@@ -6,6 +6,15 @@
*/
package org.jboss.cache.pojo.impl;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Observer;
+import java.util.Set;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -27,17 +36,8 @@
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
import org.jboss.cache.pojo.memory.FieldPersistentReference;
-import org.jboss.cache.pojo.observable.Observer;
import org.jboss.cache.pojo.util.AopUtil;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* Delegate class for PojoCache, the real implementation code happens here.
*
@@ -57,10 +57,8 @@
private ThreadLocal<Boolean> bulkRemove_ = new ThreadLocal<Boolean>();
private final String DETACH = "DETACH";
private PojoUtil util_ = new PojoUtil();
- // Observer for field event notification
- private Observer observer_;
- public PojoCacheDelegate(PojoCacheImpl cache, Observer observer)
+ public PojoCacheDelegate(PojoCacheImpl cache)
{
pCache_ = cache;
cache_ = (CacheSPI) pCache_.getCache();
@@ -68,8 +66,7 @@
graphHandler_ = new ObjectGraphHandler(pCache_, internal_);
collectionHandler_ = new CollectionClassHandler(pCache_, internal_);
serializableHandler_ = new SerializableObjectHandler(pCache_, internal_);
- observer_ = observer;
- advisedHandler_ = new AdvisedPojoHandler(pCache_, internal_, util_, observer_);
+ advisedHandler_ = new AdvisedPojoHandler(pCache_, internal_, util_);
}
public void setBulkRemove(boolean bulk)
@@ -434,7 +431,7 @@
{
if (!detachOnly)
{
- util_.detachInterceptor(advisor, interceptor, observer_);
+ util_.detachInterceptor(advisor, interceptor);
undoMap.put(advisor, interceptor);
}
else
1.6 +26 -30 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- PojoCacheImpl.java 8 Feb 2007 14:52:41 -0000 1.5
+++ PojoCacheImpl.java 23 Apr 2007 02:53:22 -0000 1.6
@@ -7,6 +7,14 @@
package org.jboss.cache.pojo.impl;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -26,25 +34,18 @@
import org.jboss.cache.pojo.annotation.Attach;
import org.jboss.cache.pojo.annotation.Detach;
import org.jboss.cache.pojo.annotation.Find;
-import org.jboss.cache.pojo.observable.Observer;
-import org.jboss.cache.pojo.observable.Subject;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
+import org.jboss.cache.pojo.notification.AttachNotification;
+import org.jboss.cache.pojo.notification.DetachNotification;
+import org.jboss.cache.pojo.notification.Notification;
+import org.jboss.cache.pojo.notification.NotificationContext;
/**
* Implementation class for PojoCache interface
*
* @author Ben Wang
- * @version $Id: PojoCacheImpl.java,v 1.5 2007/02/08 14:52:41 genman Exp $
+ * @version $Id: PojoCacheImpl.java,v 1.6 2007/04/23 02:53:22 jgreene Exp $
*/
-public class PojoCacheImpl implements PojoCache, Observer
+public class PojoCacheImpl implements PojoCache
{
private CacheSPI cache_ = null;
protected final Log log_ = LogFactory.getLog(PojoCacheImpl.this.getClass());
@@ -99,7 +100,7 @@
throw new PojoCacheException("init " + config + " failed", e);
}
- delegate_ = new PojoCacheDelegate(this, this);
+ delegate_ = new PojoCacheDelegate(this);
}
public CacheSPI getUnderlyingCache()
@@ -350,22 +351,15 @@
/********************************************************************************
* Internal API for event notification
********************************************************************************/
- /**
- * Callback for Observable to notify of field modification
- *
- * @param subject
- */
- public void fireChange(Subject subject, Field modifiedField, boolean pre)
- {
- boolean isLocal = true;// TODO Not yet supported. Always true now.
- if (hasListeners)
+
+ private NotificationContext makeContext()
{
- for (Iterator it = listeners.iterator(); it.hasNext();)
+ return new NotificationContext() {
+ public PojoCache getPojoCache()
{
- ((PojoCacheListener) it.next()).modify(subject, modifiedField, pre, isLocal);
- }
+ return PojoCacheImpl.this;
}
-
+ };
}
private void notifyAttach(Object pojo, boolean pre)
@@ -378,7 +372,8 @@
{
for (Iterator it = listeners.iterator(); it.hasNext();)
{
- ((PojoCacheListener) it.next()).attach(pojo, pre, isLocal);
+ AttachNotification notification = new AttachNotification(makeContext(), pojo, pre ? Notification.Phase.PRE : Notification.Phase.POST, isLocal);
+ ((PojoCacheListener) it.next()).attach(notification);
}
}
}
@@ -393,7 +388,8 @@
{
for (Iterator it = listeners.iterator(); it.hasNext();)
{
- ((PojoCacheListener) it.next()).detach(pojo, pre, isLocal);
+ DetachNotification notification = new DetachNotification(makeContext(), pojo, pre ? Notification.Phase.PRE : Notification.Phase.POST, isLocal);
+ ((PojoCacheListener) it.next()).detach(notification);
}
}
}
More information about the jboss-cvs-commits
mailing list