[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/impl ...
Ben Wang
bwang at jboss.com
Mon Jul 17 05:07:08 EDT 2006
User: bwang
Date: 06/07/17 05:07:08
Modified: src-50/org/jboss/cache/pojo/impl
AdvisedPojoHandler.java CollectionClassHandler.java
InternalHelper.java ObjectGraphHandler.java
PojoCacheDelegate.java PojoCacheImpl.java
SerializableObjectHandler.java
Log:
First cut of new internal object mapping using flat space.
Revision Changes Path
1.5 +11 -13 JBossCache/src-50/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-50/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- AdvisedPojoHandler.java 16 Jul 2006 04:04:41 -0000 1.4
+++ AdvisedPojoHandler.java 17 Jul 2006 09:07:08 -0000 1.5
@@ -11,7 +11,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.CachedType;
-import org.jboss.cache.pojo.PojoReference;
+import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoUtil;
import org.jboss.cache.pojo.observable.Observer;
import org.jboss.cache.pojo.memory.FieldPersistentReference;
@@ -40,7 +40,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: AdvisedPojoHandler.java,v 1.4 2006/07/16 04:04:41 bwang Exp $
+ * @version $Id: AdvisedPojoHandler.java,v 1.5 2006/07/17 09:07:08 bwang Exp $
*/
class AdvisedPojoHandler
{
@@ -61,7 +61,7 @@
observer_ = observer;
}
- public Object get(Fqn fqn, Class clazz, PojoReference pojoReference)
+ public Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
throws CacheException
{
CachedType type = pCache_.getCachedType(clazz);
@@ -78,12 +78,12 @@
// Insert interceptor at runtime
InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
- interceptor.setAopInstance(pojoReference);
+ interceptor.setAopInstance(pojoInstance);
util_.attachInterceptor(obj, advisor, interceptor, observer_);
return obj;
}
- void put(Fqn fqn, Object obj) throws CacheException
+ void put(Fqn fqn, Fqn referencingFqn, Object obj) throws CacheException
{
CachedType type = pCache_.getCachedType(obj.getClass());
// We have a clean slate then.
@@ -94,19 +94,17 @@
advisor = new ClassInstanceAdvisor(obj);
((Advised) obj)._setInstanceAdvisor(advisor);
}
-
// Let's do batch update via Map instead
Map map = new HashMap();
// Always initialize the ref count so we can mark this as an AopNode.
- PojoReference pojoReference = InternalHelper.initializeAopInstance();
+ PojoInstance pojoInstance = InternalHelper.initializeAopInstance(referencingFqn);
// Insert interceptor at runtime
CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
- interceptor.setAopInstance(pojoReference);
+ interceptor.setAopInstance(pojoInstance);
util_.attachInterceptor(obj, advisor, interceptor, observer_);
- map.put(PojoReference.KEY, pojoReference);
- // This is put into map first.
- InternalHelper.putAopClazz(type.getType(), map);
+ map.put(PojoInstance.KEY, pojoInstance);
+ pojoInstance.setPojoClass(type.getType());
// we will do it recursively.
// Map of sub-objects that are non-primitive
Map subPojoMap = new HashMap();
@@ -155,7 +153,7 @@
// Use option to skip locking since we have parent lock already.
cache_.put(fqn, map, internal_.getLockOption());
// This is in-memory operation only
- InternalHelper.setPojo(pojoReference, obj);
+ InternalHelper.setPojo(pojoInstance, obj);
for (Object o : subPojoMap.keySet())
{
@@ -175,7 +173,7 @@
// Need to make sure this is behind put such that obj.toString is done correctly.
if (log.isDebugEnabled())
{
- log.debug("_regularPutObject(): inserting with fqn: " + fqn);
+ log.debug("internalPut(): inserting with fqn: " + fqn);
}
}
1.6 +9 -14 JBossCache/src-50/org/jboss/cache/pojo/impl/CollectionClassHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CollectionClassHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/CollectionClassHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CollectionClassHandler.java 16 Jul 2006 04:04:41 -0000 1.5
+++ CollectionClassHandler.java 17 Jul 2006 09:07:08 -0000 1.6
@@ -18,7 +18,7 @@
import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.CachedType;
-import org.jboss.cache.pojo.PojoReference;
+import org.jboss.cache.pojo.PojoInstance;
import java.util.Iterator;
import java.util.List;
@@ -30,7 +30,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: CollectionClassHandler.java,v 1.5 2006/07/16 04:04:41 bwang Exp $
+ * @version $Id: CollectionClassHandler.java,v 1.6 2006/07/17 09:07:08 bwang Exp $
*/
class CollectionClassHandler
{
@@ -46,7 +46,7 @@
internal_ = internal;
}
- Object get(Fqn fqn, Class clazz, PojoReference pojoReference)
+ Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
throws CacheException
{
Object obj = null;
@@ -73,8 +73,7 @@
return obj;
}
-
- void put(Fqn fqn, Object obj) throws CacheException
+ void put(Fqn fqn, Fqn referencingFqn, Object obj) throws CacheException
{
boolean isCollection = false;
@@ -93,8 +92,6 @@
log.debug("collectionPutObject(): aspectized obj is a Map type of size: " + ((Map) obj).size());
}
- internal_.putAopClazz(fqn, type.getType());
-
// Let's replace it with a proxy if necessary
Map map = (Map) obj;
if (!(obj instanceof ClassProxy))
@@ -126,7 +123,6 @@
}
List list = (List) obj;
- internal_.putAopClazz(fqn, type.getType());
// Let's replace it with a proxy if necessary
if (!(obj instanceof ClassProxy))
@@ -157,7 +153,6 @@
}
Set set = (Set) obj;
- internal_.putAopClazz(fqn, type.getType());
// Let's replace it with a proxy if necessary
if (!(obj instanceof ClassProxy))
@@ -184,15 +179,15 @@
if (isCollection)
{
// Always initialize the ref count so that we can mark this as an AopNode.
- PojoReference pojoReference = InternalHelper.initializeAopInstance();
- cache_.put(fqn, PojoReference.KEY, pojoReference);
+ PojoInstance pojoInstance = InternalHelper.initializeAopInstance(referencingFqn);
+ pojoInstance.set(obj);
+ pojoInstance.setPojoClass(type.getType());
+ cache_.put(fqn, PojoInstance.KEY, pojoInstance);
// Attach pojoReference to that interceptor
BaseInterceptor baseInterceptor = (BaseInterceptor) CollectionInterceptorUtil.getInterceptor(
(ClassProxy) obj);
- baseInterceptor.setAopInstance(pojoReference);
-
- InternalHelper.setPojo(pojoReference, obj);
+ baseInterceptor.setAopInstance(pojoInstance);
}
}
1.5 +95 -55 JBossCache/src-50/org/jboss/cache/pojo/impl/InternalHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InternalHelper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/InternalHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- InternalHelper.java 16 Jul 2006 04:04:41 -0000 1.4
+++ InternalHelper.java 17 Jul 2006 09:07:08 -0000 1.5
@@ -14,8 +14,9 @@
import org.jboss.cache.config.Option;
import org.jboss.cache.pojo.util.ObjectUtil;
import org.jboss.cache.pojo.PojoTreeCache;
-import org.jboss.cache.pojo.PojoReference;
+import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.InternalConstant;
+import org.jboss.cache.pojo.PojoReference;
import java.util.Map;
@@ -63,26 +64,40 @@
return skipLockOption_;
}
- PojoReference getAopInstance(Fqn fqn) throws CacheException
+ PojoInstance getAopInstance(Fqn fqn) throws CacheException
+ {
+ // Not very efficient now since we are peeking every single time.
+ // Should have cache it without going to local cache.
+ return (PojoInstance) get(fqn, PojoInstance.KEY, false);
+ }
+
+ PojoReference getPojoReference(Fqn fqn) throws CacheException
{
// Not very efficient now since we are peeking every single time.
// Should have cache it without going to local cache.
return (PojoReference) get(fqn, PojoReference.KEY, false);
}
- private PojoReference getAopInstanceWithGravitation(Fqn fqn) throws CacheException
+ PojoReference getPojoReferenceWithGravitation(Fqn fqn) throws CacheException
{
// Not very efficient now since we are peeking every single time.
// Should have cache it without going to local cache.
return (PojoReference) get(fqn, PojoReference.KEY, true);
}
- static PojoReference initializeAopInstance()
+ private PojoInstance getAopInstanceWithGravitation(Fqn fqn) throws CacheException
{
- PojoReference pojoReference = new PojoReference();
+ // Not very efficient now since we are peeking every single time.
+ // Should have cache it without going to local cache.
+ return (PojoInstance) get(fqn, PojoInstance.KEY, true);
+ }
+
+ static PojoInstance initializeAopInstance(Fqn sourceFqn)
+ {
+ PojoInstance pojoInstance = new PojoInstance();
- pojoReference.incrementRefCount(null);
- return pojoReference;
+ pojoInstance.incrementRefCount(sourceFqn);
+ return pojoInstance;
}
/**
@@ -90,13 +105,13 @@
*/
int incrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(originalFqn);
- if (pojoReference == null)
+ PojoInstance pojoInstance = getAopInstance(originalFqn);
+ if (pojoInstance == null)
throw new RuntimeException("InternalDelegate.incrementRefCount(): null pojoReference for fqn: " + originalFqn);
- int count = pojoReference.incrementRefCount(referencingFqn);
+ int count = pojoInstance.incrementRefCount(referencingFqn);
// need to update it.
- put(originalFqn, PojoReference.KEY, pojoReference);
+ put(originalFqn, PojoInstance.KEY, pojoInstance);
return count;
}
@@ -152,24 +167,24 @@
*/
int decrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(originalFqn);
- if (pojoReference == null)
+ PojoInstance pojoInstance = getAopInstance(originalFqn);
+ if (pojoInstance == null)
throw new RuntimeException("InternalDelegate.decrementRefCount(): null pojoReference.");
- int count = pojoReference.decrementRefCount(referencingFqn);
+ int count = pojoInstance.decrementRefCount(referencingFqn);
if (count < -1) // can't dip below -1
throw new RuntimeException("InternalDelegate.decrementRefCount(): null pojoReference.");
// need to update it.
- put(originalFqn, PojoReference.KEY, pojoReference);
+ put(originalFqn, PojoInstance.KEY, pojoInstance);
return count;
}
- static boolean isReferenced(PojoReference pojoReference)
+ static boolean isReferenced(PojoInstance pojoInstance)
{
// If ref counter is greater than 0, we fqn is being referenced.
- return (pojoReference.getRefCount() > 0);
+ return (pojoInstance.getRefCount() > 0);
}
int getRefCount(Fqn fqn) throws CacheException
@@ -177,18 +192,18 @@
return getAopInstance(fqn).getRefCount();
}
- String getRefFqn(Fqn fqn) throws CacheException
+ String XgetRefFqn(Fqn fqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(fqn);
- return getRefFqn(pojoReference);
+ PojoInstance pojoInstance = getAopInstance(fqn);
+ return getRefFqn(pojoInstance);
}
- String getRefFqn(PojoReference pojoReference) throws CacheException
+ String getRefFqn(PojoInstance pojoInstance) throws CacheException
{
- if (pojoReference == null)
+ if (pojoInstance == null)
return null;
- String aliasFqn = pojoReference.getInternalFqn();
+ String aliasFqn = pojoInstance.getInternalFqn();
if (aliasFqn == null || aliasFqn.length() == 0) return null;
@@ -197,77 +212,102 @@
void setRefFqn(Fqn fqn, String internalFqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(fqn);
- if (pojoReference == null)
- pojoReference = new PojoReference();
+ PojoInstance pojoInstance = getAopInstance(fqn);
+ if (pojoInstance == null)
+ pojoInstance = new PojoInstance();
- pojoReference.setInternalFqn(internalFqn);
- put(fqn, PojoReference.KEY, pojoReference);
+ pojoInstance.setInternalFqn(internalFqn);
+ put(fqn, PojoInstance.KEY, pojoInstance);
}
void removeRefFqn(Fqn fqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(fqn);
- if (pojoReference == null)
+ PojoInstance pojoInstance = getAopInstance(fqn);
+ if (pojoInstance == null)
throw new RuntimeException("InternalDelegate.getInternalFqn(): null pojoReference.");
- pojoReference.removeInternalFqn();
- put(fqn, PojoReference.KEY, pojoReference);
+ pojoInstance.removeInternalFqn();
+ put(fqn, PojoInstance.KEY, pojoInstance);
}
Object getPojo(Fqn fqn) throws CacheException
{
- PojoReference pojoReference = getAopInstance(fqn);
- if (pojoReference == null)
+ PojoReference pojoReference = getPojoReference(fqn);
+ Fqn realFqn = null;
+ if(pojoReference != null)
+ {
+ // This is outward facing node
+ realFqn = pojoReference.getFqn();
+ } else
+ {
+ // This is the internal node.
+ realFqn = fqn;
+ }
+
+ PojoInstance pojoInstance = getAopInstance(realFqn);
+ if (pojoInstance == null)
return null;
- return pojoReference.get();
+ return pojoInstance.get();
}
Object getPojoWithGravitation(Fqn fqn) throws CacheException
{
// This is for buddy replication
- PojoReference pojoReference = getAopInstanceWithGravitation(fqn);
- if (pojoReference == null)
+ PojoReference pojoReference = getPojoReferenceWithGravitation(fqn);
+ // Find the real fqn where it is stored.
+ Fqn internalFqn = pojoReference.getFqn();
+
+ PojoInstance pojoInstance = getAopInstanceWithGravitation(internalFqn);
+ if (pojoInstance == null)
return null;
- return pojoReference.get();
+ return pojoInstance.get();
}
void setPojo(Fqn fqn, Object pojo) throws CacheException
{
- PojoReference pojoReference = getAopInstance(fqn);
- if (pojoReference == null)
+ PojoInstance pojoInstance = getAopInstance(fqn);
+ if (pojoInstance == null)
{
- pojoReference = new PojoReference();
- put(fqn, PojoReference.KEY, pojoReference);
+ pojoInstance = new PojoInstance();
+ put(fqn, PojoInstance.KEY, pojoInstance);
}
- pojoReference.set(pojo);
+ pojoInstance.set(pojo);
// No need to do a cache put since pojo is transient anyway.
}
- static void setPojo(PojoReference pojoReference, Object pojo)
+ static boolean isMultipleReferenced(PojoInstance pojoInstance)
+ {
+ if(pojoInstance.getRefCount() > (PojoInstance.INITIAL_COUNTER_VALUE+1)) return true;
+
+ return false;
+ }
+
+ static void setPojo(PojoInstance pojoInstance, Object pojo)
{
// No need to do a cache put since pojo is transient anyway.
- pojoReference.set(pojo);
+ pojoInstance.set(pojo);
}
- void setPojo(Fqn fqn, Object pojo, PojoReference pojoReference) throws CacheException
+ void setPojo(Fqn fqn, Object pojo, PojoInstance pojoInstance) throws CacheException
{
- if (pojoReference == null)
+ if (pojoInstance == null)
{
- pojoReference = new PojoReference();
- put(fqn, PojoReference.KEY, pojoReference);
+ pojoInstance = new PojoInstance();
+ put(fqn, PojoInstance.KEY, pojoInstance);
}
- pojoReference.set(pojo);
+ pojoInstance.set(pojo);
// No need to do a cache put since pojo is transient anyway.
}
- /**
- * We store the class name in string.
- */
+ void putPojoReference(Fqn fqn, PojoReference pojoReference) throws CacheException
+ {
+ put(fqn, PojoReference.KEY, pojoReference);
+ }
+
void putAopClazz(Fqn fqn, Class clazz) throws CacheException
{
put(fqn, InternalConstant.CLASS_INTERNAL, clazz);
@@ -289,7 +329,7 @@
void removeInternalAttributes(Fqn fqn) throws CacheException
{
- cache_.remove(fqn, PojoReference.KEY);
+ cache_.remove(fqn, PojoInstance.KEY);
cache_.remove(fqn, InternalConstant.CLASS_INTERNAL);
}
@@ -363,7 +403,7 @@
Fqn getNextFqnInLine(Fqn currentFqn) throws CacheException
{
- PojoReference ai = getAopInstance(currentFqn);
+ PojoInstance ai = getAopInstance(currentFqn);
return ai.getAndRemoveFirstFqnInList();
}
1.5 +42 -99 JBossCache/src-50/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ObjectGraphHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/ObjectGraphHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ObjectGraphHandler.java 16 Jul 2006 04:04:41 -0000 1.4
+++ ObjectGraphHandler.java 17 Jul 2006 09:07:08 -0000 1.5
@@ -20,7 +20,9 @@
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.CachedType;
+import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoReference;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
/**
@@ -28,7 +30,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: ObjectGraphHandler.java,v 1.4 2006/07/16 04:04:41 bwang Exp $
+ * @version $Id: ObjectGraphHandler.java,v 1.5 2006/07/17 09:07:08 bwang Exp $
*/
class ObjectGraphHandler
{
@@ -44,32 +46,20 @@
internal_ = internal;
}
- Object get(Fqn fqn, Class clazz, PojoReference pojoReference) throws CacheException
+ Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance) throws CacheException
{
// Note this is actually the aliasFqn, not the real fqn!
- String refFqn = internal_.getRefFqn(pojoReference);
Object obj;
- if (refFqn != null)
- {
- // this is recursive. Need to obtain the object from parent fqn
- // No need to add CacheFieldInterceptor as a result. Everything is re-directed.
- // In addition, this op will not be recursive.
- if (log.isDebugEnabled())
- {
- log.debug("get(): obtain value from reference fqn: " + refFqn);
- }
- obj = pCache_.getObject(Fqn.fromString(refFqn));
+
+ obj = pCache_.getObject(fqn);
if (obj == null)
throw new RuntimeException("ObjectGraphHandler.get(): null object from internal ref node." +
- " Original fqn: " + fqn + " Internal ref node: " + refFqn);
+ " Internal ref node: " + fqn);
return obj; // No need to set the instance under fqn. It is located in refFqn anyway.
}
- return null;
- }
-
- boolean put(Fqn fqn, Object obj) throws CacheException
+ void put(Fqn fqn, Object obj) throws CacheException
{
CachedType type = pCache_.getCachedType(obj.getClass());
@@ -98,94 +88,57 @@
// This will increment the ref count, reset, and add ref fqn in the current fqn node.
setupRefCounting(fqn, originalFqn);
- internal_.putAopClazz(fqn, type.getType());
- return true;
+ // Store a PojoReference in the external fqn node
+ PojoReference pojoReference = new PojoReference();
+ pojoReference.setFqn(originalFqn);
+ pojoReference.setPojoClass(type.getType());
+ internal_.putPojoReference(fqn, pojoReference);
}
- void remove(Fqn fqn, Object pojo)
- throws CacheException
+ boolean isMultipleReferenced(Fqn internalFqn)
{
// Note this is actually the aliasFqn, not the real fqn!
- PojoReference pojoReference = internal_.getAopInstance(fqn);
- String refFqn = internal_.getRefFqn(pojoReference);
- // check if this is a refernce
- if (refFqn != null)
+ PojoInstance pojoInstance = null;
+ try
{
- if (log.isDebugEnabled())
+ pojoInstance = internal_.getAopInstance(internalFqn);
+ } catch (CacheException e)
{
- log.debug("remove(): removing object fqn: " + fqn + " but is actually from ref fqn: " + refFqn
- + " Will just de-reference it.");
+ e.printStackTrace();
+ throw new PojoCacheException("Exception in isMultipleReferenced " + e);
}
- removeFromReference(fqn, refFqn);
- internal_.cleanUp(fqn);
- } else
- {
- if (InternalHelper.isReferenced(pojoReference))
- {
- // This node is currently referenced by others. We will relocate it to the next in line,
- // and update the indirectFqnMap
-
- // First decrement counter.
- decrementRefCount(fqn, null);
- // Determine where to move first.
- Fqn newFqn = internal_.getNextFqnInLine(fqn);
- // Is newFqn is child of fqn?
- if (newFqn.isChildOf(fqn))
- {
- // Take out the child fqn reference to me.
- internal_.removeRefFqn(newFqn);
+ // check if this is a refernce
+ return internal_.isMultipleReferenced(pojoInstance);
- if (log.isDebugEnabled())
- {
- log.debug("remove(): this node " + fqn + " is currently referenced by a cyclic reference: "
- + newFqn + "Will only decrement reference count.");
}
- } else
- {
- // Relocate all the contents from old to the new fqn
- internal_.relocate(fqn, newFqn);
- // Reset the fqn in the cache interceptor
- InstanceAdvisor advisor = ((Advised) pojo)._getInstanceAdvisor();
- CacheFieldInterceptor interceptor = (CacheFieldInterceptor) AopUtil.findCacheInterceptor(advisor);
- if (interceptor == null)
- throw new IllegalStateException("ObjectGraphHandler.remove(): null interceptor");
- interceptor.setFqn(newFqn);
- // reset the fqn in the indirect fqn map
- internal_.setIndirectFqn(fqn.toString(), newFqn.toString());
+ void remove(Fqn referencingFqn, Fqn internalFqn, Object pojo)
+ throws CacheException
+ {
if (log.isDebugEnabled())
{
- log.debug("remove(): this node " + fqn + " is currently referenced by " +
- +internal_.getRefCount(newFqn) +
- " other pojos after relocating to " + newFqn.toString());
- }
- }
- }
+ log.debug("remove(): removing object fqn: " + referencingFqn
+ + " Will just de-reference it.");
}
+ removeFromReference(referencingFqn, internalFqn);
}
/**
* Remove the object from the the reference fqn, meaning just decrement the ref counter.
*
- * @param fqn
- * @param refFqn
- * @throws CacheException
*/
- private void removeFromReference(Fqn fqn, String refFqn) throws CacheException
+ private void removeFromReference(Fqn referencingFqn, Fqn originalFqn) throws CacheException
{
- synchronized (refFqn)
+ synchronized (referencingFqn)
{ // we lock the internal fqn here so no one else has access.
// Decrement ref counting on the internal node
- if (decrementRefCount(Fqn.fromString(refFqn), fqn) == PojoReference.INITIAL_COUNTER_VALUE)
+ if (decrementRefCount(referencingFqn, originalFqn) == PojoInstance.INITIAL_COUNTER_VALUE)
{
// No one is referring it so it is safe to remove
// TODO we should make sure the parent nodes are also removed they are empty as well.
- pCache_.removeObject(Fqn.fromString(refFqn));
+ pCache_.removeObject(referencingFqn);
}
}
-
- // Remove ref fqn from this fqn
- internal_.removeRefFqn(fqn);
}
/**
@@ -200,22 +153,12 @@
synchronized (refFqn)
{ // we lock the ref fqn here so no one else has access.
// increment the reference counting
- String aliasFqn = null;
- if (incrementRefCount(refFqn, fqn) == 1)
- {
- // We have the first multiple reference
- aliasFqn = internal_.createIndirectFqn(refFqn.toString());
- } else
- {
- aliasFqn = InternalHelper.getIndirectFqn(refFqn.toString());
- }
+ incrementRefCount(refFqn, fqn);
// set the internal fqn in fqn so we can reference it.
if (log.isTraceEnabled())
{
log.trace("setupRefCounting(): current fqn: " + fqn + " set to point to: " + refFqn);
}
-
- internal_.setRefFqn(fqn, aliasFqn);
}
}
@@ -224,10 +167,10 @@
return internal_.incrementRefCount(originalFqn, referencingFqn);
}
- private int decrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
+ private int decrementRefCount(Fqn referencingFqn, Fqn originalFqn) throws CacheException
{
int count = 0;
- if ((count = internal_.decrementRefCount(originalFqn, referencingFqn)) == (PojoReference.INITIAL_COUNTER_VALUE + 1))
+ if ((count = internal_.decrementRefCount(originalFqn, referencingFqn)) == (PojoInstance.INITIAL_COUNTER_VALUE + 1))
{
internal_.removeIndirectFqn(originalFqn.toString());
}
1.6 +77 -81 JBossCache/src-50/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-50/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- PojoCacheDelegate.java 16 Jul 2006 04:04:41 -0000 1.5
+++ PojoCacheDelegate.java 17 Jul 2006 09:07:08 -0000 1.6
@@ -23,6 +23,7 @@
import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.PojoUtil;
import org.jboss.cache.pojo.CachedType;
+import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoReference;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
@@ -80,10 +81,8 @@
public Object getObject(Fqn fqn) throws CacheException
{
- // Remember not to print obj here since it will trigger the CacheFieldInterceptor.
-
// TODO Must we really to couple with BR? JBCACHE-669
- Object pojo = internal_.getPojoWithGravitation(fqn);
+ Object pojo = internal_.getPojo(fqn);
if (pojo != null)
{
// we already have an advised instance
@@ -122,15 +121,13 @@
*/
public Object putObject(Fqn fqn, Object obj) throws CacheException
{
- // Remember not to print obj here since it will trigger the CacheFieldInterceptor.
-
// Skip some un-necessary update if obj is the same class as the old one
Object oldValue = internal_.getPojo(fqn);
if (oldValue == obj)
{
if (log.isDebugEnabled())
{
- log.debug("putObject(): fqn: " + fqn + " pojo is already in the cache. Returns right away.");
+ log.debug("putObject(): fqn: " + fqn + " pojo is already in the cache. Return right away.");
}
return obj;
}
@@ -149,28 +146,49 @@
return oldValue; // we are done
}
- // Trigger bulk remove here for performance. Let's not worry about performance optimization yet.
- setBulkRemove(false);
+ // This create a PojoReference to store a pointer to the real fqn.
+ Fqn internalFqn = createPojoReference(fqn, obj);
- if( (obj instanceof Advised || obj instanceof ClassProxy) && isMultipleReferenced(obj))
+ if( (obj instanceof Advised || obj instanceof ClassProxy) && isMultipleReferencedPut(obj))
{
+ // we pass in the originating fqn intentionaly
graphHandler_.put(fqn, obj);
} else if (obj instanceof Advised)
{
- advisedHandler_.put(fqn, obj);
+ advisedHandler_.put(internalFqn, fqn, obj);
} else if (isCollection(obj))
{
- collectionHandler_.put(fqn, obj);
+ collectionHandler_.put(internalFqn, fqn, obj);
//
} else
{
// must be Serializable, including primitive types
- serializableHandler_.put(fqn, obj);
+ serializableHandler_.put(internalFqn, obj);
}
return oldValue;
}
+ Fqn createPojoReference(Fqn fqn, Object obj) throws CacheException
+ {
+ // Create PojoReference
+ CachedType type = pCache_.getCachedType(obj.getClass());
+ PojoReference pojoReference = new PojoReference();
+ pojoReference.setPojoClass(type.getType());
+
+ // Create an internal Fqn name
+ Fqn internalFqn = AopUtil.createInternalFqn();
+ // store PojoReference
+ pojoReference.setFqn(internalFqn);
+ internal_.putPojoReference(fqn, pojoReference);
+ if (log.isDebugEnabled())
+ {
+ log.debug("put(): inserting PojoReference with fqn: " + fqn);
+ }
+ // store obj in the internal fqn
+ return internalFqn;
+ }
+
/**
* Note that caller of this method will take care of synchronization within the <code>fqn</code> sub-tree.
*
@@ -180,70 +198,52 @@
*/
public Object removeObject(Fqn fqn) throws CacheException
{
- Class clazz = internal_.peekAopClazz(fqn);
- if (clazz == null)
+ // the class attribute is implicitly stored as an immutable read-only attribute
+ PojoReference pojoReference = internal_.getPojoReference(fqn);
+ if(pojoReference == null)
{
+ // clazz and pojoReference can be not null if this node is the replicated brother node.
if (log.isTraceEnabled())
{
- log.trace("removeObject(): clasz is null. fqn: " + fqn + " No need to remove.");
+ log.trace("removeObject(): clazz is null. fqn: " + fqn + " No need to remove.");
}
return null;
}
+ Class clazz = pojoReference.getPojoClass();
+ Fqn internalFqn = pojoReference.getFqn();
+
if (log.isDebugEnabled())
{
log.debug("removeObject(): removing object from fqn: " + fqn);
}
- Object result = pCache_.getObject(fqn);
+ Object result = pCache_.getObject(internalFqn);
if (result == null)
{
- // This is not a *Pojo*. Must be regular cache stuffs
- if (cache_.exists(fqn))
- {
- // TODO What do we do here. It can still have children pojo though.
- cache_.remove(fqn);
- }
- return null;
+ throw new IllegalStateException("PojoCacheDelegate.removeObject(): fqn: "
+ +fqn + " has null pojo.");
}
- // can check if we need to do any bulk remove. E.g., if there is no object graph.
-/*
- if (getBulkRemove())
- {
- if (bulkRemove(fqn, result))
+ if(graphHandler_.isMultipleReferenced(internalFqn))
{
- // Remember not to print obj here since it will trigger the CacheFieldInterceptor.
- if (log.isDebugEnabled())
- {
- log.debug("_removeObject(): fqn: " + fqn + "removing existing object in bulk.");
- }
-
- return result;
- }
- setBulkRemove(false);
- }
-*/
-
- if( (result instanceof Advised || result instanceof ClassProxy) &&isMultipleReferenced(result))
- {
- graphHandler_.remove(fqn, result);
- }
- if (Advised.class.isAssignableFrom(clazz))
+ graphHandler_.remove(fqn, internalFqn, result);
+ } else if (Advised.class.isAssignableFrom(clazz))
{
- advisedHandler_.remove(fqn, result, clazz);
- internal_.cleanUp(fqn);
+ advisedHandler_.remove(internalFqn, result, clazz);
+ internal_.cleanUp(internalFqn);
} else if (isCollectionGet(clazz))
{
// We need to return the original reference
- result = collectionHandler_.remove(fqn, result);
- internal_.cleanUp(fqn);
+ result = collectionHandler_.remove(internalFqn, result);
+ internal_.cleanUp(internalFqn);
} else
{ // Just Serializable objects. Do a brute force remove is ok.
serializableHandler_.remove();
- internal_.cleanUp(fqn);
+ internal_.cleanUp(internalFqn);
}
+ internal_.cleanUp(fqn);
// remove the interceptor as well.
return result;
}
@@ -271,50 +271,46 @@
private Object getObjectInternal(Fqn fqn) throws CacheException
{
// the class attribute is implicitly stored as an immutable read-only attribute
- Class clazz = internal_.peekAopClazz(fqn);
+ PojoReference pojoReference = internal_.getPojoReference(fqn);
+ if(pojoReference == null)
+ {
// clazz and pojoReference can be not null if this node is the replicated brother node.
- if (clazz == null)
return null;
+ }
+
+ // This is the real location for the pojo.
+ Fqn internalFqn = pojoReference.getFqn();
+ Class clazz = pojoReference.getPojoClass();
/**
* Reconstruct the managed POJO
*/
Object obj;
-
- PojoReference pojoReference = internal_.getAopInstance(fqn);
- if (pojoReference == null)
+ PojoInstance pojoInstance = internal_.getAopInstance(internalFqn);
+ if (pojoInstance == null)
{
- throw new RuntimeException("PojoCacheDelegate._getObject(): null PojoReference.");
+ throw new RuntimeException("PojoCacheDelegate.getObjectInternal(): null PojoInstance.");
}
// Check for both Advised and Collection classes for object graph.
- if (isMultipleReferencedGet(pojoReference))
- {
- obj = graphHandler_.get(fqn, clazz, pojoReference); // retrieved from internal ref node. We are done.
- } else if (Advised.class.isAssignableFrom(clazz))
+ // Note: no need to worry about multiple referencing here. If there is a graph, we won't come this far.
+ if (Advised.class.isAssignableFrom(clazz))
{
- obj = advisedHandler_.get(fqn, clazz, pojoReference);
+ obj = advisedHandler_.get(internalFqn, clazz, pojoInstance);
} else if(isCollectionGet(clazz))
{ // Must be Collection classes. We will use aop.ClassProxy instance instead.
- obj = collectionHandler_.get(fqn, clazz, pojoReference);
+ obj = collectionHandler_.get(internalFqn, clazz, pojoInstance);
} else
{
// Maybe it is just a serialized object.
- obj = serializableHandler_.get(fqn, clazz, pojoReference);
+ obj = serializableHandler_.get(internalFqn, clazz, pojoInstance);
}
- InternalHelper.setPojo(pojoReference, obj);
+ InternalHelper.setPojo(pojoInstance, obj);
return obj;
}
- private boolean isMultipleReferencedGet(PojoReference pojoReference) throws CacheException
- {
- if(internal_.getRefFqn(pojoReference) != null) return true;
-
- return false;
- }
-
private boolean isCollectionGet(Class clazz)
{
if(Map.class.isAssignableFrom(clazz) || Collection.class.isAssignableFrom(clazz))
@@ -324,7 +320,7 @@
}
- private boolean isMultipleReferenced(Object obj)
+ private boolean isMultipleReferencedPut(Object obj)
{
Interceptor interceptor = null;
if(obj instanceof Advised)
@@ -443,10 +439,10 @@
{
return false;
}
- PojoReference pojoReference = interceptor.getAopInstance();
+ PojoInstance pojoInstance = interceptor.getAopInstance();
// Check if there is cross referenced.
- if (pojoReference.getRefCount() != 0) return true; // I have been referenced
- if (pojoReference.getInternalFqn() != null) return true; // I am referencing others
+ if (pojoInstance.getRefCount() != 0) return true; // I have been referenced
+ if (pojoInstance.getInternalFqn() != null) return true; // I am referencing others
boolean hasFieldAnnotation = hasAnnotation(obj.getClass(), ((Advised) obj)._getAdvisor(), type);
// Check the fields
@@ -504,11 +500,11 @@
InstanceAdvisor advisor = ((ClassProxy) obj)._getInstanceAdvisor();
BaseInterceptor interceptor = (BaseInterceptor) AopUtil.findCollectionInterceptor(advisor);
- PojoReference pojoReference = interceptor.getAopInstance();
- if (pojoReference == null) return false; // safeguard
+ PojoInstance pojoInstance = interceptor.getAopInstance();
+ if (pojoInstance == null) return false; // safeguard
// Check if there is cross referenced.
- if (pojoReference.getRefCount() != 0) return true; // I have been referenced
- if (pojoReference.getInternalFqn() != null) return true; // I am referencing others
+ if (pojoInstance.getRefCount() != 0) return true; // I have been referenced
+ if (pojoInstance.getInternalFqn() != null) return true; // I am referencing others
// iterate thru the keys
if (obj instanceof Map)
{
1.12 +4 -1 JBossCache/src-50/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-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- PojoCacheImpl.java 16 Jul 2006 04:04:41 -0000 1.11
+++ PojoCacheImpl.java 17 Jul 2006 09:07:08 -0000 1.12
@@ -38,7 +38,7 @@
* Implementation class for PojoCache interface
*
* @author Ben Wang
- * @version $Id: PojoCacheImpl.java,v 1.11 2006/07/16 04:04:41 bwang Exp $
+ * @version $Id: PojoCacheImpl.java,v 1.12 2006/07/17 09:07:08 bwang Exp $
*/
public class PojoCacheImpl implements PojoCache, Observer
{
@@ -289,6 +289,7 @@
protected void notifyAttach(Object pojo, boolean pre)
{
+ if(pojo == null) return;
boolean isLocal = true; // TODO Not yet supported. Always true now.
if (hasListeners)
{
@@ -300,6 +301,8 @@
protected void notifyDetach(Object pojo, boolean pre)
{
+ if(pojo == null) return;
+
boolean isLocal = true; // TODO Not yet supported. Always true now.
if (hasListeners)
{
1.6 +7 -7 JBossCache/src-50/org/jboss/cache/pojo/impl/SerializableObjectHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SerializableObjectHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/SerializableObjectHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SerializableObjectHandler.java 16 Jul 2006 04:04:41 -0000 1.5
+++ SerializableObjectHandler.java 17 Jul 2006 09:07:08 -0000 1.6
@@ -12,7 +12,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.PojoTreeCache;
-import org.jboss.cache.pojo.PojoReference;
+import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.InternalConstant;
import java.util.HashMap;
@@ -22,7 +22,7 @@
* Handle Serializable object cache management.
*
* @author Ben Wang
- * @version $Id: SerializableObjectHandler.java,v 1.5 2006/07/16 04:04:41 bwang Exp $
+ * @version $Id: SerializableObjectHandler.java,v 1.6 2006/07/17 09:07:08 bwang Exp $
*/
class SerializableObjectHandler
{
@@ -38,7 +38,7 @@
internal_ = internal;
}
- Object get(Fqn fqn, Class clazz, PojoReference pojoReference)
+ Object get(Fqn fqn, Class clazz, PojoInstance pojoInstance)
throws CacheException
{
Object obj = internal_.get(fqn, InternalConstant.SERIALIZED);
@@ -64,12 +64,12 @@
throws CacheException
{
Map map = new HashMap();
- InternalHelper.putAopClazz(obj.getClass(), map);
// Special optimization here.
- PojoReference pojoReference = new PojoReference();
- pojoReference.set(obj);
- map.put(PojoReference.KEY, pojoReference);
+ PojoInstance pojoInstance = new PojoInstance();
+ pojoInstance.set(obj);
+ pojoInstance.setPojoClass(obj.getClass());
+ map.put(PojoInstance.KEY, pojoInstance);
// Note that we will only have one key in this fqn.
map.put(InternalConstant.SERIALIZED, obj);
internal_.put(fqn, map);
More information about the jboss-cvs-commits
mailing list