[Jboss-cvs] JBossAS SVN: r56325 - branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 28 01:35:59 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-08-28 01:35:58 -0400 (Mon, 28 Aug 2006)
New Revision: 56325
Modified:
branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheService.java
Log:
Tighten up add/removeObserver; move type parsing from JBCService to Util
Modified: branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheService.java
===================================================================
--- branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheService.java 2006-08-28 05:34:55 UTC (rev 56324)
+++ branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheService.java 2006-08-28 05:35:58 UTC (rev 56325)
@@ -25,9 +25,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -35,7 +33,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Stack;
import java.util.StringTokenizer;
import java.util.WeakHashMap;
@@ -48,6 +45,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.aop.PojoCacheMBean;
+import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.transaction.BatchModeTransactionManager;
import org.jboss.invocation.MarshalledValue;
import org.jboss.invocation.MarshalledValueInputStream;
@@ -66,33 +64,12 @@
* </ul>
*/
public class JBossCacheService
-{
- // Types that are considered "primitive".
- private static final Set immediates =
- new HashSet(Arrays.asList(new Object[]{
- String.class,
- Boolean.class,
- Double.class,
- Float.class,
- Integer.class,
- Long.class,
- Short.class,
- Character.class,
- Boolean.TYPE,
- Double.TYPE,
- Float.TYPE,
- Integer.TYPE,
- Long.TYPE,
- Short.TYPE,
- Character.TYPE,
- Class.class}));
-
+{
protected static Logger log_ = Logger.getLogger(JBossCacheService.class);
- public static final String BUDDY_BACKUP = "_BUDDY_BACKUP_";
- public static final Fqn BUDDY_BACKUP_FQN = new Fqn("_BUDDY_BACKUP_");
+ public static final String BUDDY_BACKUP = BuddyManager.BUDDY_BACKUP_SUBTREE;
+ public static final Fqn BUDDY_BACKUP_FQN = BuddyManager.BUDDY_BACKUP_SUBTREE_FQN;
public static final String SESSION = "JSESSION";
public static final String ATTRIBUTE = "ATTRIBUTE";
- public static final String KEY = "ATRR_KEY";
// Needed for cache invalidation
static final String VERSION_KEY = "VERSION";
static final String FQN_DELIMITER = "/";
@@ -692,10 +669,10 @@
*/
public void addObserver(Observer session, Object pojo)
{
- addObserver(session, pojo, new Stack());
+ addObserver(session, pojo, new HashSet());
}
- private void addObserver(Observer session, Object pojo, Stack stack)
+ private void addObserver(Observer session, Object pojo, Set processed)
{
if ( pojo instanceof Collection )
{
@@ -703,7 +680,7 @@
for (Iterator i = col.iterator(); i.hasNext();) {
Object obj = i.next();
// If not a managed pojo, will return anyway
- addObserver(session, obj, stack);
+ addObserver(session, obj, processed);
}
return;
@@ -716,8 +693,8 @@
Object value = map.get(key);
// Walk thru key and value
- addObserver(session, key, stack);
- addObserver(session, value, stack);
+ addObserver(session, key, processed);
+ addObserver(session, value, processed);
}
return;
@@ -748,12 +725,15 @@
Set complexFields = (Set) typeMap.get(type);
if (complexFields == null)
{
- complexFields = parseComplexFields(type);
+ complexFields = Util.parseComplexFields(type);
typeMap.put(type, complexFields);
}
+
+ if (complexFields.size() == 0)
+ return;
- // Store a ref to the pojo on the stack to avoid cyclic additions
- stack.push(pojo);
+ // Store a ref to the pojo to avoid cyclic additions
+ processed.add(pojo);
for (Iterator iter = complexFields.iterator(); iter.hasNext();)
{
@@ -772,8 +752,8 @@
value=field.get(pojo);
// Continue recursively unless we've already handled this value
- if (value != null && !stack.contains(value))
- addObserver(session, value, stack);
+ if (value != null && !processed.contains(value))
+ addObserver(session, value, processed);
break;
}
catch(IllegalAccessException e)
@@ -795,8 +775,6 @@
}
}
}
-
- stack.pop();
}
/**
@@ -810,10 +788,10 @@
*/
public void removeObserver(Observer session, Object pojo)
{
- removeObserver(session, pojo, new Stack());
+ removeObserver(session, pojo, new HashSet());
}
- private void removeObserver(Observer session, Object pojo, Stack stack)
+ private void removeObserver(Observer session, Object pojo, Set stack)
{
if ( pojo instanceof Collection )
{
@@ -864,13 +842,16 @@
Set complexFields = (Set) typeMap.get(type);
if (complexFields == null)
{
- complexFields = parseComplexFields(type);
+ complexFields = Util.parseComplexFields(type);
typeMap.put(type, complexFields);
}
- // Store a ref to the pojo on the stack to avoid cyclic additions
- stack.push(pojo);
+ if (complexFields.size() == 0)
+ return;
+ // Store a ref to the pojo to avoid cyclic removals
+ stack.add(pojo);
+
for (Iterator iter = complexFields.iterator(); iter.hasNext();)
{
String fieldName = (String) iter.next();
@@ -911,15 +892,13 @@
}
}
}
-
- stack.pop();
}
private Fqn getFieldFqn(String id, String key)
{
// /SESSION/id/ATTR/key
// Guard against string with delimiter.
- List list = new ArrayList();
+ List list = new ArrayList(6);
list.add(SESSION);
list.add(hostName_);
list.add(webAppPath_);
@@ -1073,46 +1052,5 @@
}
}
-
- private Set parseComplexFields(Class clazz)
- {
- Set result = new HashSet();
-
- while (clazz != null)
- {
- Field[] fields = clazz.getDeclaredFields();
- for (int i = 0; i < fields.length; i++)
- {
- if (!immediates.contains(fields[i].getType())
- && isReplicatable(fields[i]))
- {
- result.add(fields[i].getName());
- }
- }
-
- clazz = clazz.getSuperclass();
- }
- return result;
- }
- /**
- * Returns false if the given field is static, transient or final.
- *
- * @param f the field
- * @return
- */
- private static boolean isReplicatable(Field f) {
- int mods = f.getModifiers();
- /**
- * The following modifiers are ignored in the cache, i.e., they will not be stored in the cache.
- * Whenever, user trying to access these fields, it will be accessed from the in-memory version.
- */
- if (Modifier.isStatic(mods)
- || Modifier.isTransient(mods)
- || Modifier.isFinal(mods)) {
- return false;
- }
- return true;
- }
-
}
More information about the jboss-cvs-commits
mailing list