Revision: 15350
Author: [email protected]
Date: Wed Nov 17 10:33:31 2010
Log: Fixes Issue 1873
http://code.google.com/p/mobicents/source/detail?r=15350

Modified:
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManager.java /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManagerDelegate.java /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java

=======================================
--- /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManager.java Wed Jun 16 14:12:53 2010 +++ /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManager.java Wed Nov 17 10:33:31 2010
@@ -30,6 +30,8 @@
import org.jboss.web.tomcat.service.session.notification.ClusteredSipSessionNotificationPolicy;
 import org.mobicents.cluster.MobicentsCluster;
 import org.mobicents.servlet.sip.core.session.DistributableSipManager;
+import org.mobicents.servlet.sip.core.session.SipApplicationSessionKey;
+import org.mobicents.servlet.sip.core.session.SipSessionKey;

 /**
  * @author [email protected]
@@ -77,4 +79,7 @@
public DistributedCacheConvergedSipManager getDistributedCacheConvergedSipManager();

        MobicentsCluster getMobicentsCluster();
-}
+
+       void checkSipApplicationSessionPassivation(SipApplicationSessionKey 
key);
+       void checkSipSessionPassivation(SipSessionKey key);
+}
=======================================
--- /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManagerDelegate.java Wed Nov 17 05:14:51 2010 +++ /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipManagerDelegate.java Wed Nov 17 10:33:31 2010
@@ -66,6 +66,8 @@
SipApplicationSessionKey key, SipContext sipContext, boolean scheduleTimer) { ClusteredSipApplicationSession<? extends OutgoingDistributableSessionData> session = null;

+               clusteredSipManager.checkSipApplicationSessionPassivation(key);
+
                if 
(replicationGranularity.equals(ReplicationGranularity.ATTRIBUTE)) {
session = new AttributeBasedClusteredSipApplicationSession(key,sipContext, useJK);
                } else if 
(replicationGranularity.equals(ReplicationGranularity.FIELD)) {
@@ -89,6 +91,9 @@
                        SipFactoryImpl sipFactoryImpl,
                        MobicentsSipApplicationSession 
mobicentsSipApplicationSession) {
ClusteredSipSession<? extends OutgoingDistributableSessionData> session = null;
+
+               clusteredSipManager.checkSipSessionPassivation(key);
+
                if 
(replicationGranularity.equals(ReplicationGranularity.ATTRIBUTE)) {
session = new AttributeBasedClusteredSipSession(key, sipFactoryImpl, mobicentsSipApplicationSession, useJK);
                } else if 
(replicationGranularity.equals(ReplicationGranularity.FIELD)) {
=======================================
--- /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java Wed Nov 17 08:12:10 2010 +++ /trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java Wed Nov 17 10:33:31 2010
@@ -141,6 +141,10 @@
private final ConcurrentMap<String, ClusteredSession<? extends OutgoingDistributableSessionData>> embryonicSessions = new ConcurrentHashMap<String, ClusteredSession<? extends OutgoingDistributableSessionData>>();

+ /** number of sessions rejected because the number active sip sessions exceeds maxActive */
+       protected AtomicInteger rejectedSipSessionCounter_ = new 
AtomicInteger();
+ /** number of sessions rejected because the number active sip application sessions exceeds maxActive */ + protected AtomicInteger rejectedSipApplicationSessionCounter_ = new AtomicInteger();
        /** Number of passivated sip sessions */
        private AtomicInteger passivatedSipSessionCount_ = new AtomicInteger();
        /** Maximum number of concurrently passivated sip sessions */
@@ -470,7 +474,7 @@
                        " and max allowed sessions = " + maxActiveAllowed_);
          }

