[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo ...
Ben Wang
bwang at jboss.com
Mon Jul 17 05:07:09 EDT 2006
User: bwang
Date: 06/07/17 05:07:08
Modified: src-50/org/jboss/cache/pojo PojoReference.java
PojoTreeCache.java
Added: src-50/org/jboss/cache/pojo PojoInstance.java
Log:
First cut of new internal object mapping using flat space.
Revision Changes Path
1.3 +10 -91 JBossCache/src-50/org/jboss/cache/pojo/PojoReference.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoReference.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/PojoReference.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- PojoReference.java 13 Jul 2006 15:56:15 -0000 1.2
+++ PojoReference.java 17 Jul 2006 09:07:08 -0000 1.3
@@ -9,16 +9,8 @@
import org.jboss.cache.Fqn;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-/** POJO class metadata information.
- * When an object is looked up or put in PojoCache, this object will be advised with a CacheFieldInterceptor.
- * The underlying cache stores a reference to this object (for example to update the instance variables, etc.).
- * Since this reference need to be transactional but never replicated (the reference is only valid
- * within the VM this reference is thus stored into an PojoReference (as a transient field).
- * In addition, this instance also serves as a metadata for PojoCache. E.g., it has a reference counting for
- * multiple references and reference FQN.
+/** POJO reference that contains the information to point to the real POJO storage.
*
* @author Ben Wang
*/
@@ -26,106 +18,33 @@
{
// protected static Log log=LogFactory.getLog(PojoReference.class.getName());
public static final Object KEY = "PojoReference";
- public static final int INITIAL_COUNTER_VALUE = -1;
-
static final long serialVersionUID = 6492134565825613209L;
-
- // The instance is transient to avoid replication outside the VM
- private transient Object instance_;
-
// If not null, it signifies that this is a reference that points to this fqn.
// Note that this will get replicated.
- private String internalFqn_ = null;
-
- // Reference counting. THis will get replicated as well. This keep track of number of
- // other instances that referenced this fqn.
- private int refCount_ = INITIAL_COUNTER_VALUE;
-
- // List of fqns that reference this fqn. Assume list size is not big since it may not be efficient.
- private List referencedBy_ = null;
+ private Fqn internalFqn_ = null;
+ private Class clazz_ = null;
public PojoReference()
{
}
- public PojoReference(Object instance)
- {
- set(instance);
- }
-
- public Object get()
- {
- return instance_;
- }
-
- public void set(Object instance)
+ public void setFqn(Fqn fqn)
{
- instance_ = instance;
+ internalFqn_ = fqn;
}
- public String getInternalFqn()
+ public Fqn getFqn()
{
return internalFqn_;
}
- public void setInternalFqn(String refFqn)
- {
- internalFqn_ = refFqn;
- }
-
- public void removeInternalFqn()
- {
- internalFqn_ = null;
- }
-
- synchronized public int incrementRefCount(Fqn sourceFqn)
- {
- if(sourceFqn != null)
- {
- if (referencedBy_ == null)
- {
- referencedBy_ = new ArrayList();
- }
-
- if (referencedBy_.contains(sourceFqn))
- throw new IllegalStateException("PojoReference.incrementRefCount(): source fqn: " +
- sourceFqn + " is already present.");
-
- referencedBy_.add(sourceFqn);
- }
- refCount_ += 1;
-//logger_.info("incrementRefCount(): current ref count " +refCount_);
- return refCount_;
- }
-
- synchronized public int decrementRefCount(Fqn sourceFqn)
- {
- if(sourceFqn != null)
- {
- if (!referencedBy_.contains(sourceFqn))
- throw new IllegalStateException("PojoReference.decrementRefCount(): source fqn: " +
- sourceFqn + " is not present.");
-
- referencedBy_.remove(sourceFqn);
- }
-
- refCount_ -= 1;
-//logger_.info("decrementRefCount(): current ref count " +refCount_);
- return refCount_;
- }
-
- synchronized public int getRefCount()
- {
- return refCount_;
- }
-
- synchronized public Fqn getAndRemoveFirstFqnInList()
+ public void setPojoClass(Class clazz)
{
- return (Fqn) referencedBy_.remove(0);
+ clazz_ = clazz;
}
- synchronized public void addXFqnIntoList(Fqn fqn)
+ public Class getPojoClass()
{
- referencedBy_.add(0, fqn);
+ return clazz_;
}
}
1.10 +1 -1 JBossCache/src-50/org/jboss/cache/pojo/PojoTreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoTreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/PojoTreeCache.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- PojoTreeCache.java 13 Jul 2006 16:53:13 -0000 1.9
+++ PojoTreeCache.java 17 Jul 2006 09:07:08 -0000 1.10
@@ -152,7 +152,7 @@
DataNode node = peek(fqn);
if (node == null) return false;
- if (node.get(PojoReference.KEY) != null)
+ if (node.get(PojoInstance.KEY) != null)
return true;
else
return false;
1.1 date: 2006/07/17 09:07:08; author: bwang; state: Exp;JBossCache/src-50/org/jboss/cache/pojo/PojoInstance.java
Index: PojoInstance.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo;
import org.jboss.cache.Fqn;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/** POJO class metadata information.
* When an object is looked up or put in PojoCache, this object will be advised with a CacheFieldInterceptor.
* The underlying cache stores a reference to this object (for example to update the instance variables, etc.).
* Since this reference need to be transactional but never replicated (the reference is only valid
* within the VM this reference is thus stored into an PojoReference (as a transient field).
* In addition, this instance also serves as a metadata for PojoCache. E.g., it has a reference counting for
* multiple references and reference FQN.
*
* @author Ben Wang
*/
public class PojoInstance implements Serializable // Externalizable is no more efficient
{
// protected static Log log=LogFactory.getLog(PojoReference.class.getName());
public static final Object KEY = "PojoInstance";
public static final int INITIAL_COUNTER_VALUE = -1;
static final long serialVersionUID = 6492134565825613209L;
// The instance is transient to avoid replication outside the VM
private transient Object instance_;
// If not null, it signifies that this is a reference that points to this fqn.
// Note that this will get replicated.
private String internalFqn_ = null;
// Reference counting. THis will get replicated as well. This keep track of number of
// other instances that referenced this fqn.
private int refCount_ = INITIAL_COUNTER_VALUE;
// List of fqns that reference this fqn. Assume list size is not big since it may not be efficient.
private List referencedBy_ = null;
private Class clazz_ = null;
public PojoInstance()
{
}
public PojoInstance(Object instance)
{
set(instance);
}
public void setPojoClass(Class clazz)
{
clazz_ = clazz;
}
public Class getPojoClass()
{
return clazz_;
}
public Object get()
{
return instance_;
}
public void set(Object instance)
{
instance_ = instance;
}
public String getInternalFqn()
{
return internalFqn_;
}
public void setInternalFqn(String refFqn)
{
internalFqn_ = refFqn;
}
public void removeInternalFqn()
{
internalFqn_ = null;
}
synchronized public int incrementRefCount(Fqn sourceFqn)
{
if(sourceFqn != null)
{
if (referencedBy_ == null)
{
referencedBy_ = new ArrayList();
}
if (referencedBy_.contains(sourceFqn))
throw new IllegalStateException("PojoReference.incrementRefCount(): source fqn: " +
sourceFqn + " is already present.");
referencedBy_.add(sourceFqn);
}
refCount_ += 1;
//logger_.info("incrementRefCount(): current ref count " +refCount_);
return refCount_;
}
synchronized public int decrementRefCount(Fqn sourceFqn)
{
if(sourceFqn != null)
{
if (!referencedBy_.contains(sourceFqn))
throw new IllegalStateException("PojoReference.decrementRefCount(): source fqn: " +
sourceFqn + " is not present.");
referencedBy_.remove(sourceFqn);
}
refCount_ -= 1;
//logger_.info("decrementRefCount(): current ref count " +refCount_);
return refCount_;
}
synchronized public int getRefCount()
{
return refCount_;
}
synchronized public Fqn getAndRemoveFirstFqnInList()
{
return (Fqn) referencedBy_.remove(0);
}
synchronized public void addXFqnIntoList(Fqn fqn)
{
referencedBy_.add(0, fqn);
}
}
More information about the jboss-cvs-commits
mailing list