Revision: 22836
Author:   [email protected]
Date:     Tue Dec  4 04:05:23 2012
Log:      Update Issue 3262.
http://code.google.com/p/mobicents/source/detail?r=22836

Modified:
/branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyBranchImpl.java /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyImpl.java

=======================================
--- /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java Thu Oct 20 11:38:28 2011 +++ /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java Tue Dec 4 04:05:23 2012
@@ -1403,10 +1403,13 @@
 //             }

                if(sessionCreatingTransactionRequest != null &&
-                               sessionCreatingTransactionRequest.getTransaction()!= 
null &&
- sessionCreatingTransactionRequest.getTransaction().equals(transaction)) { + transaction.equals(sessionCreatingTransactionRequest.getTransaction())) {
                        sessionCreatingTransactionRequest.cleanUp();
                }
+
+               if (proxy != null) {
+                       proxy.removeTransaction(transaction.getBranchId());
+               }

                if(logger.isDebugEnabled()) {
logger.debug("transaction "+ transaction +" has been removed from sip session's ongoingTransactions ? " + removed );
=======================================
--- /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyBranchImpl.java Tue Jun 19 00:01:26 2012 +++ /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyBranchImpl.java Tue Dec 4 04:05:23 2012
@@ -35,6 +35,7 @@
 import java.net.InetSocketAddress;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -50,7 +51,6 @@
 import javax.servlet.sip.ar.SipApplicationRoutingDirective;
 import javax.sip.ClientTransaction;
 import javax.sip.DialogState;
-import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
 import javax.sip.SipProvider;
 import javax.sip.header.RouteHeader;
@@ -119,7 +119,7 @@
* in both directions in proxy. http://code.google.com/p/mobicents/issues/detail?id=1852
         *
         */
- public transient LinkedList<TransactionRequest> ongoingTransactions = new LinkedList<TransactionRequest>(); + public transient List<TransactionRequest> ongoingTransactions = Collections.synchronizedList(new LinkedList<TransactionRequest>());

        public static class TransactionRequest {
                public TransactionRequest(String branch, SipServletRequestImpl 
request) {
@@ -233,7 +233,7 @@
        public void onBranchTerminated() {
                if(outgoingRequest != null) {
String txid = ((ViaHeader) outgoingRequest.getMessage().getHeader(ViaHeader.NAME)).getBranch();
-                       proxy.getTransactionMap().remove(txid);
+                       proxy.removeTransaction(txid);
                }
        }

@@ -379,10 +379,7 @@
                        }
                        recordRoute = recordRouteURI;
                }
- if(!originalRequest.getMethod().equalsIgnoreCase("ACK") && !originalRequest.getMethod().equalsIgnoreCase("PRACK")) { - String branch = ((Via)originalRequest.getMessage().getHeader(Via.NAME)).getBranch(); - this.ongoingTransactions.add(new TransactionRequest(branch, originalRequest));
-               }
+               addTransaction(originalRequest);

                Request cloned = ProxyUtils.createProxiedRequest(
                                outgoingRequest,
@@ -463,10 +460,7 @@
                } catch (IOException e) {
                        throw new IllegalStateException(e);
                }
- String txid = ((ViaHeader) clonedRequest.getMessage().getHeader(ViaHeader.NAME)).getBranch();
-               if(clonedRequest.getTransactionApplicationData() != null) {
- proxy.transactionMap.put(txid, clonedRequest.getTransactionApplicationData());
-               }
+               proxy.putTransaction(clonedRequest);
        }

        /**
@@ -621,15 +615,27 @@
                        if(remove != null) {
                                boolean removed = 
this.ongoingTransactions.remove(remove);
                                if(logger.isDebugEnabled()) {
- logger.debug("Removed transaction from proxy " + branch + " success: " + removed); + logger.debug("Removed transaction " + branch + " from proxy branch? " + removed);
                                }
                        } else {
                                if(logger.isDebugEnabled()) {
- logger.debug("Removing transaction from proxy " + branch + " FAILED. It was null"); + logger.debug("Removing transaction " + branch + " from proxy branch FAILED. Not found.");
                                }
                        }
                }
        }
+
+       void addTransaction(SipServletRequestImpl request) {
+ if(!request.getMethod().equalsIgnoreCase("ACK") && !request.getMethod().equalsIgnoreCase("PRACK")) { + String branch = ((Via)request.getMessage().getHeader(Via.NAME)).getBranch(); + if(this.ongoingTransactions.add(new TransactionRequest(branch, request))) {
+                               
request.getTransactionApplicationData().setProxyBranch(this);
+                               if(logger.isDebugEnabled()) {
+                                       logger.debug("Added transaction "+branch+" 
to proxy branch.");
+                               }
+                       }
+               }
+       }

        /**
* Call this method when a subsequent request must be proxied through the branch.
@@ -637,10 +643,7 @@
         * @param request
         */
        public void proxySubsequentRequest(SipServletRequestImpl request) {
- if(!request.getMethod().equalsIgnoreCase("ACK") && !request.getMethod().equalsIgnoreCase("PRACK")) { - String branch = ((Via)request.getMessage().getHeader(Via.NAME)).getBranch();
-                       this.ongoingTransactions.add(new 
TransactionRequest(branch, request));
-               }
+               addTransaction(request);
// A re-INVITE needs special handling without goind through the dialog-stateful methods
                if(request.getMethod().equalsIgnoreCase("INVITE")) {
                        if(logger.isDebugEnabled()) {
=======================================
--- /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyImpl.java Mon Jun 18 20:39:20 2012 +++ /branches/jbcp/5.1.x/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyImpl.java Tue Dec 4 04:05:23 2012
@@ -32,19 +32,18 @@
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;

-import javax.servlet.ServletException;
 import javax.servlet.sip.Proxy;
 import javax.servlet.sip.ProxyBranch;
 import javax.servlet.sip.ServletParseException;
 import javax.servlet.sip.SipServletRequest;
 import javax.servlet.sip.SipServletResponse;
-import javax.servlet.sip.SipSession;
 import javax.servlet.sip.SipURI;
 import javax.servlet.sip.URI;
 import javax.sip.SipException;
@@ -61,14 +60,12 @@
 import javax.sip.message.Response;

 import org.apache.log4j.Logger;
-import org.mobicents.ha.javax.sip.ClusteredSipStack;
 import org.mobicents.ha.javax.sip.ReplicationStrategy;
 import org.mobicents.javax.servlet.sip.ProxyExt;
 import org.mobicents.servlet.sip.JainSipUtils;
 import org.mobicents.servlet.sip.address.SipURIImpl;
 import org.mobicents.servlet.sip.address.TelURLImpl;
 import org.mobicents.servlet.sip.core.dispatchers.DispatcherException;
-import org.mobicents.servlet.sip.core.dispatchers.MessageDispatcher;
import org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
 import org.mobicents.servlet.sip.core.session.MobicentsSipSession;
 import org.mobicents.servlet.sip.core.timers.ProxyTimerService;
@@ -106,7 +103,7 @@
        private transient SipFactoryImpl sipFactoryImpl;
        private boolean isNoCancel;

- transient HashMap<String, TransactionApplicationData> transactionMap = new HashMap<String, TransactionApplicationData>(); + transient Map<String, TransactionApplicationData> transactionMap = Collections.synchronizedMap(new HashMap<String, TransactionApplicationData>());

        private transient Map<URI, ProxyBranchImpl> proxyBranches;
        private boolean started;
@@ -138,7 +135,7 @@
this.proxyTimerService = ((MobicentsSipApplicationSession)request.getApplicationSession(false)).getSipContext().getProxyTimerService();
                this.originalRequest = request;
                this.sipFactoryImpl = sipFactoryImpl;
-               this.proxyBranches = new LinkedHashMap<URI, ProxyBranchImpl> ();
+ this.proxyBranches = Collections.synchronizedMap(new LinkedHashMap<URI, ProxyBranchImpl> ());
                this.proxyTimeout = 180; // 180 secs default
                this.proxy1xxTimeout = -1; // not activated by default
String outboundInterfaceStringified = ((MobicentsSipSession)request.getSession()).getOutboundInterface();
@@ -152,10 +149,25 @@
this.callerFromTag = ((MessageExt)request.getMessage()).getFromHeader().getTag();
                this.previousNode = extractPreviousNodeFromRequest(request);
this.callerCSeq = ((MessageExt)request.getMessage()).getCSeqHeader().getSeqNumber(); - String txid = ((ViaHeader) request.getMessage().getHeader(ViaHeader.NAME)).getBranch();
-               if(originalRequest.getTransactionApplicationData() != null) {
- this.transactionMap.put(txid, originalRequest.getTransactionApplicationData());
-               }
+               putTransaction(originalRequest);
+       }
+
+       public void putTransaction(SipServletRequestImpl request) {
+ final String txId = ((ViaHeader) request.getMessage().getHeader(ViaHeader.NAME)).getBranch(); + final TransactionApplicationData txData = request.getTransactionApplicationData();
+               if(txData != null && this.transactionMap.put(txId, txData) == 
null) {
+                       if(logger.isDebugEnabled()) {
+                               logger.debug("Transaction "+txId+" added to 
proxy.");
+                       }
+               }
+       }
+
+       public void removeTransaction(String txId) {
+               if(this.transactionMap.remove(txId) != null) {
+                       if(logger.isDebugEnabled()) {
+                               logger.debug("Transaction "+txId+" removed from 
proxy.");
+                       }
+               }
        }

        /*
@@ -929,7 +941,7 @@
                this.callerFromTag = initiatorFromTag;
        }

-       public HashMap<String, TransactionApplicationData> getTransactionMap() {
+       public Map<String, TransactionApplicationData> getTransactionMap() {
                return transactionMap;
        }

Reply via email to