[jboss-cvs] JBossAS SVN: r104549 - in projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src: test/java/org/jboss/web/tomcat/service/session/distributedcache/impl and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 6 23:33:35 EDT 2010
Author: bstansberry at jboss.com
Date: 2010-05-06 23:33:33 -0400 (Thu, 06 May 2010)
New Revision: 104549
Modified:
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListenerBase.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/PassivationListener.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/CacheListenerUnitTestCase.java
Log:
Sync to 2.0.1.GA release
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -24,10 +24,12 @@
import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -69,6 +71,7 @@
@SuppressWarnings("unchecked")
public static final Fqn<String> BUDDY_BACKUP_FQN = BuddyManager.BUDDY_BACKUP_SUBTREE_FQN;
public static final String SESSION = "JSESSION";
+ public static final String DEAD_BUDDY_SUFFIX = ":DEAD";
// Use Integers as JBC keys -- replication performant but won't be
// confused with String attribute keys for ATTRIBUTE granularity sessions
@@ -92,6 +95,7 @@
return Fqn.fromList(Arrays.asList(objs), true);
}
+ @Deprecated
public static Fqn<String> getBuddyBackupSessionFqn(String dataOwner, String contextHostPath, String sessionId)
{
String[] objs = new String[]{BUDDY_BACKUP, dataOwner, SESSION, contextHostPath, sessionId};
@@ -461,34 +465,71 @@
}
else
{
- Fqn<String> fqn = getBuddyBackupSessionFqn(dataOwner, combinedPath_, realId);
- if (log_.isTraceEnabled())
+ List<Fqn<Object>> fqns = getBuddyBackupSessionFqns(dataOwner, combinedPath_, realId);
+ for (Fqn<Object> fqn : fqns)
{
- log_.trace("Remove session from my own distributed store only. Fqn: " + fqn);
+ if (log_.isTraceEnabled())
+ {
+ log_.trace("Remove session from my own distributed store only. Fqn: " + fqn);
+ }
+ cacheWrapper_.removeLocal(fqn);
}
- cacheWrapper_.removeLocal(fqn);
}
}
public void evictSession(String realId)
{
- evictSession(realId, null);
+ Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
+ if(log_.isTraceEnabled())
+ {
+ log_.trace("evictSession(): evicting session from my distributed store. Fqn: " + fqn);
+ }
+ cacheWrapper_.evictSubtree(fqn);
}
public void evictSession(String realId, String dataOwner)
{
- Fqn<String> fqn = dataOwner == null ? getSessionFqn(combinedPath_, realId) : getBuddyBackupSessionFqn(dataOwner, combinedPath_, realId);
- if(log_.isTraceEnabled())
+ if (dataOwner == null)
{
- log_.trace("evictSession(): evicting session from my distributed store. Fqn: " + fqn);
+ evictSession(realId);
}
- cacheWrapper_.evictSubtree(fqn);
+ else
+ {
+ List<Fqn<Object>> fqns = getBuddyBackupSessionFqns(dataOwner, combinedPath_, realId);
+ for (Fqn<Object> fqn : fqns)
+ {
+ if(log_.isTraceEnabled())
+ {
+ log_.trace("evictSession(): evicting session from my distributed store. Fqn: " + fqn);
+ }
+ cacheWrapper_.evictSubtree(fqn);
+ }
+ }
}
public IncomingDistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes)
{
- Fqn<String> fqn = dataOwner == null ? getSessionFqn(combinedPath_, realId) : getBuddyBackupSessionFqn(dataOwner, combinedPath_, realId);
- Map<Object, Object> distributedCacheData = cacheWrapper_.getData(fqn, false);
+ Map<Object, Object> distributedCacheData = null;
+ if (dataOwner == null)
+ {
+ Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
+ distributedCacheData = cacheWrapper_.getData(fqn, false);
+ }
+ else
+ {
+ List<Fqn<Object>> fqns = getBuddyBackupSessionFqns(dataOwner, combinedPath_, realId);
+ for (Fqn<Object> fqn : fqns)
+ {
+ distributedCacheData = cacheWrapper_.getData(fqn, false);
+ // Above call will return an empty map if fqn doesn't exist;
+ // once we get a non-empty on that's the real data
+ if (distributedCacheData.size() > 0)
+ {
+ break;
+ }
+ }
+ }
+
return getDistributableSessionData(realId, distributedCacheData, includeAttributes);
}
@@ -677,6 +718,25 @@
}
}
}
+
+ private List<Fqn<Object>> getBuddyBackupSessionFqns(String dataOwner, String contextHostPath, String sessionId)
+ {
+ List<Fqn<Object>> result = new ArrayList<Fqn<Object>>();
+ // First, just assume a non-dead tree exists
+ Object[] objs = new Object[]{BUDDY_BACKUP, dataOwner, SESSION, contextHostPath, sessionId};
+ result.add(Fqn.fromList(Arrays.asList(objs), true));
+
+ // Now append any "dead" trees associated with this owner
+ String deadBuddy = dataOwner + DEAD_BUDDY_SUFFIX;
+ Fqn<String> dead = Fqn.fromElements(BUDDY_BACKUP, deadBuddy);
+ Set<Object> buddies = plainCache_.getChildrenNames(dead); // won't return null
+ for (Object child : buddies)
+ {
+ objs = new Object[]{BUDDY_BACKUP, deadBuddy, child, SESSION, contextHostPath, sessionId};
+ result.add(Fqn.fromList(Arrays.asList(objs), true));
+ }
+ return result;
+ }
private void cleanWebappRegion(Fqn<String> regionFqn)
{
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -77,28 +77,30 @@
@SuppressWarnings("unchecked")
Fqn<String> fqn = event.getFqn();
- boolean isBuddy = isBuddyFqn(fqn);
+ boolean isBuddy = isBuddyFqn(fqn);
+ int baseIdx = getJSessionIndex(fqn, isBuddy);
if (!local
- && isFqnSessionRootSized(fqn, isBuddy)
- && isFqnForOurWebapp(fqn, isBuddy))
+ && isFqnSessionRootSized(fqn, baseIdx)
+ && isFqnForOurWebapp(fqn, baseIdx))
{
// A session has been invalidated from another node;
// need to inform manager
- String sessId = getIdFromFqn(fqn, isBuddy);
+ String sessId = getIdFromFqn(fqn, baseIdx);
manager_.notifyRemoteInvalidation(sessId);
}
else if (local && !isBuddy
- && isPossibleInternalPojoFqn(fqn)
- && isFqnForOurWebapp(fqn, isBuddy))
+ && isPossibleInternalPojoFqn(fqn, baseIdx)
+ && isFqnForOurWebapp(fqn, baseIdx))
{
// One of our sessions' pojos is modified; need to inform
// the manager so it can mark the session dirty
- String sessId = getIdFromFqn(fqn, isBuddy);
+ String sessId = getIdFromFqn(fqn, baseIdx);
manager_.notifyLocalAttributeModification(sessId);
}
- }
+ }
+
@NodeModified
public void nodeModified(NodeModifiedEvent event)
{
@@ -111,11 +113,12 @@
@SuppressWarnings("unchecked")
Fqn<String> fqn = event.getFqn();
- boolean isBuddy = isBuddyFqn(fqn);
+ boolean isBuddy = isBuddyFqn(fqn);
+ int baseIdx = getJSessionIndex(fqn, isBuddy);
if (!local
- &&isFqnSessionRootSized(fqn, isBuddy)
- &&isFqnForOurWebapp(fqn, isBuddy))
+ && isFqnSessionRootSized(fqn, baseIdx)
+ && isFqnForOurWebapp(fqn, baseIdx))
{
// Query if we have version value in the distributed cache.
// If we have a version value, compare the version and invalidate if necessary.
@@ -124,7 +127,7 @@
Integer version = (Integer) data.get(AbstractJBossCacheService.VERSION_KEY);
if(version != null)
{
- String realId = getIdFromFqn(fqn, isBuddy);
+ String realId = getIdFromFqn(fqn, baseIdx);
String owner = isBuddy ? getBuddyOwner(fqn) : null;
Long timestamp = (Long) data.get(AbstractJBossCacheService.TIMESTAMP_KEY);
if (timestamp == null)
@@ -158,19 +161,26 @@
}
}
else if (local && !isBuddy
- && isPossibleInternalPojoFqn(fqn)
- && isFqnForOurWebapp(fqn, isBuddy))
+ && isPossibleInternalPojoFqn(fqn, baseIdx)
+ && isFqnForOurWebapp(fqn, baseIdx))
{
// One of our sessions' pojos is modified; need to inform
// the manager so it can mark the session dirty
- String sessId = getIdFromFqn(fqn, isBuddy);
+ String sessId = getIdFromFqn(fqn, baseIdx);
manager_.notifyLocalAttributeModification(sessId);
}
}
+ public static String getPojoKeyFromFqn(Fqn<String> fqn, int jsessionIndex)
+ {
+ return (String) fqn.get(jsessionIndex + POJO_KEY_FQN_INDEX);
+ }
+
+ @Deprecated
public static String getPojoKeyFromFqn(Fqn<String> fqn, boolean isBuddy)
{
- return (String) fqn.get(isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + POJO_KEY_FQN_INDEX: POJO_KEY_FQN_INDEX);
+ int index = getJSessionIndex(fqn, isBuddy);
+ return getPojoKeyFromFqn(fqn, index);
}
/**
@@ -191,12 +201,41 @@
* based on != ATTRIBUTE to avoid having to code to the internal PojoCache
* _JBossInternal_ name.
*
+ * @param fqn the
+ * @param
+ * @return
+ */
+ public static boolean isPossibleInternalPojoFqn(Fqn<String> fqn, int jsessionIndex)
+ {
+ return (jsessionIndex > -1 && fqn.size() > jsessionIndex + POJO_INTERNAL_FQN_SIZE
+ && FieldBasedJBossCacheService.ATTRIBUTE.equals(fqn.get(jsessionIndex + POJO_INTERNAL_FQN_INDEX)) == false);
+ }
+
+ /**
+ * Check if the fqn is big enough to be in the internal pojo area but
+ * isn't in the regular attribute area.
+ *
+ * Structure in the cache is:
+ *
+ * /JSESSION
+ * ++ /contextPath_hostname
+ * ++++ /sessionid
+ * ++++++ /ATTRIBUTE
+ * ++++++ /_JBossInternal_
+ * ++++++++ etc etc
+ *
+ * If the Fqn size is big enough to be "etc etc" or lower, but the 4th
+ * level is not "ATTRIBUTE", it must be under _JBossInternal_. We discriminate
+ * based on != ATTRIBUTE to avoid having to code to the internal PojoCache
+ * _JBossInternal_ name.
+ *
* @param fqn
* @return
*/
+ @Deprecated
public static boolean isPossibleInternalPojoFqn(Fqn<String> fqn)
{
- return (fqn.size() > POJO_INTERNAL_FQN_SIZE
- && FieldBasedJBossCacheService.ATTRIBUTE.equals(fqn.get(POJO_INTERNAL_FQN_INDEX)) == false);
+ int index = getJSessionIndex(fqn, false);
+ return isPossibleInternalPojoFqn(fqn, index);
}
}
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListenerBase.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListenerBase.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListenerBase.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -33,12 +33,14 @@
public class CacheListenerBase
{
- private static final int JSESSION_FQN_INDEX = 0;
private static final int WEBAPP_FQN_INDEX = 1;
protected static final int SESSION_ID_FQN_INDEX = 2;
private static final int SESSION_FQN_SIZE = SESSION_ID_FQN_INDEX + 1;
private static final int BUDDY_BACKUP_ROOT_OWNER_INDEX = BuddyManager.BUDDY_BACKUP_SUBTREE_FQN.size();
protected static final int BUDDY_BACKUP_ROOT_OWNER_SIZE = BUDDY_BACKUP_ROOT_OWNER_INDEX + 1;
+ private static final String DEAD_BUDDY_SUFFIX = ":DEAD";
+ private static final String JSESSION = AbstractJBossCacheService.SESSION;
+
protected LocalDistributableSessionManager manager_;
private String contextHostPath_;
@@ -47,31 +49,77 @@
this.manager_ = manager;
this.contextHostPath_ = contextHostPath;
}
-
- protected boolean isFqnForOurWebapp(Fqn<String> fqn, boolean isBuddy)
+
+ public static final int getJSessionIndex(Fqn<String> fqn, boolean isBuddy)
{
try
{
- if (contextHostPath_.equals(fqn.get(isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + WEBAPP_FQN_INDEX : WEBAPP_FQN_INDEX))
- && AbstractJBossCacheService.SESSION.equals(fqn.get(isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + JSESSION_FQN_INDEX : JSESSION_FQN_INDEX)))
- return true;
+ if (!isBuddy && JSESSION.equals(fqn.get(0)))
+ {
+ return 0;
+ }
+ else if (isBuddy)
+ {
+ if (JSESSION.equals(fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX + 1)))
+ {
+ return BUDDY_BACKUP_ROOT_OWNER_INDEX + 1;
+ }
+ else if (JSESSION.equals(fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX + 2)))
+ {
+ return BUDDY_BACKUP_ROOT_OWNER_INDEX + 2;
+ }
+ }
}
catch (IndexOutOfBoundsException e)
{
+ // too small; just fall through
+ }
+ return -1;
+ }
+
+ protected boolean isFqnForOurWebapp(Fqn<String> fqn, int jsessionIndex)
+ {
+ try
+ {
+ return (jsessionIndex > -1 && contextHostPath_.equals(fqn.get(jsessionIndex + WEBAPP_FQN_INDEX)));
+ }
+ catch (IndexOutOfBoundsException e)
+ {
// can't be ours; too small; just fall through
}
return false;
}
+ @Deprecated
+ protected boolean isFqnForOurWebapp(Fqn<String> fqn, boolean isBuddy)
+ {
+ int index = getJSessionIndex(fqn, isBuddy);
+ return isFqnForOurWebapp(fqn, index);
+ }
+
+ public static boolean isFqnSessionRootSized(Fqn<String> fqn, int jsessionIndex)
+ {
+ return fqn.size() == jsessionIndex + SESSION_FQN_SIZE;
+ }
+
+ @Deprecated
public static boolean isFqnSessionRootSized(Fqn<String> fqn, boolean isBuddy)
{
- return fqn.size() == (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + SESSION_FQN_SIZE : SESSION_FQN_SIZE);
+ int index = getJSessionIndex(fqn, isBuddy);
+ return (isBuddy ? index > 0 && isFqnSessionRootSized(fqn, index) : isFqnSessionRootSized(fqn, index));
}
+ public static String getIdFromFqn(Fqn<String> fqn, int jsessionIndex)
+ {
+ return (String)fqn.get(jsessionIndex + SESSION_ID_FQN_INDEX);
+ }
+
+ @Deprecated
public static String getIdFromFqn(Fqn<String> fqn, boolean isBuddy)
{
- return (String)fqn.get(isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + SESSION_ID_FQN_INDEX : SESSION_ID_FQN_INDEX);
+ int index = getJSessionIndex(fqn, isBuddy);
+ return getIdFromFqn(fqn, index);
}
public static boolean isBuddyFqn(Fqn<String> fqn)
@@ -96,6 +144,7 @@
*/
public static String getBuddyOwner(Fqn<String> fqn)
{
- return (String) fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX);
+ String base = (String) fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX);
+ return base.endsWith(DEAD_BUDDY_SUFFIX) ? base.substring(0, base.length() - DEAD_BUDDY_SUFFIX.length()): base;
}
}
\ No newline at end of file
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheWrapper.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -24,7 +24,9 @@
import java.util.Map;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.SuspectException;
import org.jboss.cache.lock.TimeoutException;
public class JBossCacheWrapper
@@ -40,9 +42,9 @@
plainCache_ = cache;
}
- Map<Object, Object> getData(Fqn<String> fqn, boolean gravitate)
+ Map<Object, Object> getData(Fqn<?> fqn, boolean gravitate)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -58,6 +60,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
@@ -69,7 +75,7 @@
* @param id
* @return
*/
- Object get(Fqn<String> fqn, String id)
+ Object get(Fqn<?> fqn, String id)
{
return get(fqn, id, false);
}
@@ -81,9 +87,9 @@
* @param id
* @return
*/
- Object get(Fqn<String> fqn, String id, boolean gravitate)
+ Object get(Fqn<?> fqn, String id, boolean gravitate)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -99,6 +105,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
@@ -112,9 +122,9 @@
* @param value
* @return
*/
- void put(Fqn<String> fqn, String id, Object value)
+ void put(Fqn<?> fqn, String id, Object value)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -126,6 +136,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
@@ -138,9 +152,9 @@
* @param fqn
* @param map
*/
- void put(Fqn<String> fqn, Map<Object, Object> map)
+ void put(Fqn<?> fqn, Map<Object, Object> map)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -152,6 +166,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
@@ -164,9 +182,9 @@
* @param id
* @return
*/
- Object remove(Fqn<String> fqn, String id)
+ Object remove(Fqn<?> fqn, String id)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -177,6 +195,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
@@ -189,7 +211,7 @@
* @param id
* @return
*/
- Object removeLocal(Fqn<String> fqn, String id)
+ Object removeLocal(Fqn<?> fqn, String id)
{
TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
@@ -214,9 +236,9 @@
*
* @param fqn
*/
- void remove(Fqn<String> fqn)
+ void remove(Fqn<?> fqn)
{
- TimeoutException ex = null;
+ CacheException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -228,6 +250,10 @@
{
ex = e;
}
+ catch (SuspectException e)
+ {
+ ex = e;
+ }
}
throw new RuntimeException(RETRY_FAIL_MSG, ex);
@@ -238,7 +264,7 @@
*
* @param fqn
*/
- void removeLocal(Fqn<String> fqn)
+ void removeLocal(Fqn<?> fqn)
{
TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
@@ -259,7 +285,7 @@
throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
- void evictSubtree(Fqn<String> fqn)
+ void evictSubtree(Fqn<?> fqn)
{
TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/PassivationListener.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/PassivationListener.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/PassivationListener.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -65,9 +65,9 @@
{
@SuppressWarnings("unchecked")
Fqn<String> fqn = event.getFqn();
- boolean isBuddy = isBuddyFqn(fqn);
- if (isFqnSessionRootSized(fqn, isBuddy)
- && isFqnForOurWebapp(fqn, isBuddy))
+ int baseIdx = getJSessionIndex(fqn, isBuddyFqn(fqn));
+ if (isFqnSessionRootSized(fqn, baseIdx)
+ && isFqnForOurWebapp(fqn, baseIdx))
{
manager_.sessionActivated();
}
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/CacheListenerUnitTestCase.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/CacheListenerUnitTestCase.java 2010-05-07 03:32:56 UTC (rev 104548)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/CacheListenerUnitTestCase.java 2010-05-07 03:33:33 UTC (rev 104549)
@@ -26,6 +26,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.AbstractJBossCacheService;
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.CacheListener;
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.CacheListenerBase;
import org.jboss.web.tomcat.service.session.distributedcache.impl.jbc.FieldBasedJBossCacheService;
@@ -34,17 +35,17 @@
/**
* A CacheListenerUnitTestCase.
*
- * FIXME: Move this to the ha-server-cache-jbc project
- *
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
public class CacheListenerUnitTestCase extends TestCase
{
private static final String DATA_OWNER = "localhost_12345";
+ private static final String DEAD_DATA_OWNER = "localhost_12345:DEAD";
private static final String CONTEXT_HOST_PATH = SessionBasedJBossCacheService.getCombinedPath("localhost", "webapp");
- private static final Fqn BASE = SessionBasedJBossCacheService.getSessionFqn(CONTEXT_HOST_PATH, "123");
- private static final Fqn BUDDY_BASE = SessionBasedJBossCacheService.getBuddyBackupSessionFqn(DATA_OWNER, CONTEXT_HOST_PATH, "123");
+ private static final Fqn<String> BASE = SessionBasedJBossCacheService.getSessionFqn(CONTEXT_HOST_PATH, "123");
+ private static final Fqn<String> BUDDY_BASE = Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, DATA_OWNER, AbstractJBossCacheService.SESSION, CONTEXT_HOST_PATH, "123");
+ private static final Fqn<String> DEAD_BUDDY_BASE = Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, DEAD_DATA_OWNER, "1", AbstractJBossCacheService.SESSION, CONTEXT_HOST_PATH, "123");
public void testIsBuddyFqn()
{
@@ -62,13 +63,65 @@
public void testGetBuddyBackupOwner()
{
- Fqn test = BUDDY_BASE;
+ Fqn<String> test = BUDDY_BASE;
assertEquals("Got correct owner", DATA_OWNER, CacheListenerBase.getBuddyOwner(test));
+ test = DEAD_BUDDY_BASE;
+ assertEquals("Got correct owner from dead tree", DATA_OWNER, CacheListenerBase.getBuddyOwner(test));
}
+ public void testGetJSessionIndex()
+ {
+ Fqn<String> test = BASE;
+ assertEquals(0, CacheListenerBase.getJSessionIndex(test, false));
+ assertEquals(-1, CacheListenerBase.getJSessionIndex(test, true));
+
+ test = BUDDY_BASE;
+ assertEquals(2, CacheListenerBase.getJSessionIndex(test, true));
+ assertEquals(-1, CacheListenerBase.getJSessionIndex(test, false));
+
+ test = DEAD_BUDDY_BASE;
+ assertEquals(3, CacheListenerBase.getJSessionIndex(test, true));
+ assertEquals(-1, CacheListenerBase.getJSessionIndex(test, false));
+
+ assertEquals(-1, CacheListenerBase.getJSessionIndex(Fqn.ROOT, false));
+ }
+
public void testIsFqnSessionRootSized()
{
- Fqn test = BASE;
+ Fqn<String> test = BASE;
+ int idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertTrue("Non-buddy session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = BUDDY_BASE;
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertTrue("Buddy session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = Fqn.fromRelativeElements(BASE, FieldBasedJBossCacheService.ATTRIBUTE);
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertFalse("Non-buddy non-session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = BUDDY_BASE;
+ test = Fqn.fromRelativeElements(test, FieldBasedJBossCacheService.ATTRIBUTE);
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertFalse("Buddy non-session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = DEAD_BUDDY_BASE;
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertTrue("Buddy session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = Fqn.fromRelativeElements(test, FieldBasedJBossCacheService.ATTRIBUTE);
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertFalse("Buddy non-session root correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+
+ test = Fqn.ROOT;
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertFalse("Fqn.ROOT correct", CacheListenerBase.isFqnSessionRootSized(test, idx));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testIsFqnSessionRootSizedDeprecated()
+ {
+ Fqn<String> test = BASE;
assertTrue("Non-buddy session root correct", CacheListenerBase.isFqnSessionRootSized(test, false));
assertFalse("Non-buddy session root correct with wrong isBuddy", CacheListenerBase.isFqnSessionRootSized(test, true));
@@ -82,11 +135,39 @@
test = BUDDY_BASE;
test = Fqn.fromRelativeElements(test, FieldBasedJBossCacheService.ATTRIBUTE);
assertFalse("Buddy non-session root correct", CacheListenerBase.isFqnSessionRootSized(test, true));
+
+ test = DEAD_BUDDY_BASE;
+ assertTrue("Buddy session root correct", CacheListenerBase.isFqnSessionRootSized(test, true));
+ assertFalse("Buddy session root correct with wrong isBuddy", CacheListenerBase.isFqnSessionRootSized(test, false));
+
+ test = Fqn.fromRelativeElements(test, FieldBasedJBossCacheService.ATTRIBUTE);
+ assertFalse("Buddy non-session root correct", CacheListenerBase.isFqnSessionRootSized(test, true));
}
public void testIsPossibleInternalPojoFqn()
{
- Fqn test = BASE;
+ Fqn<String> test = BASE;
+ int idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertFalse("Session root correct", CacheListener.isPossibleInternalPojoFqn(test, idx));
+
+ test = FieldBasedJBossCacheService.getAttributeFqn(CONTEXT_HOST_PATH, "123");
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertFalse("ATTRIBUTE fqn correct", CacheListener.isPossibleInternalPojoFqn(test, idx));
+
+ test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertFalse("Pojo attach point correct", CacheListener.isPossibleInternalPojoFqn(test, idx));
+
+ test = Fqn.fromRelativeElements(BASE, "_JBossInternal_");
+ test = Fqn.fromRelativeElements(test, "person");
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertTrue("Internal pojo correct", CacheListener.isPossibleInternalPojoFqn(test, idx));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testIsPossibleInternalPojoFqnDeprecated()
+ {
+ Fqn<String> test = BASE;
assertFalse("Session root correct", CacheListener.isPossibleInternalPojoFqn(test));
test = FieldBasedJBossCacheService.getAttributeFqn(CONTEXT_HOST_PATH, "123");
@@ -102,7 +183,29 @@
public void testGetPojoKeyFromFqn()
{
- Fqn test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
+ Fqn<String> test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
+ int idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertEquals("Non-buddy pojo field correct", "person", CacheListener.getPojoKeyFromFqn(test, idx));
+
+ test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
+ test = Fqn.fromRelativeElements(test, "subobject");
+ idx = CacheListenerBase.getJSessionIndex(test, false);
+ assertEquals("Non-buddy pojo field correct with subobject", "person", CacheListener.getPojoKeyFromFqn(test, idx));
+
+ test = Fqn.fromRelativeElements(BUDDY_BASE, FieldBasedJBossCacheService.ATTRIBUTE);
+ test = Fqn.fromRelativeElements(test, "person");
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertEquals("Buddy pojo field correct", "person", CacheListener.getPojoKeyFromFqn(test, idx));
+
+ test = Fqn.fromRelativeElements(test, "subobject");
+ idx = CacheListenerBase.getJSessionIndex(test, true);
+ assertEquals("Buddy pojo field correct with subobject", "person", CacheListener.getPojoKeyFromFqn(test, idx));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testGetPojoKeyFromFqnDeprecated()
+ {
+ Fqn<String> test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
assertEquals("Non-buddy pojo field correct", "person", CacheListener.getPojoKeyFromFqn(test, false));
test = FieldBasedJBossCacheService.getFieldFqn(CONTEXT_HOST_PATH, "123", "person");
@@ -114,7 +217,7 @@
assertEquals("Buddy pojo field correct", "person", CacheListener.getPojoKeyFromFqn(test, true));
test = Fqn.fromRelativeElements(test, "subobject");
- assertEquals("Buddy pojo field correct with subobject", "person", CacheListener.getPojoKeyFromFqn(test, true));
-
+ assertEquals("Buddy pojo field correct with subobject", "person", CacheListener.getPojoKeyFromFqn(test, true));
}
+
}
More information about the jboss-cvs-commits
mailing list