Revision: 17139
Author: vladimir.ralev
Date: Thu Mar  3 12:11:05 2011
Log: Update Issue 2397

Backport the whole issue to hot fix branch
http://code.google.com/p/mobicents/source/detail?r=17139

Modified:
/branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipProtocolHandler.java /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipStandardService.java /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-tomcat-jboss4/src /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java

=======================================
--- /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Wed Feb 23 17:10:51 2011 +++ /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Thu Mar 3 12:11:05 2011
@@ -937,12 +937,13 @@
SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
                                                                //the context 
can be null if the server is being shutdown
                                                                if(sipContext 
!= null) {
+ MobicentsSipApplicationSession sipApplicationSession = sipSession.getSipApplicationSession();
                                                                        try {
- sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                               
sipContext.enterSipApp(sipApplicationSession, sipSession);
                                                                                
checkForAckNotReceived(sipServletMessage);
                                                                                
checkForPrackNotReceived(sipServletMessage);
                                                                        } 
finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                               
sipContext.exitSipApp(sipApplicationSession, sipSession);
                                                                        }
                                                                        
dialog.delete();
                                                                        
tryToInvalidateSession(sipSessionKey, false);
@@ -990,8 +991,9 @@
SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
                                                        //the context can be 
null if the server is being shutdown
                                                        if(sipContext != null) {
+ MobicentsSipApplicationSession sipApplicationSession = sipSession.getSipApplicationSession();
                                                                try {
- sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                       
sipContext.enterSipApp(sipApplicationSession, sipSession);
// naoki : Fix for Issue 1618 http://code.google.com/p/mobicents/issues/detail?id=1618 on Timeout don't do the 408 processing for Server Transactions if(sipServletMessage instanceof SipServletRequestImpl && !timeoutEvent.isServerTransaction()) {
                                                                                
try {
@@ -1025,7 +1027,7 @@
appNotifiedOfPrackNotReceived = checkForPrackNotReceived(sipServletMessage);
                                                                } finally {
                                                                        
sipSession.removeOngoingTransaction(transaction);
- sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                       
sipContext.exitSipApp(sipApplicationSession, sipSession);
                                                                }
// don't invalidate here because if the application sends a final response on the noPrack received // the ACK to this final response won't be able to get routed since the sip session would have been invalidated
@@ -1178,8 +1180,9 @@
SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
                                                                //the context 
can be null if the server is being shutdown
                                                                if(sipContext 
!= null) {
+ MobicentsSipApplicationSession sipApplicationSession = sipSession.getSipApplicationSession();
                                                                        try {
- sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                               
sipContext.enterSipApp(sipApplicationSession, sipSession);
if(b2buaHelperImpl != null && tad.getSipServletMessage() instanceof SipServletRequestImpl) { b2buaHelperImpl.unlinkOriginalRequestInternal((SipServletRequestImpl)tad.getSipServletMessage());
                                                                                
}
@@ -1194,7 +1197,7 @@
                                                                                
        transaction.setApplicationData(null);
                                                                                
}
                                                                        } 
finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                                               
sipContext.exitSipApp(sipApplicationSession, sipSession);
                                                                        }
                                                                }
                                                        } else {
=======================================
--- /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipProtocolHandler.java Fri Sep 3 11:41:28 2010 +++ /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipProtocolHandler.java Thu Mar 3 12:11:05 2011
@@ -516,7 +516,7 @@
                        setStarted(true);
                } catch (Exception ex) {
                        logger.error(
-                                       "Bad shit happened -- check server.xml for 
tomcat. ", ex);
+                                       "Problem with bootstrap -- check server.xml 
for tomcat. ", ex);
                } finally {
                        if(!isStarted()) {
                                destroy();
=======================================
--- /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipStandardService.java Thu Jul 22 06:24:18 2010 +++ /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/startup/SipStandardService.java Thu Mar 3 12:11:05 2011
@@ -83,7 +83,7 @@
        private int t4Interval = 5000;
        private int timerDInterval = 32000;

-       protected int dispatcherThreadPoolSize = 4;
+       protected int dispatcherThreadPoolSize = 15;

protected String concurrencyControlMode = ConcurrencyControlMode.None.toString(); protected String congestionControlPolicy = CongestionControlPolicy.ErrorResponse.toString();
=======================================
--- /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java Mon Jan 31 01:20:29 2011 +++ /branches/jbcp/1.2-CP09-HF01-2314.2263.1837.2088.1618/sip-servlets-release/sip-servlets-tomcat-jboss4/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java Thu Mar 3 12:11:05 2011
@@ -28,6 +28,7 @@
 import java.util.Stack;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;

 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -1112,6 +1113,51 @@
                }
                return ok;
        }
+
+ private void acquire(Semaphore semaphore, MobicentsSipSession sipSession, MobicentsSipApplicationSession sipApplicationSession) {
+               try {
+                       while(!semaphore.tryAcquire(30000, 
TimeUnit.MILLISECONDS)){
+                               logger.warn("Failed to acquire session semaphore 
" +
+                                               semaphore + " for 30 secs. We will 
unlock the " +
+                                               "semaphore no matter what because 
the " +
+                                               "transaction is about to timeout. 
THIS " +
+                                               "MIGHT ALSO BE CONCURRENCY CONTROL 
RISK." +
+                                               " SipSession is " + sipSession +
+                                               " app Session is" + 
sipApplicationSession);
+                               semaphore.release();
+                       }
+               } catch (InterruptedException e) {
+                       logger.error("Problem acquiring semaphore", e);
+               }
+       }
+
+ private void release(Semaphore semaphore, MobicentsSipSession sipSession, MobicentsSipApplicationSession sipApplicationSession) { + //equalize the semaphore permits to the expected number for binary semaphore
+               if(semaphore.availablePermits()>0) {
+ logger.warn("About to release semaphore but we expected permits = 0. We will adjust to normal " + + semaphore + " app session=" + sipApplicationSession + " sipSession=" +
+                                       sipApplicationSession);
+                       while(semaphore.availablePermits()>0) {
+                               try {
+                                       semaphore.acquire();
+                               } catch (Exception e) {
+                               }
+                       }
+               }
+               if(semaphore.availablePermits()<0) {
+ logger.warn("About to release semaphore but we expected permits = 0. We will adjust to normal " + + semaphore + " app session=" + sipApplicationSession + " sipSession=" +
+                                       sipApplicationSession);
+                       while(semaphore.availablePermits()<0) {
+                               try {
+                                       semaphore.release();
+                               } catch (Exception e) {
+                               }
+                       }
+               }
+
+               semaphore.release();
+       }

public void enterSipApp(MobicentsSipApplicationSession sipApplicationSession, MobicentsSipSession sipSession) {
                switch (concurrencyControlMode) {
@@ -1123,7 +1169,7 @@
logger.debug("SipSession: Before semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                        " sipSession=" + 
sipSession + " semaphore=" + semaphore);
                                                }
-                                               
semaphore.acquireUninterruptibly();
+                                               acquire(semaphore, sipSession, 
sipApplicationSession);
                                                if(logger.isDebugEnabled()) {
logger.debug("SipSession: After semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                        " sipSession=" + 
sipSession + " semaphore=" + semaphore);
@@ -1145,7 +1191,7 @@
logger.debug("Child SipSession: Before semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                                " 
sipSession=" + sipSession + " semaphore=" + semaphore);
                                                        }
-                                                       
semaphore.acquireUninterruptibly();
+                                                       acquire(semaphore, 
sipSession, sipApplicationSession);
                                                        
if(logger.isDebugEnabled()) {
logger.debug("Child SipSession: After semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                                " 
sipSession=" + sipSession + " semaphore=" + semaphore);
@@ -1162,7 +1208,7 @@
logger.debug("SipAppSession: Before semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                        " sipSession=" + 
sipSession + " semaphore=" + semaphore);
                                                }
-                                               
semaphore.acquireUninterruptibly();
+                                               acquire(semaphore, sipSession, 
sipApplicationSession);
                                                if(logger.isDebugEnabled()) {
logger.debug("SipAppSession: After semaphore acquire for sipApplicationSession=" + sipApplicationSession +
                                                                        " sipSession=" + 
sipSession + " semaphore=" + semaphore);
@@ -1181,7 +1227,7 @@
                                if(sipSession != null) {
                                        final Semaphore semaphore = 
sipSession.getSemaphore();
                                        if(semaphore != null) {
-                                               semaphore.release();
+                                               release(semaphore, sipSession, 
sipApplicationSession);
                                                if(logger.isDebugEnabled()) {
logger.debug("SipSession: Semaphore released for sipApplicationSession=" + sipApplicationSession +
                                                                        " sipSession=" + 
sipSession + " semaphore=" + semaphore);
@@ -1195,7 +1241,7 @@
                                                                .next();
                                                final Semaphore semaphore = 
childSipSession.getSemaphore();
                                                if(semaphore != null) {
-                                                       semaphore.release();
+                                                       release(semaphore, 
sipSession, sipApplicationSession);
                                                        
if(logger.isDebugEnabled()) {
logger.debug("Child SipSession: Semaphore released for sipApplicationSession=" + sipApplicationSession +
                                                                                " 
sipSession=" + sipSession + " semaphore=" + semaphore);
@@ -1206,10 +1252,11 @@
                                break;
                        case SipApplicationSession:
if(sipApplicationSession != null && sipApplicationSession.getSemaphore() != null) {
-                                       
sipApplicationSession.getSemaphore().release();
+                                       Semaphore semaphore = 
sipApplicationSession.getSemaphore();
+                                       release(semaphore, sipSession, 
sipApplicationSession);
                                        if(logger.isDebugEnabled()) {
logger.debug("SipAppSession: Semaphore released for sipApplicationSession=" + sipApplicationSession + - " sipSession=" + sipSession + " semaphore=" + sipApplicationSession.getSemaphore());
+                                                               " sipSession=" + 
sipSession + " semaphore=" + semaphore);
                                        }
                                } else {
                                        if(logger.isDebugEnabled()) {

Reply via email to