Revision: 15436
Author: vladimir.ralev
Date: Mon Nov 22 06:08:04 2010
Log: Update Issue 2093
Fixing the issue in trunk for AS4
http://code.google.com/p/mobicents/source/detail?r=15436
Modified:
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
Fri Nov 19 08:48:05 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
Mon Nov 22 06:08:04 2010
@@ -116,6 +116,8 @@
import org.mobicents.servlet.sip.startup.SipContext;
import org.mobicents.servlet.sip.startup.StaticServiceHolder;
+import com.sun.tools.javac.comp.Enter;
+
/**
* Implementation of the SipApplicationDispatcher interface.
* Central point getting the sip messages from the different stacks for a
Tomcat Service(Engine),
@@ -917,6 +919,7 @@
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()))) {
@@ -942,6 +945,7 @@
sipSessionImpl.onTerminatedState();
}
} finally {
+
sipContext.exitSipAppHa(null, null);
sipContext.exitSipApp(sipApplicationSession, sipSessionImpl);
}
} else {
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java
Thu Nov 18 06:05:14 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipApplicationSessionImpl.java
Mon Nov 22 06:08:04 2010
@@ -213,6 +213,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);
@@ -651,6 +654,15 @@
// }
facade = null;
}
+
+ public void cancelAllTimers() {
+ cancelExpirationTimer();
+ if(this.servletTimers != null) {
+ for(ServletTimer timer:this.servletTimers.values()) {
+ timer.cancel();
+ }
+ }
+ }
private void cancelExpirationTimer() {
sipContext.getSipApplicationSessionTimerService().cancel(expirationTimerTask);
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
Mon Nov 8 12:25:26 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
Mon Nov 22 06:08:04 2010
@@ -965,7 +965,7 @@
/**
* @param isValid the isValid to set
*/
- protected void setValid(boolean isValid) {
+ public void setValid(boolean isValid) {
this.isValidInternal.set(isValid);
}
/*
@@ -1644,7 +1644,7 @@
/**
* @param readyToInvalidate the readyToInvalidate to set
*/
- protected void setReadyToInvalidate(boolean readyToInvalidate) {
+ public void setReadyToInvalidate(boolean readyToInvalidate) {
if(logger.isDebugEnabled()) {
logger.debug("readyToInvalidate flag is set to " +
readyToInvalidate);
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java
Thu Aug 5 07:17:57 2010
+++
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java
Mon Nov 22 06:08:04 2010
@@ -1394,14 +1394,14 @@
}
@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);
@@ -1419,4 +1419,12 @@
public String getHaId() {
return haId;
}
-}
+
+ public void setReadyToInvalidateInternal(boolean readyToInvalidate) {
+ super.setReadyToInvalidate(readyToInvalidate);
+ }
+
+ public void setValidInternal(boolean isValid) {
+ super.setValid(isValid);
+ }
+}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java
Fri Jul 30 08:54:53 2010
+++
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/ConvergedSessionReplicationContext.java
Mon Nov 22 06:08:04 2010
@@ -23,12 +23,18 @@
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import javax.servlet.sip.SipApplicationSession;
+import javax.servlet.sip.SipSession;
+import javax.servlet.sip.SipApplicationSession.Protocol;
+
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;
@@ -58,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;
@@ -138,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();
@@ -247,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--;
@@ -261,7 +275,7 @@
// if (ctx.sipActivityCount < 1)
// sipReplicationContext.set(null);
-
+ trulyExpiredSessions.set(null);
return ctx;
}
}
@@ -318,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);
@@ -331,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);
@@ -648,6 +702,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;
@@ -667,6 +724,9 @@
}
expiredSessions.put(manager, session.getRealId());
}
+ if(logger.isDebugEnabled()) {
+ logger.debug("addExpiredSession " + session + " mgr=" + manager
+ "store=" + store);
+ }
}
private void addExpiredSipSession(ClusteredSipSession session,
SnapshotManager manager)
@@ -748,5 +808,8 @@
return result;
}
+ public String toString() {
+ return super.toString() + "[sipActivityCount" + sipActivityCount + ",
sipAppCount=" + this.sipappCount + "]";
+ }
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java
Fri Jul 16 08:23:29 2010
+++
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheClusteredSipApplicationSession.java
Mon Nov 22 06:08:04 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);
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java
Wed Aug 11 02:43:49 2010
+++
/trunk/servers/sip-servlets/sip-servlets-tomcat-jboss4/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java
Mon Nov 22 06:08:04 2010
@@ -2056,7 +2056,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);
}
@@ -2105,7 +2107,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);
}
@@ -2912,11 +2918,20 @@
if(!localOnly) {
boolean isSipSessionBoundAndExpired =
ConvergedSessionReplicationContext
- .isSipSessionBoundAndExpired(key.toString(),
snapshotManager_);
+ .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
- + " bound and expired ? " +
isSipSessionBoundAndExpired);
- }
+ + " 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