[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "cleanup" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Nov 29 16:13:01 CST 2010


branch "cleanup" has been updated
       via  e971cf16fcd669f6fbec5b48ff2c36aca9e1ad6a (commit)
      from  34ce99c2d1e10d40be12c6066a30a6b0b6ad504e (commit)

Summary of changes:
 src/SessionRouter.cpp |  116 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 76 insertions(+), 40 deletions(-)


- Log -----------------------------------------------------------------
commit e971cf16fcd669f6fbec5b48ff2c36aca9e1ad6a
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Nov 29 16:11:48 2010 -0600

    Addressed review comments from review: CR-ASTSCF-6

diff --git a/src/SessionRouter.cpp b/src/SessionRouter.cpp
index 1afe420..ce6a266 100644
--- a/src/SessionRouter.cpp
+++ b/src/SessionRouter.cpp
@@ -57,9 +57,10 @@ public:
      */
     RetryPolicy(size_t maxRetries, size_t intervalInMilliseconds) :
         mMaxRetries(maxRetries),
-        mRetryInterval(intervalInMilliseconds),
+        mRetryIntervalMilliseconds(intervalInMilliseconds),
         mCounter(0)
     {
+        assert(maxRetries < 0xffff);
     }
 
     /**
@@ -67,19 +68,26 @@ public:
      */
     bool canRetry()
     {
-        return mCounter < mMaxRetries;
+        return mCounter <= mMaxRetries;
     }
 
     /**
-     * Using must call this for each attempt. Applies the delay between calls and does
+     * User must call this after each failed attempt. Applies the delay between calls and does
      * bookkeeping.
      */
     bool retry()
     {
-        lg(Debug) << "Retrying for the " << mCounter + 1 << " time.";
-        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(mRetryInterval));
         ++mCounter;
-        return canRetry();
+        lg(Debug) << "Retrying for the " << mCounter << " time.";
+
+        bool doRetry = canRetry();
+
+        if (doRetry)
+        {
+            IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(mRetryIntervalMilliseconds));
+        }
+
+        return doRetry;
     }
 
     /**
@@ -92,7 +100,7 @@ public:
 
 private:
     size_t mMaxRetries;
-    size_t mRetryInterval;
+    size_t mRetryIntervalMilliseconds;
     size_t mCounter;
 };
 
@@ -156,7 +164,7 @@ public: // The following operations are implementations of the SessionListener i
             }
             catch(const Ice::Exception &e)
             {
-                lg(Error) << "Session Listener unable to forward stop to session " << (*s)->ice_toString() << " due to " << e.what() << std::endl;
+                lg(Error) << "Session Listener unable to forward stop to session " << (*s)->ice_toString() << " due to " << e.what();
             }
         }
 
@@ -198,7 +206,7 @@ public:
             }
             catch(const Ice::Exception &e)
             {
-                lg(Error) << "Exception adding listener to session " << session->ice_toString() << ". Details: " << e.what() << std::endl;
+                lg(Error) << "Exception adding listener to session " << session->ice_toString() << ". Details: " << e.what();
             }
         }
     }
@@ -225,18 +233,18 @@ public:
             sessionsToCall = mSessions;
         }
 
-        lg(Debug) << "unregister() called with " << sessionsToCall.size() << " sessions to remove listener from." << std::endl ;
+        lg(Debug) << "unregister() called with " << sessionsToCall.size() << " sessions to remove listener from.";
 
         for(SessionSeq::iterator s=sessionsToCall.begin(); s != sessionsToCall.end(); ++s)
         {
             try
             {
-                lg(Debug) << "Removing listener from session " << (*s)->ice_toString() << std::endl ;
+                lg(Debug) << "Removing listener from session " << (*s)->ice_toString();
                 (*s)->removeListener(mListenerPrx);
             }
             catch(const Ice::Exception &e)
             {
-                lg(Error) << "Exception removing listener from session " << (*s)->ice_toString() << ". Details: " << e.what() << std::endl;
+                lg(Error) << "Exception removing listener from session " << (*s)->ice_toString() << ". Details: " << e.what();
             }
         }
 
@@ -279,10 +287,24 @@ public:
           mAdapter(adapter)
     {
         Ice::ObjectPrx prx = adapter->addWithUUID(mSessionListener);
-        SessionListenerPrx listenerProxy = SessionListenerPrx::checkedCast(prx);
-        mSessionListener->setProxy(listenerProxy);
 
-        mSessionListener->addSessionAndListen(session);
+        try
+        {
+            SessionListenerPrx listenerProxy = SessionListenerPrx::checkedCast(prx);
+            mSessionListener->setProxy(listenerProxy);
+
+            mSessionListener->addSessionAndListen(session);
+        }
+        catch(...)
+        {
+            try
+            {
+               mAdapter->remove(prx->ice_getIdentity());
+            }
+            catch(...)
+            {
+            }
+        }
     }
 
     SessionListenerAllocator(Ice::ObjectAdapterPtr adapter, SessionSeq& sessionSequence)
@@ -290,12 +312,26 @@ public:
           mAdapter(adapter)
     {
         Ice::ObjectPrx prx = adapter->addWithUUID(mSessionListener);
-        SessionListenerPrx listenerProxy = SessionListenerPrx::checkedCast(prx);
-        mSessionListener->setProxy(listenerProxy);
 
-        for(SessionSeq::iterator s = sessionSequence.begin(); s != sessionSequence.end(); ++s)
+        try
         {
-            mSessionListener->addSessionAndListen(*s);
+            SessionListenerPrx listenerProxy = SessionListenerPrx::checkedCast(prx);
+            mSessionListener->setProxy(listenerProxy);
+
+            for(SessionSeq::iterator s = sessionSequence.begin(); s != sessionSequence.end(); ++s)
+            {
+                mSessionListener->addSessionAndListen(*s);
+            }
+        }
+        catch(...)
+        {
+            try
+            {
+               mAdapter->remove(prx->ice_getIdentity());
+            }
+            catch(...)
+            {
+            }
         }
     }
 
@@ -306,13 +342,13 @@ public:
         // in proper order.
         try
         {
-            lg(Debug) << "About to unregister the listener..." << std::endl ;
+            lg(Debug) << "About to unregister the listener..." ;
 
             mSessionListener->unregister();
         }
         catch(const std::exception& e)
         {
-            lg(Debug) << "Exception unregistering: " << e.what() << std::endl ;
+            lg(Debug) << "Exception unregistering: " << e.what() ;
         }
 
         try
@@ -324,7 +360,7 @@ public:
         }
         catch(const std::exception& e)
         {
-            lg(Debug) << "Exception removing listener from Object Adatper " << e.what() << std::endl ;
+            lg(Debug) << "Exception removing listener from Object Adatper " << e.what() ;
         }
     }
 
@@ -408,7 +444,7 @@ public:
             }
             catch (const Ice::Exception &e)
             {
-                lg(Error) << "Unable to forward the start() operation to session " << (*s) << " Details: " << e.what() << std::endl;
+                lg(Error) << "Unable to forward the start() operation to session " << (*s) << " Details: " << e.what();
                 // TBD... probably other bridge cleanup needs to be done.
                 throw;
             }
@@ -434,18 +470,18 @@ public:
             {
                 if(!policy.retry())
                 {
-                    lg(Error) << "getBridge(): ConnectionLostException getting bridge for session, failed "  << policy.maxRetries() << " retries." << std::endl;
+                    lg(Error) << "getBridge(): ConnectionLostException getting bridge for session, failed "  << policy.maxRetries() << " retries." ;
                     throw;
                 }
             }
             catch(const NotBridged& e)
             {
-                lg(Error) << "getBridge(): session is not bridged."  << std::endl;
+                lg(Error) << "getBridge(): session is not bridged." ;
                 throw e; // rethrow
             }
             catch(const Ice::Exception& e)
             {
-                lg(Error) << "getBridge(): Ice exception getting bridge for session:"  << e.what() << std::endl;
+                lg(Error) << "getBridge(): Ice exception getting bridge for session:"  << e.what();
                 throw e; // rethrow
             }
         }
@@ -454,23 +490,23 @@ public:
     }
 
     /**
-     * Add a session to each of a given set of endpoints, and return a collection of the 
+     * Create a session to each of a given set of endpoints, and return a collection of the 
      * newly added sessions. 
      */
