[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/collection ...
Jason Thomas Greene
jgreene at jboss.com
Thu May 31 15:11:06 EDT 2007
User: jgreene
Date: 07/05/31 15:11:06
Modified: src/org/jboss/cache/pojo/collection CachedListImpl.java
CachedMapImpl.java CachedSetImpl.java
Log:
Add collection notifications
Revision Changes Path
1.2 +50 -21 JBossCache/src/org/jboss/cache/pojo/collection/CachedListImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedListImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/collection/CachedListImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CachedListImpl.java 13 Jan 2007 15:55:05 -0000 1.1
+++ CachedListImpl.java 31 May 2007 19:11:06 -0000 1.2
@@ -6,6 +6,17 @@
*/
package org.jboss.cache.pojo.collection;
+import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
+
+import java.io.ObjectStreamException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
@@ -17,15 +28,6 @@
import org.jboss.cache.pojo.util.CacheApiUtil;
import org.jboss.cache.pojo.util.Null;
-import java.io.ObjectStreamException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
/**
* List implementation that uses cache as a backend store.
*
@@ -100,8 +102,7 @@
{
if (index != 0)
checkIndex(); // Since index can be size().
- return Null.toNullValue(pCache_.attach(AopUtil.constructFqn(getFqn(),
- IntegerCache.toString(index)), Null.toNullObject(element)));
+ return Null.toNullValue(attach(index, element, "SET"));
}
public void add(int index, Object element)
@@ -110,10 +111,38 @@
checkIndex(); // Since index can be size().
for (int i = size(); i > index; i--)
{
- Object obj = pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i - 1)));
- pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)), obj);
+ Object obj = detach(i - 1);
+ attach(i, obj);
+ }
+ attach(index, element, "ADD");
+ }
+
+ private Object attach(int i, Object obj)
+ {
+ return attach(i, obj, null);
+ }
+
+ private Object attach(int i, Object obj, String operation)
+ {
+ Fqn fqn = AopUtil.constructFqn(getFqn(), IntegerCache.toString(i));
+ Object o = pCache_.attach(fqn, Null.toNullObject(obj));
+ if (operation != null)
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, operation);
+
+ return o;
+ }
+
+ private Object detach(int i)
+ {
+ return detach(i, null);
}
- pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index)), Null.toNullObject(element));
+
+ private Object detach(int i, String operation)
+ {
+ Fqn fqn = AopUtil.constructFqn(getFqn(), IntegerCache.toString(i));
+ if (operation != null)
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, operation);
+ return pCache_.detach(fqn);
}
public int indexOf(Object o)
@@ -162,15 +191,15 @@
checkIndex();
// Object result = cache.removeObject(((Fqn) fqn.clone()).add(new Integer(index)));
int size = size();
- Object result = Null.toNullValue(pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index))));
+ Object result = Null.toNullValue(detach(index, "REMOVE"));
if (size == (index + 1))
{
return result; // We are the last one.
}
for (int i = index; i < size - 1; i++)
{
- Object obj = pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i + 1)));
- pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)), obj);
+ Object obj = detach(i + 1);
+ attach(i, obj);
}
return result;
}
@@ -213,16 +242,16 @@
if (current < (size - 1))
{
// Need to reshuffle the items.
- Object last = pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(current)));
+ Object last = detach(current, "REMOVE");
for (int i = current + 1; i < size; i++)
{
- last = pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)));
- pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i - 1)), last);
+ last = detach(i);
+ attach(i - 1, last);
}
} else
{ // we are the last index.
// Need to move back the cursor.
- pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(current)));
+ detach(current, "REMOVE");
}
current--;
size--;
1.2 +24 -6 JBossCache/src/org/jboss/cache/pojo/collection/CachedMapImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedMapImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/collection/CachedMapImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CachedMapImpl.java 13 Jan 2007 15:55:05 -0000 1.1
+++ CachedMapImpl.java 31 May 2007 19:11:06 -0000 1.2
@@ -6,6 +6,8 @@
*/
package org.jboss.cache.pojo.collection;
+import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
+
import org.jboss.aop.Advised;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
@@ -61,12 +63,28 @@
return new Fqn(baseFqn, relative);
}
-
private Fqn getFqn()
{
return interceptor_.getFqn();
}
+ private Object attach(Object key, Object value)
+ {
+ Fqn fqn = constructFqn(getFqn(), Null.toNullKeyObject(key));
+ Object o = pCache_.attach(fqn, Null.toNullObject(value));
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, "PUT");
+
+ return o;
+ }
+
+ private Object detach(Object key)
+ {
+ Fqn fqn = constructFqn(getFqn(), Null.toNullKeyObject(key));
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, "REMOVE");
+
+ return pCache_.detach(fqn);
+ }
+
// implementation of the java.util.Map interface
private Set<Node> getNodeChildren()
@@ -81,7 +99,7 @@
public Object put(Object key, Object value)
{
- return pCache_.attach(constructFqn(getFqn(), Null.toNullKeyObject(key)), Null.toNullObject(value));
+ return attach(key, value);
}
public void putAll(Map map)
@@ -95,7 +113,7 @@
public Object remove(Object key)
{
- return pCache_.detach(constructFqn(getFqn(), Null.toNullKeyObject(key)));
+ return detach(key);
}
public void clear()
@@ -358,7 +376,7 @@
public Object setValue(Object value)
{
- return pCache_.attach(constructFqn(getFqn(), key), Null.toNullObject(value));
+ return attach(key, value);
}
public int hashCode()
1.2 +35 -8 JBossCache/src/org/jboss/cache/pojo/collection/CachedSetImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedSetImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/collection/CachedSetImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CachedSetImpl.java 13 Jan 2007 15:55:05 -0000 1.1
+++ CachedSetImpl.java 31 May 2007 19:11:06 -0000 1.2
@@ -6,6 +6,8 @@
*/
package org.jboss.cache.pojo.collection;
+import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
+
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
@@ -76,7 +78,7 @@
Object o2 = getNoUnmask(key);
if (o2 == null)
{
- attachNoMask(key, o);
+ attach(key, o, true);
return true;
}
if (o.equals(o2))
@@ -146,12 +148,12 @@
if (removed)
{
// move o2 to old key
- pCache_.detach(AopUtil.constructFqn(getFqn(), key));
- pCache_.attach(AopUtil.constructFqn(getFqn(), oldkey), o2);
+ detach(key);
+ attach(oldkey, o2);
}
if (o.equals(o2))
{
- pCache_.detach(AopUtil.constructFqn(getFqn(), key));
+ detach(key, true);
removed = true;
}
oldkey = key;
@@ -189,9 +191,34 @@
return Long.toHexString(key);
}
- private Object attachNoMask(Object key, Object pojo)
+
+ private Object attach(Object key, Object pojo)
+ {
+ return attach(key, pojo, false);
+ }
+
+ private Object attach(Object key, Object pojo, boolean add)
+ {
+ Fqn fqn = AopUtil.constructFqn(getFqn(), key);
+ Object o = pCache_.attach(fqn, pojo);
+ if (add)
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, "ADD");
+
+ return o;
+ }
+
+ private Object detach(Object key)
{
- return pCache_.attach(AopUtil.constructFqn(getFqn(), key), pojo);
+ return detach(key, false);
+ }
+
+ private Object detach(Object key, boolean remove)
+ {
+ Fqn fqn = AopUtil.constructFqn(getFqn(), key);
+ if (remove)
+ pCache_.getCache().put(fqn, POJOCACHE_OPERATION, "REMOVE");
+
+ return pCache_.detach(fqn);
}
private Object getNoUnmask(Object key)
More information about the jboss-cvs-commits
mailing list