[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "retry_deux" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jan 17 17:19:08 CST 2012


branch "retry_deux" has been created
        at  df5d82f9460d3d582f89dbd1c31c770d7291b4fa (commit)

- Log -----------------------------------------------------------------
commit df5d82f9460d3d582f89dbd1c31c770d7291b4fa
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jan 17 17:18:21 2012 -0600

    Added retry logic to a single WorkQueue-based AMI call for review purposes.

diff --git a/src/PJSIPSessionModule.cpp b/src/PJSIPSessionModule.cpp
index 79a58a5..9fcbfcb 100644
--- a/src/PJSIPSessionModule.cpp
+++ b/src/PJSIPSessionModule.cpp
@@ -40,6 +40,7 @@
 #include <AsteriskSCF/Logger.h>
 #include <AsteriskSCF/WorkQueue/WorkQueue.h>
 #include <AsteriskSCF/WorkQueue/SuspendableWorkQueue.h>
+#include <AsteriskSCF/Helpers/Retry.h>
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
@@ -472,15 +473,14 @@ protected:
             else
             {
                 // If this is not an attended transfer we can just route the session as normally
-                std::string operationId = ::IceUtil::generateUUID();
+                mOperationId = ::IceUtil::generateUUID();
 
                 // Update the Party Id information on the session.
                 mSession->setSelfAsCaller();
 
                 SuspendableWorkListenerPtr listener = 0;
-                SIPAMICallbackPtr cb(new SIPAMICallback(listener, mSession, this, false, true));
-                Ice::CallbackPtr d = Ice::newCallback(cb, &SIPAMICallback::callback);
-                mSessionRouter->begin_routeSession(operationId, mSession->getSessionProxy(), mDestination, 0, mCallerID, mRedirections, d);
+                mAmiCallback = new SIPAMICallback(listener, mSession, this, false, true);
+                invokeOperation();
             }
         }
         catch (const Ice::CommunicatorDestroyedException &)
@@ -498,6 +498,12 @@ protected:
         return Complete;
     }
 
+    void invokeOperation()
+    {
+        Ice::CallbackPtr d = Ice::newCallback(mAmiCallback, &SIPAMICallback::callback);
+        mSessionRouter->begin_routeSession(mOperationId, mSession->getSessionProxy(), mDestination, 0, mCallerID, mRedirections, d);
+    }
+
     SuspendableWorkResult calledBack(const Ice::AsyncResultPtr& asyncResult)
     {
         SessionRouterPrx router = SessionRouterPrx::uncheckedCast(asyncResult->getProxy());
@@ -505,31 +511,52 @@ protected:
         {
             router->end_routeSession(asyncResult);
         }
-        catch (const DestinationNotFoundException &)
+        catch (const Ice::ConnectionLostException &cle)
         {
-            if (success(pjsip_inv_end_session(mInv, 404, NULL, &mTdata)))
-            {
-                pjsip_inv_send_msg(mInv, mTdata);
-            }
-            else
+            // Assume a failover is occurring for the routing service. 
+            // This will block the WorkQueue's thread, but it's highly likely
+            // that the failover effects most of the other enqueued operations 
+            // anyway. 
+            RetryPolicy retryPolicy(5,500);
+            while(retryPolicy.canRetry())
             {
-                lg(Warning) << "Unable to create 404 response for INVITE";
+                lg(Warning) << "SessionCreationOperation: Retrying routeSession operation.";
+
+                if(!retryPolicy.retry())
+                {
+                    lg(Error) << "SessionCreationOperation: ConnectionLostException routing session failed "  << retryPolicy.getMaxRetries() << " retries." ;
+                    endSession(500);
+                }
+                else
+                {
+                    // Retry the operation. 
+                    invokeOperation();
+                }
             }
         }
+        catch (const DestinationNotFoundException &)
+        {
+            endSession(404);
+        }
         catch (...)
         {
-            if (success(pjsip_inv_end_session(mInv, 500, NULL, &mTdata)))
-            {
-                pjsip_inv_send_msg(mInv, mTdata);
-            }
-            else
-            {
-                lg(Warning) << "Unable to create 500 response for INVITE";
-            }
+            endSession(500);
         }
         return Complete;
     }
 
+    void endSession(int statusCode)
+    {
+        if (success(pjsip_inv_end_session(mInv, statusCode, NULL, &mTdata)))
+        {
+            pjsip_inv_send_msg(mInv, mTdata);
+        }
+        else
+        {
+            lg(Warning) << "Unable to create " << statusCode << " response for INVITE";
+        }
+    }
+
 private:
     PJSIPSessionModulePtr mSessionModule;
     SIPEndpointPtr mCaller;
@@ -541,6 +568,8 @@ private:
     SIPSessionPtr mSession;
     CallerPtr mCallerID;
     RedirectionsPtr mRedirections;
+    std::string mOperationId;
+    SIPAMICallbackPtr mAmiCallback;
 };
 
 bool PJSIPSessionModule::getPrivacy(pjsip_rx_data *rdata)

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list