[jboss-cvs] JBossAS SVN: r60308 - branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 5 16:05:09 EST 2007
Author: bstansberry at jboss.com
Date: 2007-02-05 16:05:09 -0500 (Mon, 05 Feb 2007)
New Revision: 60308
Added:
branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/AbstractCacheListener.java
Modified:
branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java
Log:
[JBAS-4067] Detect collection modifications in FIELD pojos
Reduce calls to log.isTraceEnabled()
Added: branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/AbstractCacheListener.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/AbstractCacheListener.java (rev 0)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/AbstractCacheListener.java 2007-02-05 21:05:09 UTC (rev 60308)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.session;
+
+import org.jboss.cache.AbstractTreeCacheListener;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+import org.jgroups.View;
+
+/**
+ * Overrides the standard JBoss Cache version to eliminate the overhead
+ * of trace logging checks. Each method is implemented as a complete no-op.
+ *
+ * @author Brian Stansberry
+ */
+public abstract class AbstractCacheListener extends AbstractTreeCacheListener
+{
+ @Override
+ public void nodeCreated(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void nodeRemoved(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void nodeLoaded(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void nodeEvicted(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void nodeModify(Fqn fqn, boolean pre, boolean isLocal)
+ {
+ }
+
+ @Override
+ public void nodeModified(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void nodeVisited(Fqn fqn)
+ {
+ }
+
+ @Override
+ public void cacheStarted(TreeCache cache)
+ {
+ }
+
+ @Override
+ public void cacheStopped(TreeCache cache)
+ {
+ }
+
+ @Override
+ public void viewChange(View new_view)
+ {
+ }
+
+ @Override
+ public void nodeEvict(Fqn fqn, boolean pre)
+ {
+
+ }
+
+ @Override
+ public void nodeRemove(Fqn fqn, boolean pre, boolean isLocal)
+ {
+ }
+
+ @Override
+ public void nodeActivate(Fqn fqn, boolean pre)
+ {
+ }
+
+ @Override
+ public void nodePassivate(Fqn fqn, boolean pre)
+ {
+ }
+}
Modified: branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java 2007-02-05 21:04:22 UTC (rev 60307)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java 2007-02-05 21:05:09 UTC (rev 60308)
@@ -21,14 +21,20 @@
*/
package org.jboss.web.tomcat.service.session;
-import org.jboss.cache.AbstractTreeCacheListener;
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.logging.Logger;
import org.jboss.metadata.WebMetaData;
-
-public class CacheListener extends AbstractTreeCacheListener
+/**
+ * Listens for distributed caches events, notifying the JBossCacheManager
+ * of events of interest.
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision: 57206 $
+ */
+public class CacheListener extends AbstractCacheListener
{
// Element within an FQN that is JSESSION
private static final int JSESSION_FQN_INDEX = 0;
@@ -72,66 +78,83 @@
int granularity = manager_.getReplicationGranularity();
fieldBased_ = (granularity == WebMetaData.REPLICATION_GRANULARITY_FIELD);
// TODO decide if disdaining local activity is always good for REPL_ASYNC
- disdainLocalActivity_ = (granularity == WebMetaData.REPLICATION_GRANULARITY_SESSION);; // for now
+ disdainLocalActivity_ = (granularity == WebMetaData.REPLICATION_GRANULARITY_SESSION); // for now
}
// --------------- TreeCacheListener methods ------------------------------------
public void nodeRemoved(Fqn fqn)
{
- // Ignore our own activity
- if (SessionReplicationContext.isLocallyActive())
+ // Ignore our own activity if not field based
+ boolean local = SessionReplicationContext.isLocallyActive();
+ if (!fieldBased_ && local)
return;
boolean isBuddy = isBuddyFqn(fqn);
+ int size = fqn.size();
- // Potential removal of a Pojo where we need to unregister as an Observer.
- if (fieldBased_
- && isFqnPojoKeySized(fqn, isBuddy)
- && isFqnForOurWebapp(fqn, isBuddy))
+ if(isFqnSessionRootSized(size, isBuddy))
{
- String sessId = getIdFromFqn(fqn, isBuddy);
- String attrKey = getPojoKeyFromFqn(fqn, isBuddy);
- manager_.processRemoteAttributeRemoval(sessId, attrKey);
+ if (!local && isFqnForOurWebapp(fqn, isBuddy))
+ {
+ // A session has been invalidated from another node;
+ // need to inform manager
+ String sessId = getIdFromFqn(fqn, isBuddy);
+ manager_.processRemoteInvalidation(sessId);
+ }
}
- else if(isFqnSessionRootSized(fqn, isBuddy)
- && isFqnForOurWebapp(fqn, isBuddy)
-// && !isDataGravitationCleanup()
- )
+ else if (fieldBased_ && isFqnForOurWebapp(fqn, isBuddy))
{
- // A session has been invalidated from another node;
- // need to inform manager
- String sessId = getIdFromFqn(fqn, isBuddy);
- manager_.processRemoteInvalidation(sessId);
+ // Potential removal of a Pojo where we need to unregister as an Observer.
+ if (!local && isFqnPojoKeySized(size, isBuddy))
+ {
+ String sessId = getIdFromFqn(fqn, isBuddy);
+ String attrKey = getPojoKeyFromFqn(fqn, isBuddy);
+ manager_.processRemoteAttributeRemoval(sessId, attrKey);
+ }
+ else if (local && isFqnInPojo(size, isBuddy))
+ {
+ // One of our pojo's is modified
+ String sessId = getIdFromFqn(fqn, isBuddy);
+ manager_.processLocalPojoModification(sessId);
+ }
}
}
public void nodeModified(Fqn fqn)
{
- // If checking for local activity has a higher likelihood of
- // catching unwanted notifications than checking fqn size,
- // do it first
- if (disdainLocalActivity_)
- {
- if (SessionReplicationContext.isLocallyActive())
- return;
- }
+ boolean local = SessionReplicationContext.isLocallyActive();
+ if (!fieldBased_ && local)
+ return;
boolean isBuddy = isBuddyFqn(fqn);
- // We only care if there is a chance this is for a session root
- if (!isFqnSessionRootSized(fqn, isBuddy))
- return;
+ int size = fqn.size();
- if (!disdainLocalActivity_)
+ // We only care if this is for a session root or it's for a pojo
+ if (isFqnSessionRootSized(size, isBuddy))
{
- if (SessionReplicationContext.isLocallyActive())
- return;
+ if (!local && isFqnForOurWebapp(fqn, isBuddy))
+ {
+ handleSessionRootModification(fqn, isBuddy);
+ }
}
-
+ else if (fieldBased_
+ && local
+ && isFqnForOurWebapp(fqn, isBuddy)
+ && isFqnInPojo(size, isBuddy))
+ {
+ // One of our pojo's is modified
+ String sessId = getIdFromFqn(fqn, isBuddy);
+ manager_.processLocalPojoModification(sessId);
+ }
+ }
+
+ private void handleSessionRootModification(Fqn fqn, boolean isBuddy)
+ {
// We only care if this is for our webapp
if (!isFqnForOurWebapp(fqn, isBuddy))
return;
-
+
// Query if we have version value in the distributed cache.
// If we have a version value, compare the version and invalidate if necessary.
Integer version = (Integer)cacheWrapper_.get(fqn, JBossCacheService.VERSION_KEY);
@@ -207,16 +230,21 @@
return false;
}
- private static boolean isFqnSessionRootSized(Fqn fqn, boolean isBuddy)
+ private static boolean isFqnSessionRootSized(int size, boolean isBuddy)
{
- return fqn.size() == (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + SESSION_FQN_SIZE : SESSION_FQN_SIZE);
+ return size == (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + SESSION_FQN_SIZE : SESSION_FQN_SIZE);
}
- private static boolean isFqnPojoKeySized(Fqn fqn, boolean isBuddy)
+ private static boolean isFqnPojoKeySized(int size, boolean isBuddy)
{
- return fqn.size() == (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + POJO_KEY_FQN_SIZE : POJO_KEY_FQN_SIZE);
+ return size == (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + POJO_KEY_FQN_SIZE : POJO_KEY_FQN_SIZE);
}
+ private static boolean isFqnInPojo(int size, boolean isBuddy)
+ {
+ return size >= (isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + POJO_KEY_FQN_SIZE : POJO_KEY_FQN_SIZE);
+ }
+
private static String getIdFromFqn(Fqn fqn, boolean isBuddy)
{
return (String)fqn.get(isBuddy ? BUDDY_BACKUP_ROOT_OWNER_SIZE + SESSION_ID_FQN_INDEX : SESSION_ID_FQN_INDEX);
More information about the jboss-cvs-commits
mailing list