-         processExpirationPassivation();
+         processHttpSessionExpirationPassivation();

          if (calcActiveSessions() >= maxActiveAllowed_)
          {
@@ -1037,12 +1041,14 @@

    protected int getTotalActiveSipApplicationSessions()
    {
- return localActiveSipApplicationSessionCounter_.get() + unloadedSipApplicationSessions_.size() - passivatedSipApplicationSessionCount_.get(); +// return localActiveSipApplicationSessionCounter_.get() + unloadedSipApplicationSessions_.size() - passivatedSipApplicationSessionCount_.get(); + return localActiveSipApplicationSessionCounter_.get() + unloadedSipApplicationSessions_.size();
    }

    protected int getTotalActiveSipSessions()
    {
- return localActiveSipSessionCounter_.get() + unloadedSipSessions_.size() - passivatedSipSessionCount_.get(); +// return localActiveSipSessionCounter_.get() + unloadedSipSessions_.size() - passivatedSipSessionCount_.get(); + return localActiveSipSessionCounter_.get() + unloadedSipSessions_.size();
    }

    @Override
@@ -1499,13 +1505,13 @@
       long passivationMax = passivationMaxIdleTime_ * 1000L;
       long passivationMin = passivationMinIdleTime_ * 1000L;

-      if (trace_)
-      {
+      if (trace_) {
log_.trace("processSipSessionExpirationPassivation(): Looking for sip sessions that have expired ..."); + log_.trace("processSipSessionExpirationPassivation(): passivation Max = " + passivationMax); + log_.trace("processSipSessionExpirationPassivation(): passivation Min = " + passivationMin); log_.trace("processSipSessionExpirationPassivation(): active sip sessions = " + calcActiveSipSessions()); log_.trace("processSipSessionExpirationPassivation(): expired sip sessions = " + expiredSipSessionCounter_);
-         if (passivate)
-         {
+         if (passivate) {
log_.trace("processSipSessionExpirationPassivation(): passivated count = " + getPassivatedSipSessionCount());
          }
       }
@@ -1590,6 +1596,7 @@
                {
                   long timeNow = System.currentTimeMillis();
long timeIdle = timeNow - passivationCheck.getLastUpdate(); + log_.debug("Time now " + timeNow + ", Time Idle " + timeIdle); // if maxIdle time configured, means that we need to passivate sessions that have
                   // exceeded the max allowed idle time
                   if (passivationMax >= 0
@@ -1632,13 +1639,11 @@
          ConvergedSessionInvalidationTracker.resume();
       }

-      if (trace_)
-      {
+      if (trace_) {
log_.trace("processSipSessionExpirationPassivation(): Completed ..."); log_.trace("processSipSessionExpirationPassivation(): active sip sessions = " + calcActiveSipSessions()); log_.trace("processSipSessionExpirationPassivation(): expired sip sessions = " + expiredSipSessionCounter_);
-         if (passivate)
-         {
+         if (passivate) {
log_.trace("processSipSessionExpirationPassivation(): passivated count = " + getPassivatedSipSessionCount());
          }
       }
@@ -4774,4 +4779,52 @@
                boolean isSessionOutdated(
ClusteredSipApplicationSession<? extends OutgoingDistributableSessionData> session);
        }
-}
+
+ public void checkSipApplicationSessionPassivation(SipApplicationSessionKey key) {
+               if (maxActiveAllowed_ > 0
+                               && calcActiveSipApplicationSessions() >= 
maxActiveAllowed_) {
+                       if (trace_) {
+ log_.trace("checkSipApplicationSessionPassivation(): active sip application sessions = "
+                                               + calcActiveSipApplicationSessions() + 
" and max allowed sessions = "
+                                               + maxActiveAllowed_);
+                       }
+
+                       processSipApplicationSessionExpirationPassivation();
+
+                       if (calcActiveSipApplicationSessions() >= 
maxActiveAllowed_) {
+                               // Exceeds limit. We need to reject it.
+                               
rejectedSipApplicationSessionCounter_.incrementAndGet();
+                               // Catalina api does not specify what happens
+                               // but we will throw a runtime exception for 
now.
+// throw new IllegalStateException("checkSipApplicationSessionPassivation(): number of "
+//                                             + "active sip application sessions 
exceeds the maximum limit: "
+// + maxActiveAllowed_ + " when trying to create sip application session "
+//                                             + key);
+                       }
+               }
+       }
+
+       public void checkSipSessionPassivation(SipSessionKey key) {
+               if (maxActiveAllowed_ > 0
+                               && calcActiveSipSessions() >= 
maxActiveAllowed_) {
+                       if (trace_) {
+                               log_.trace("checkSipSessionPassivation(): active sip 
sessions = "
+                                               + calcActiveSipSessions() + " and 
max allowed sessions = "
+                                               + maxActiveAllowed_);
+                       }
+
+                       processSipSessionExpirationPassivation();
+
+                       if (calcActiveSipSessions() >= maxActiveAllowed_) {
+                               // Exceeds limit. We need to reject it.
+                               rejectedSipSessionCounter_.incrementAndGet();
+                               // Catalina api does not specify what happens
+                               // but we will throw a runtime exception for 
now.
+// throw new IllegalStateException("checkSipSessionPassivation(): number of "
+//                                             + "active sip sessions exceeds the 
maximum limit: "
+//                                             + maxActiveAllowed_ + " when trying 
to create sip session "
+//                                             + key);
+                       }
+               }
+       }
+}

Reply via email to