[jboss-cvs] JBossAS SVN: r88986 - branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun May 17 10:17:58 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-05-17 10:17:57 -0400 (Sun, 17 May 2009)
New Revision: 88986
Modified:
branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
Log:
Help Mobicents create subclasses
Modified: branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-05-16 23:19:21 UTC (rev 88985)
+++ branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-05-17 14:17:57 UTC (rev 88986)
@@ -224,7 +224,7 @@
// Initing the proxy would be better in start, but we do it here so we
// can detect ClusteringNotSupportedException at this deploy stage
- initCacheProxy();
+ initDistributedCacheManager();
embedded_ = true;
}
@@ -715,6 +715,9 @@
backgroundProcessAllowed.set(false);
}
+ // Let subclasses clean up
+ stopExtensions();
+
resetStats();
// Notify our interested LifecycleListeners
@@ -1216,9 +1219,244 @@
this.replicationFieldBatchMode_ = Boolean.valueOf(replicationFieldBatchMode);
}
- // --------------------------------------------------------------- Overrides
+ // --------------------------------------------------------------- Protected
+
/**
+ * Accesses the underlying cache and creates the proxy
+ *
+ * @throws ClusteringNotSupportedException
+ */
+ protected void initDistributedCacheManager() throws ClusteringNotSupportedException
+ {
+ proxy_ = distributedCacheManagerFactory.getDistributedCacheManager(this);
+ }
+
+ /**
+ * Create and start a snapshot manager.
+ */
+ protected void initSnapshotManager()
+ {
+ String ctxPath = ((Context) container_).getPath();
+ if (SnapshotMode.INSTANT == snapshotMode_)
+ {
+ snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
+ }
+ else if (snapshotMode_ == null)
+ {
+ log_.warn("Snapshot mode must be 'instant' or 'interval' - " +
+ "using 'instant'");
+ snapshotMode_ = SnapshotMode.INSTANT;
+ snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
+ }
+ else if (ReplicationGranularity.FIELD == replicationGranularity_)
+ {
+ throw new IllegalStateException("Property snapshotMode must be " +
+ SnapshotMode.INTERVAL + " when FIELD granularity is used");
+ }
+ else if (snapshotInterval_ < 1)
+ {
+ log_.warn("Snapshot mode set to 'interval' but snapshotInterval is < 1 " +
+ "using 'instant'");
+ snapshotMode_ = SnapshotMode.INSTANT;
+ snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
+ }
+ else
+ {
+ snapshotManager_ = new IntervalSnapshotManager(this, ctxPath, snapshotInterval_);
+ }
+
+ snapshotManager_.start();
+ }
+
+ protected SnapshotManager getSnapshotManager()
+ {
+ return snapshotManager_;
+ }
+
+ protected void setSnapshotManager(SnapshotManager manager)
+ {
+ this.snapshotManager_ = manager;
+ }
+
+ /**
+ * Instantiate a SnapshotManager and ClusteredSessionValve and add
+ * the valve to our parent Context's pipeline.
+ * Add a JvmRouteValve and BatchReplicationClusteredSessionValve if needed.
+ */
+ protected void installValves()
+ {
+ log_.debug("Adding LockingValve");
+ this.installValve(new LockingValve(this.valveLock));
+
+ // If JK usage wasn't explicitly configured, default to enabling
+ // it if jvmRoute is set on our containing Engine
+ if (useJK_ == null)
+ {
+ useJK_ = Boolean.valueOf(getJvmRoute() != null);
+ }
+
+ if (getUseJK())
+ {
+ log_.debug("We are using JK for load-balancing. Adding JvmRouteValve.");
+ this.installValve(new JvmRouteValve(this));
+ }
+
+ // Handle batch replication if needed.
+ // TODO -- should we add this even if not FIELD in case a cross-context
+ // call traverses a field-based webapp?
+ BatchingManager valveBM = null;
+ if (replicationGranularity_ == ReplicationGranularity.FIELD
+ && Boolean.TRUE.equals(replicationFieldBatchMode_))
+ {
+ valveBM = this.batchingManager;
+ log_.debug("Including transaction manager in ClusteredSessionValve to support batch replication.");
+ }
+
+ // Add clustered session valve
+ ClusteredSessionValve valve = new ClusteredSessionValve(this, valveBM);
+ log_.debug("Adding ClusteredSessionValve");
+ this.installValve(valve);
+ }
+
+ protected void initClusteredSessionNotificationPolicy()
+ {
+ if (this.notificationPolicyClass_ == null || this.notificationPolicyClass_.length() == 0)
+ {
+ this.notificationPolicyClass_ = AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty("jboss.web.clustered.session.notification.policy",
+ IgnoreUndeployLegacyClusteredSessionNotificationPolicy.class.getName());
+ }
+ });
+ }
+
+ try
+ {
+ this.notificationPolicy_ = (ClusteredSessionNotificationPolicy) Thread.currentThread().getContextClassLoader().loadClass(this.notificationPolicyClass_).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate " +
+ ClusteredSessionNotificationPolicy.class.getName() +
+ " " + this.notificationPolicyClass_, e);
+ }
+
+ this.notificationPolicy_.setClusteredSessionNotificationCapability(new ClusteredSessionNotificationCapability());
+ }
+
+ /**
+ * Gets the ids of all sessions in the distributed cache and adds
+ * them to the unloaded sessions map, along with their lastAccessedTime
+ * and their maxInactiveInterval. Passivates overage or excess sessions.
+ */
+ protected void initializeUnloadedSessions()
+ {
+ Map<String, String> sessions = proxy_.getSessionIds();
+ if (sessions != null)
+ {
+ boolean passivate = isPassivationEnabled();
+
+ long passivationMax = passivationMaxIdleTime_ * 1000L;
+ long passivationMin = passivationMinIdleTime_ * 1000L;
+
+ for (Map.Entry<String, String> entry : sessions.entrySet())
+ {
+ String realId = entry.getKey();
+ String owner = entry.getValue();
+
+ long ts = -1;
+ DistributableSessionMetadata md = null;
+ try
+ {
+ IncomingDistributableSessionData sessionData = proxy_.getSessionData(realId, owner, false);
+ ts = sessionData.getTimestamp();
+ md = sessionData.getMetadata();
+ }
+ catch (Exception e)
+ {
+ // most likely a lock conflict if the session is being updated remotely;
+ // ignore it and use default values for timstamp and maxInactive
+ log_.debug("Problem reading metadata for session " + realId + " -- " + e.toString());
+ }
+
+ long lastMod = ts == -1 ? System.currentTimeMillis() : ts;
+ int maxLife = md == null ? getMaxInactiveInterval() : md.getMaxInactiveInterval();
+
+ OwnedSessionUpdate osu = new OwnedSessionUpdate(owner, lastMod, maxLife, false);
+ unloadedSessions_.put(realId, osu);
+ if (passivate)
+ {
+ try
+ {
+ long elapsed = System.currentTimeMillis() - lastMod;
+ // if maxIdle time configured, means that we need to passivate sessions that have
+ // exceeded the max allowed idle time
+ if (passivationMax >= 0
+ && elapsed > passivationMax)
+ {
+ if (trace_)
+ {
+ log_.trace("Elapsed time of " + elapsed + " for session "+
+ realId + " exceeds max of " + passivationMax + "; passivating");
+ }
+ processUnloadedSessionPassivation(realId, osu);
+ }
+ // If the session didn't exceed the passivationMaxIdleTime_, see
+ // if the number of sessions managed by this manager greater than the max allowed
+ // active sessions, passivate the session if it exceed passivationMinIdleTime_
+ else if (maxActiveAllowed_ > 0
+ && passivationMin >= 0
+ && calcActiveSessions() > maxActiveAllowed_
+ && elapsed >= passivationMin)
+ {
+ if (trace_)
+ {
+ log_.trace("Elapsed time of " + elapsed + " for session "+
+ realId + " exceeds min of " + passivationMin + "; passivating");
+ }
+ processUnloadedSessionPassivation(realId, osu);
+ }
+ }
+ catch (Exception e)
+ {
+ // most likely a lock conflict if the session is being updated remotely; ignore it
+ log_.debug("Problem passivating session " + realId + " -- " + e.toString());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Hook executed during {@link #start()} processing that allows subclasses
+ * to add extra processing to the startup. This is invoked at the end of
+ * the startup process, just before external request are free to access
+ * this manager. This default implementation does nothing.
+ */
+ protected void startExtensions()
+ {
+ // no-op
+ }
+
+ /**
+ * Hook executed during {@link #stop()} processing that allows subclasses
+ * to add extra processing to the shutdown. This is invoked at the beginning
+ * of the shutdown process, just after external requests to this manager are
+ * cut off. This default implementation does nothing.
+ */
+ protected void stopExtensions()
+ {
+ // no-op
+ }
+
+ /**
* {@inheritDoc}
* <p>
* Overrides the superclass version to ensure that the generated id
@@ -1855,7 +2093,7 @@
if (proxy_ == null)
{
- initCacheProxy();
+ initDistributedCacheManager();
}
// We need to pass the classloader that is associated with this
@@ -1888,6 +2126,9 @@
// Notify our interested LifecycleListeners
lifecycle_.fireLifecycleEvent(AFTER_START_EVENT, this);
+ // Let subclasses do what they want
+ startExtensions();
+
log_.debug("start(): JBossCacheService started");
}
catch (Exception e)
@@ -1898,16 +2139,6 @@
registerManagerMBean();
}
-
- /**
- * Accesses the underlying cache and creates the proxy
- *
- * @throws ClusteringNotSupportedException
- */
- private void initCacheProxy() throws ClusteringNotSupportedException
- {
- proxy_ = distributedCacheManagerFactory.getDistributedCacheManager(this);
- }
private void synthesizeReplicationConfig()
{
@@ -1922,199 +2153,7 @@
cfg.setSessionNotificationPolicy(notificationPolicyClass_);
this.replicationConfig_ = cfg;
}
-
- private void initClusteredSessionNotificationPolicy()
- {
- if (this.notificationPolicyClass_ == null || this.notificationPolicyClass_.length() == 0)
- {
- this.notificationPolicyClass_ = AccessController.doPrivileged(new PrivilegedAction<String>()
- {
- public String run()
- {
- return System.getProperty("jboss.web.clustered.session.notification.policy",
- IgnoreUndeployLegacyClusteredSessionNotificationPolicy.class.getName());
- }
- });
- }
-
- try
- {
- this.notificationPolicy_ = (ClusteredSessionNotificationPolicy) Thread.currentThread().getContextClassLoader().loadClass(this.notificationPolicyClass_).newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate " +
- ClusteredSessionNotificationPolicy.class.getName() +
- " " + this.notificationPolicyClass_, e);
- }
-
- this.notificationPolicy_.setClusteredSessionNotificationCapability(new ClusteredSessionNotificationCapability());
- }
- /**
- * Gets the ids of all sessions in the distributed cache and adds
- * them to the unloaded sessions map, along with their lastAccessedTime
- * and their maxInactiveInterval. Passivates overage or excess sessions.
- */
- private void initializeUnloadedSessions()
- {
- Map<String, String> sessions = proxy_.getSessionIds();
- if (sessions != null)
- {
- boolean passivate = isPassivationEnabled();
-
- long passivationMax = passivationMaxIdleTime_ * 1000L;
- long passivationMin = passivationMinIdleTime_ * 1000L;
-
- for (Map.Entry<String, String> entry : sessions.entrySet())
- {
- String realId = entry.getKey();
- String owner = entry.getValue();
-
- long ts = -1;
- DistributableSessionMetadata md = null;
- try
- {
- IncomingDistributableSessionData sessionData = proxy_.getSessionData(realId, owner, false);
- ts = sessionData.getTimestamp();
- md = sessionData.getMetadata();
- }
- catch (Exception e)
- {
- // most likely a lock conflict if the session is being updated remotely;
- // ignore it and use default values for timstamp and maxInactive
- log_.debug("Problem reading metadata for session " + realId + " -- " + e.toString());
- }
-
- long lastMod = ts == -1 ? System.currentTimeMillis() : ts;
- int maxLife = md == null ? getMaxInactiveInterval() : md.getMaxInactiveInterval();
-
- OwnedSessionUpdate osu = new OwnedSessionUpdate(owner, lastMod, maxLife, false);
- unloadedSessions_.put(realId, osu);
- if (passivate)
- {
- try
- {
- long elapsed = System.currentTimeMillis() - lastMod;
- // if maxIdle time configured, means that we need to passivate sessions that have
- // exceeded the max allowed idle time
- if (passivationMax >= 0
- && elapsed > passivationMax)
- {
- if (trace_)
- {
- log_.trace("Elapsed time of " + elapsed + " for session "+
- realId + " exceeds max of " + passivationMax + "; passivating");
- }
- processUnloadedSessionPassivation(realId, osu);
- }
- // If the session didn't exceed the passivationMaxIdleTime_, see
- // if the number of sessions managed by this manager greater than the max allowed
- // active sessions, passivate the session if it exceed passivationMinIdleTime_
- else if (maxActiveAllowed_ > 0
- && passivationMin >= 0
- && calcActiveSessions() > maxActiveAllowed_
- && elapsed >= passivationMin)
- {
- if (trace_)
- {
- log_.trace("Elapsed time of " + elapsed + " for session "+
- realId + " exceeds min of " + passivationMin + "; passivating");
- }
- processUnloadedSessionPassivation(realId, osu);
- }
- }
- catch (Exception e)
- {
- // most likely a lock conflict if the session is being updated remotely; ignore it
- log_.debug("Problem passivating session " + realId + " -- " + e.toString());
- }
- }
- }
- }
- }
-
- /**
- * Instantiate a SnapshotManager and ClusteredSessionValve and add
- * the valve to our parent Context's pipeline.
- * Add a JvmRouteValve and BatchReplicationClusteredSessionValve if needed.
- */
- private void installValves()
- {
- log_.debug("Adding LockingValve");
- this.installValve(new LockingValve(this.valveLock));
-
- // If JK usage wasn't explicitly configured, default to enabling
- // it if jvmRoute is set on our containing Engine
- if (useJK_ == null)
- {
- useJK_ = Boolean.valueOf(getJvmRoute() != null);
- }
-
- if (getUseJK())
- {
- log_.debug("We are using JK for load-balancing. Adding JvmRouteValve.");
- this.installValve(new JvmRouteValve(this));
- }
-
- // Handle batch replication if needed.
- // TODO -- should we add this even if not FIELD in case a cross-context
- // call traverses a field-based webapp?
- BatchingManager valveBM = null;
- if (replicationGranularity_ == ReplicationGranularity.FIELD
- && Boolean.TRUE.equals(replicationFieldBatchMode_))
- {
- valveBM = this.batchingManager;
- log_.debug("Including transaction manager in ClusteredSessionValve to support batch replication.");
- }
-
- // Add clustered session valve
- ClusteredSessionValve valve = new ClusteredSessionValve(this, valveBM);
- log_.debug("Adding ClusteredSessionValve");
- this.installValve(valve);
- }
-
- /**
- * Create and start a snapshot manager.
- */
- private void initSnapshotManager()
- {
- String ctxPath = ((Context) container_).getPath();
- if (SnapshotMode.INSTANT == snapshotMode_)
- {
- snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
- }
- else if (snapshotMode_ == null)
- {
- log_.warn("Snapshot mode must be 'instant' or 'interval' - " +
- "using 'instant'");
- snapshotMode_ = SnapshotMode.INSTANT;
- snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
- }
- else if (ReplicationGranularity.FIELD == replicationGranularity_)
- {
- throw new IllegalStateException("Property snapshotMode must be " +
- SnapshotMode.INTERVAL + " when FIELD granularity is used");
- }
- else if (snapshotInterval_ < 1)
- {
- log_.warn("Snapshot mode set to 'interval' but snapshotInterval is < 1 " +
- "using 'instant'");
- snapshotMode_ = SnapshotMode.INSTANT;
- snapshotManager_ = new InstantSnapshotManager(this, ctxPath);
- }
- else
- {
- snapshotManager_ = new IntervalSnapshotManager(this, ctxPath, snapshotInterval_);
- }
-
- snapshotManager_.start();
- }
-
private void installValve(Valve valve)
{
boolean installed = false;
@@ -2278,7 +2317,7 @@
{
if (proxy_ == null)
{
- initCacheProxy();
+ initDistributedCacheManager();
}
proxy_.start();
@@ -2296,6 +2335,9 @@
// Add SnapshotValve and, if needed, JvmRouteValve and batch repl valve
installValves();
+
+ // Let subclasses do what they want
+ startExtensions();
log_.debug("start(): JBossCacheService started");
}
More information about the jboss-cvs-commits
mailing list