-    SessionSeq addSessionToEndpoints(EndpointSeq& endpoints, const string& destination, SessionListenerAllocator& listener)
+    SessionSeq createSessionForEndpoints(const EndpointSeq& endpoints, const string& destination, SessionListenerAllocator& listener)
     {
         // Add a session
         SessionSeq newSessions;
-        for (EndpointSeq::iterator e = endpoints.begin(); e != endpoints.end(); ++e)
+        for (EndpointSeq::const_iterator e = endpoints.begin(); e != endpoints.end(); ++e)
         {
             try
             {
                 SessionEndpointPrx sessionEndpoint = SessionEndpointPrx::checkedCast(*e);
 
                 // Create a session on the destination.
-                lg(Debug) << "addSessionToEndpoints(): Creating a session at destination " << destination;
+                lg(Debug) << "createSessionForEndpoints(): Creating a session at destination " << destination;
                 SessionPrx destSession = sessionEndpoint->createSession(destination, listener->getProxy());
-                lg(Debug) << "  Session proxy: " << destSession->ice_toString() << std::endl;
+                lg(Debug) << "  Session proxy: " << destSession->ice_toString() ;
 
                 listener->addSession(destSession);
                 newSessions.push_back(destSession);
@@ -489,7 +525,7 @@ public:
      *   @bridge The bridge whose sessions are to be accessed.
      *   @except An optional session proxy to be excluded from the list of sessions. 
      */
-    SessionSeq getSessionsInBridge(BridgePrx bridge, SessionPrx except=0)
+    SessionSeq getSessionsInBridge(const BridgePrx& bridge, const SessionPrx& except=0)
     {
         SessionSeq sessions; 
         try
@@ -511,7 +547,7 @@ public:
         }
         catch(const Ice::Exception &e)
         {
-            lg(Error) << "Unable to get list of sessions for bridge. Throwing " << e.what() << std::endl;
+            lg(Error) << "Unable to get list of sessions for bridge. Throwing " << e.what();
             throw e; // rethrow
         }
         return sessions;
@@ -577,7 +613,7 @@ void SessionRouter::setBridgeManagerAccessor(const BridgeManagerAccessorPtr& bri
 void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::SessionPrx& source, const std::string& destination,
     const Ice::Current& current)
 {
-    lg(Debug) << "routeSession() entered with destination " << destination << std::endl;
+    lg(Debug) << "routeSession() entered with destination " << destination ;
 
     // Create a listener for the source to handle early termination.
     // The wrapper we're using will remove the listener and free it when
@@ -585,11 +621,11 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
     SessionListenerAllocator listener(mImpl->mAdapter, source);
 
     // Route the destination
-    lg(Debug) << "routeSession(): Routing destination " << destination << std::endl;
+    lg(Debug) << "routeSession(): Routing destination " << destination;
     EndpointSeq endpoints = mImpl->lookupEndpoints(destination, current);
 
     // Add a session to the endpoints. 
-    SessionSeq newSessions = mImpl->addSessionToEndpoints(endpoints, destination, listener);
+    SessionSeq newSessions = mImpl->createSessionForEndpoints(endpoints, destination, listener);
 
     if (listener->getNumSessions() < 2)
     {
@@ -620,7 +656,7 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
     }
     catch (const Ice::Exception &e)
     {
-        lg(Debug) << "routeSession(): Exception creating bridge: " << e.what() << std::endl;
+        lg(Debug) << "routeSession(): Exception creating bridge: " << e.what();
         listener->unregister();
 
         throw BridgingException(source->getEndpoint()->getId(), destination);
@@ -643,7 +679,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
     const ::std::string& destination,
     const Ice::Current& current)
 {
-    lg(Debug) << "connectBridgedSessionsWithDestination() entered with destination " << destination << std::endl;
+    lg(Debug) << "connectBridgedSessionsWithDestination() entered with destination " << destination;
 
     BridgePrx bridge(sessionToReplace->getBridge());
 
@@ -660,7 +696,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
     EndpointSeq endpoints = mImpl->lookupEndpoints(destination, current);
 
     // Add a session 
-    SessionSeq newSessions = mImpl->addSessionToEndpoints(endpoints, destination, listener);
+    SessionSeq newSessions = mImpl->createSessionForEndpoints(endpoints, destination, listener);
 
     if (listener->getNumSessions() < 2)
     {
@@ -712,7 +748,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
     const SessionPrx& bridgedSession,
     const Ice::Current&)
 {
-    lg(Debug) << "connectBridgedSessions() entered... " << std::endl;
+    lg(Debug) << "connectBridgedSessions() entered... ";
 
     // Get the bridge being merged into.
     BridgePrx mergeBridge = mImpl->getBridge(sessionToReplace);

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list