Revision: 15391
Author: vladimir.ralev
Date: Thu Nov 18 23:39:26 2010
Log: Update Issue 2093

Fix for JBCP 1.2 branch
http://code.google.com/p/mobicents/source/detail?r=15391

Modified:
/branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java

=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Thu Nov 18 09:26:36 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Thu Nov 18 23:39:26 2010
@@ -831,12 +831,13 @@
                                try {
                                        final ClassLoader cl = 
sipContext.getLoader().getClassLoader();
                                        
Thread.currentThread().setContextClassLoader(cl);
-
+
MobicentsSipSession sipSessionImpl = sipContext.getSipManager().getSipSession(sipSessionKey, false, sipFactoryImpl, null);
-
+
                                        MobicentsSipApplicationSession 
sipApplicationSession = null;
                                        if(sipSessionImpl != null) {
                                                
sipContext.enterSipApp(sipApplicationSession, sipSessionImpl);
+                                               sipContext.enterSipAppHa(true);
                                                try {
                                                        final ProxyImpl proxy = 
sipSessionImpl.getProxy();
if(!invalidateProxySession && (proxy == null || (proxy != null && proxy.getFinalBranchForSubsequentRequests() != null && !proxy.getFinalBranchForSubsequentRequests().getRecordRoute()))) {
@@ -859,10 +860,11 @@
                                                                }
                                                        }
                                                        sipApplicationSession = 
sipSessionImpl.getSipApplicationSession();
- if(sipSessionImpl.isValidInternal() && sipSessionImpl.isReadyToInvalidate()) { + if(sipSessionImpl.isValidInternal() && sipSessionImpl.isReadyToInvalidate()) {
                                                                
sipSessionImpl.onTerminatedState();
                                                        }
                                                } finally {
+                                                       
sipContext.exitSipAppHa(null, null);
                                                        
sipContext.exitSipApp(sipApplicationSession, sipSessionImpl);
                                                }
                                        } else {
@@ -887,11 +889,12 @@
                                                        }
if(sipApplicationSession.isValidInternal() && sipApplicationSession.isReadyToInvalidate()) {
                                                                
sipApplicationSession.tryToInvalidate();
-                                                       }
+                                                       }
                                                } finally {
+                                                       
sipContext.exitSipAppHa(null, null);
                                                        
sipContext.exitSipApp(sipApplicationSession, sipSessionImpl);
-                                               }
-                                       }
+                                               }
+                                       }

                                } finally {
                                        
Thread.currentThread().setContextClassLoader(oldClassLoader);
=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java Wed Oct 6 05:31:40 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java Thu Nov 18 23:39:26 2010
@@ -204,6 +204,9 @@
        }

public SipSessionKey removeSipSession (MobicentsSipSession mobicentsSipSession) {
+               if(logger.isDebugEnabled()) {
+                       logger.debug("Trying to remove sip session " + 
mobicentsSipSession);
+               }
                final SipSessionKey key = mobicentsSipSession.getKey();
                if(sipSessions != null) {
                        boolean wasPresent = this.sipSessions.remove(key);
@@ -645,6 +648,15 @@
        private void cancelExpirationTimer() {
sipContext.getSipApplicationSessionTimerService().cancel(expirationTimerTask);
        }
+
+       public void cancelAllTimers() {
+               cancelExpirationTimer();
+               if(this.servletTimers != null) {
+                       for(ServletTimer timer:this.servletTimers.values()) {
+                               timer.cancel();
+                       }
+               }
+       }

        /*
         * (non-Javadoc)
=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java Tue Sep 21 12:11:15 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java Thu Nov 18 23:39:26 2010
@@ -916,7 +916,7 @@
        /**
         * @param isValid the isValid to set
         */
-       protected void setValid(boolean isValid) {
+       public void setValid(boolean isValid) {
                this.isValidInternal.set(isValid);
        }
        /*
@@ -1541,7 +1541,7 @@
        /**
         * @param readyToInvalidate the readyToInvalidate to set
         */
-       protected void setReadyToInvalidate(boolean readyToInvalidate) {
+       public void setReadyToInvalidate(boolean readyToInvalidate) {
                this.readyToInvalidate = readyToInvalidate;
        }

=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java Thu Aug 5 08:05:28 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java Thu Nov 18 23:39:26 2010
@@ -1393,18 +1393,26 @@
        }

        @Override
-       protected void setReadyToInvalidate(boolean readyToInvalidate) {
+       public void setReadyToInvalidate(boolean readyToInvalidate) {
                super.setReadyToInvalidate(readyToInvalidate);
                sessionMetadataDirty();
                metaModifiedMap_.put(READY_TO_INVALIDATE, readyToInvalidate);
        }

        @Override
-       protected void setValid(boolean isValid) {
+       public void setValid(boolean isValid) {
                super.setValid(isValid);
                sessionMetadataDirty();
                metaModifiedMap_.put(IS_VALID, isValid);
        }
+
+       public void setReadyToInvalidateInternal(boolean readyToInvalidate) {
+               super.setReadyToInvalidate(readyToInvalidate);
+       }
+
+       public void setValidInternal(boolean isValid) {
+               super.setValid(isValid);
+       }

        @Override
        public void setSessionCreatingDialog(Dialog dialog) {
=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java Wed Mar 24 03:56:47 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java Thu Nov 18 23:39:26 2010
@@ -33,12 +33,15 @@

 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
+import org.apache.log4j.Logger;
 import org.mobicents.servlet.sip.core.session.SipManager;
 import org.mobicents.servlet.sip.message.SipServletRequestImpl;
 import org.mobicents.servlet.sip.message.SipServletResponseImpl;

 public final class ConvergedSessionReplicationContext
 {
+
+ private static final Logger logger = Logger.getLogger(ConvergedSessionReplicationContext.class);
    private static final ThreadLocal replicationContext = new ThreadLocal();
private static final ThreadLocal sipReplicationContext = new ThreadLocal();

@@ -61,6 +64,8 @@
    private Map expiredSipApplicationSessions;
    private Request outerRequest;
    private Response outerResponse;
+ private static final ThreadLocal<Map> trulyExpiredSessions = new ThreadLocal<Map>();
+
 //   private SipServletRequestImpl outerSipRequest;
 //   private SipServletResponseImpl outerSipResponse;

@@ -141,6 +146,9 @@
public static void enterSipapp(SipServletRequestImpl request, SipServletResponseImpl response, boolean startCacheActivity)
    {
       ConvergedSessionReplicationContext ctx = getCurrentSipContext();
+      if(logger.isDebugEnabled()) {
+         logger.debug("enterSipApp and ctx is " + ctx);
+      }
       if (ctx == null)
       {
          ctx = new ConvergedSessionReplicationContext();
@@ -250,6 +258,9 @@
    public static ConvergedSessionReplicationContext exitSipapp()
    {
       ConvergedSessionReplicationContext ctx = getCurrentSipContext();
+      if(logger.isDebugEnabled()) {
+         logger.debug("exitSipApp and ctx is " + ctx + " ");
+      }
       if (ctx != null)
       {
          ctx.sipappCount--;
@@ -264,7 +275,7 @@

 //            if (ctx.sipActivityCount < 1)
 //               sipReplicationContext.set(null);
-
+            trulyExpiredSessions.set(null);
             return ctx;
          }
       }
@@ -321,10 +332,47 @@
          ctx.addExpiredSession(session, manager);
       }
    }
+
+ static public void addTrulyExipredSession(Object session, SnapshotManager manager)
+   {
+          ConvergedSessionReplicationContext ctx = getCurrentContext();
+
+          if(logger.isDebugEnabled()) {
+ logger.debug("addTrulyExpiredSession " + session + " mgr=" + manager + "ctx=" + ctx);
+          }
+
+          if (trulyExpiredSessions.get() == null)
+          {
+                  trulyExpiredSessions.set(new HashMap());
+          }
+          ctx.trulyExpiredSessions.get().put(session, manager);
+
+   }
+
+   public static boolean isTrulyExpired(Object session) {
+          ConvergedSessionReplicationContext ctx = getCurrentContext();
+
+          if(logger.isDebugEnabled()) {
+                  logger.debug("isTrulyExpiredSession" +
+                                  "Session " + session + "ctx=" + ctx);
+          }
+          if(trulyExpiredSessions.get() != null) {
+                  logger.debug("notnull");
+                  for(Object o:trulyExpiredSessions.get().keySet().toArray()) {
+                          logger.error(o+" ");
+                  }
+                  return trulyExpiredSessions.get().get(session)!=null;
+          }
+
+          return false;
+   }

public static void sipSessionExpired(ClusteredSipSession session, String realId, SnapshotManager manager)
    {
       ConvergedSessionReplicationContext ctx = getCurrentSipContext();
+      if(logger.isDebugEnabled()) {
+         logger.debug("enterSipApp and ctx is " + ctx);
+      }
       if (ctx != null && ctx.sipappCount > 0)
       {
          ctx.addExpiredSipSession(session, manager);
@@ -334,6 +382,9 @@
public static void sipApplicationSessionExpired(ClusteredSipApplicationSession session, String realId, SnapshotManager manager)
    {
       ConvergedSessionReplicationContext ctx = getCurrentSipContext();
+      if(logger.isDebugEnabled()) {
+         logger.debug("enterSipApp and ctx is " + ctx);
+      }
       if (ctx != null && ctx.sipappCount > 0)
       {
          ctx.addExpiredSipApplicationSession(session, manager);
@@ -407,7 +458,6 @@
          }
       }
    }
-

    /**
     * Marks the current thread as actively processing the given session.
@@ -639,6 +689,9 @@
private void addExpiredSession(ClusteredSession session, SnapshotManager manager)
    {
       boolean store = manager.equals(soleManager);
+      if(logger.isDebugEnabled()) {
+ logger.debug("addExpiredSession " + session + " mgr=" + manager + "store=" + store + "cross=" + crossCtxSessions);
+      }
       if (store)
       {
          soleManager = null;
@@ -658,6 +711,9 @@
          }
          expiredSessions.put(manager, session.getRealId());
       }
+      if(logger.isDebugEnabled()) {
+ logger.debug("addExpiredSession " + session + " mgr=" + manager + "store=" + store);
+      }
    }

private void addExpiredSipSession(ClusteredSipSession session, SnapshotManager manager)
@@ -739,5 +795,8 @@
       return result;
    }

+       public String toString() {
+ return super.toString() + "[sipActivityCount" + sipActivityCount + ", sipAppCount=" + this.sipappCount + "]";
+       }

 }
=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java Thu Jul 22 07:24:40 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java Thu Nov 18 23:39:26 2010
@@ -122,7 +122,7 @@
                if(sipSessionKeys != null && sipSessionKeys.length > 0) {
                        for (SipSessionKey sipSessionKey : sipSessionKeys) {
                                
sipSessionKey.setApplicationName(proxy_.getSipApplicationName());
-                               
sipSessionKey.setApplicationName(sipAppSessionId);
+                               
sipSessionKey.setApplicationSessionId(sipAppSessionId);
                                sipSessionKey.computeToString();
                                sipSessions.add(sipSessionKey);
                        }
=======================================
--- /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java Thu Jul 22 07:57:21 2010 +++ /branches/jbcp/1.2/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java Thu Nov 18 23:39:26 2010
@@ -2057,7 +2057,9 @@
                                        .getContextClassLoader();
                        try {
                                
Thread.currentThread().setContextClassLoader(tcl_);
-                               session.expire(notify, localCall, localOnly);
+                               //session.expire(notify, localCall, localOnly);
+                               session.cancelAllTimers();
+ logger.info("SipApplicationSession invalidated by remote node " + session);
                        } finally {
                                
Thread.currentThread().setContextClassLoader(prevTcl);
                        }
@@ -2106,7 +2108,11 @@
                                        .getContextClassLoader();
                        try {
                                
Thread.currentThread().setContextClassLoader(tcl_);
-                               session.expire(notify, localCall, localOnly);
+                               session.setReadyToInvalidateInternal(true);
+                               session.setValidInternal(false);
+                               //session.expire(notify, localCall, localOnly);
+                               //session.invalidate();
+ logger.info("SipSession invalidated by remote node (forcing local invalidation without triggering events)" + session);
                        } finally {
                                
Thread.currentThread().setContextClassLoader(prevTcl);
                        }
@@ -2775,6 +2781,8 @@
                                // of the request; the removal process took 
care of that
                                
ConvergedSessionReplicationContext.sipSessionExpired(clusterSess,
                                                realId, snapshotManager_);
+                               
ConvergedSessionReplicationContext.addTrulyExipredSession(key,
+                                               snapshotManager_);

                                stats_.removeStats(realId);
                                activeCounter_--;
@@ -2890,12 +2898,23 @@
                                                + " found in the local store " 
+ session);
                        }
                }
+
+ // Vlad: This never kicks in and always need context, but better not delete it just yet
                boolean isSipSessionBoundAndExpired = 
ConvergedSessionReplicationContext
                        .isSipSessionBoundAndExpired(key.toString(), 
snapshotManager_);
                if (logger.isDebugEnabled()) {
                        logger.debug("sip session " + key
                                        + " bound and expired ? " + 
isSipSessionBoundAndExpired);
                }
+               // Vlad: ... we use this instead
+               if(!isSipSessionBoundAndExpired) {
+                       isSipSessionBoundAndExpired = 
ConvergedSessionReplicationContext
+                       .isTrulyExpired(key);
+                       if (logger.isDebugEnabled()) {
+                               logger.debug("sip session " + key
+                                               + " truly expired ? " + 
isSipSessionBoundAndExpired);
+                       }
+               }
                // If we didn't find it locally, only check the distributed 
cache
                // if we haven't previously handled this session id on this 
request.
                // If we handled it previously but it's no longer local, that 
means

Reply via email to