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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Apr 20 17:42:47 CDT 2011


branch "route_replica" has been updated
       via  894e46583a25a1721cfe820cf7ad0b98e0196bde (commit)
      from  e78b522254e0cd7cad9957aacd4edfed8186d1f7 (commit)

Summary of changes:
 local-slice/BasicRoutingStateReplicationIf.ice |  120 ++++++++++++------------
 src/BasicRoutingServiceApp.cpp                 |   63 +++++++------
 src/EndpointRegistry.cpp                       |   19 +---
 src/EndpointRegistry.h                         |    6 +-
 src/ScriptProcessor.h                          |    3 +
 5 files changed, 104 insertions(+), 107 deletions(-)


- Log -----------------------------------------------------------------
commit 894e46583a25a1721cfe820cf7ad0b98e0196bde
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Apr 20 17:42:17 2011 -0500

    Incorporating review feedback. Tabs in a slice file, and some initialization cleanup.

diff --git a/local-slice/BasicRoutingStateReplicationIf.ice b/local-slice/BasicRoutingStateReplicationIf.ice
index fc855ee..576175d 100644
--- a/local-slice/BasicRoutingStateReplicationIf.ice
+++ b/local-slice/BasicRoutingStateReplicationIf.ice
@@ -36,67 +36,67 @@ module V1
     };
 
     ///////////////////////////////////////////////////////////////////////
-	// These classes and interfaces implement the replication 
-	// pattern of Asterisk SCF.
+    // These classes and interfaces implement the replication 
+    // pattern of Asterisk SCF.
 
     ["visitor"] local class RoutingStateItemVisitor
     {
     };
 
-	/**
-	 * Base class for an item that will be replicated.
-	 * The key will be unique among all state items stored in the
-	 * state replicator. 
-	 */
+    /**
+     * Base class for an item that will be replicated.
+     * The key will be unique among all state items stored in the
+     * state replicator. 
+     */
     ["visitor:RoutingStateItemVisitor"] class RoutingStateItem
     {
-	    string key;
+        string key;
     };
 
     sequence<RoutingStateItem> RoutingStateItemSeq;
 
-	/**
-	 * Listener interface. Typically implemented by
-	 * a routing service in standby mode. 
-	 */
+    /**
+     * Listener interface. Typically implemented by
+     * a routing service in standby mode. 
+     */
     interface RoutingStateReplicatorListener
     {
         void stateRemoved(Ice::StringSeq itemKeys);
-		void stateRemovedForItems(RoutingStateItemSeq items);
+        void stateRemovedForItems(RoutingStateItemSeq items);
         void stateSet(RoutingStateItemSeq items);
     };
 
-	/**
-	 * The state replicator interface. 
-	 */
+    /**
+     * The state replicator interface. 
+     */
     interface RoutingStateReplicator
     {
        void addListener(RoutingStateReplicatorListener *listener);
        void removeListener(RoutingStateReplicatorListener *listener);
        void setState (RoutingStateItemSeq items);
        void removeState(Ice::StringSeq items);
-	   void removeStateForItems(RoutingStateItemSeq items);
+       void removeStateForItems(RoutingStateItemSeq items);
        idempotent RoutingStateItemSeq getState(Ice::StringSeq itemKeys);
        idempotent RoutingStateItemSeq getAllState();
     };
 
-	/** 
-	 * All transactional operations will derive from this. 
-	 */
-	class OperationStateItem extends RoutingStateItem
+    /** 
+     * All transactional operations will derive from this. 
+     */
+    class OperationStateItem extends RoutingStateItem
     {
         string transactionId; 
     };
 
     ///////////////////////////////////////////////////////////////////////
     // These state items represent the state transistions
-	//  of the RouteSession operation.
+    //  of the RouteSession operation.
 
     /**
-	 * Indicates the RouteSessionOperation started. 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + RouteSessionOpStartKeyMod 
-	 */
+     * Indicates the RouteSessionOperation started. 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + RouteSessionOpStartKeyMod 
+     */
     class RouteSessionOpStart extends OperationStateItem
     {
         AsteriskSCF::SessionCommunications::V1::Session *source;
@@ -104,22 +104,22 @@ module V1
     };
     const string RouteSessionOpStartKeyMod = ".START";
 
-	/**
-	 * Indicates the RouteSessionOperation has completed an AMI endpoint lookup(). 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + RouteSessionOpWaitLookupKeyMod
-	 */
+    /**
+     * Indicates the RouteSessionOperation has completed an AMI endpoint lookup(). 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + RouteSessionOpWaitLookupKeyMod
+     */
     class RouteSessionOpWaitLookupState extends OperationStateItem
     {
        AsteriskSCF::Core::Endpoint::V1::EndpointSeq endpoints;
     };
     const string RouteSessionOpWaitLookupKeyMod = ".WAITLOOKUP";
 
-	/**
-	 * Indicates the RouteSessionOperation has created the bridge. 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + RouteSessionOpBridgingKeyMod
-	 */
+    /**
+     * Indicates the RouteSessionOperation has created the bridge. 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + RouteSessionOpBridgingKeyMod
+     */
     class RouteSessionOpBridgingState extends OperationStateItem
     {
         AsteriskSCF::SessionCommunications::V1::Bridge* bridge;
@@ -128,54 +128,54 @@ module V1
 
     ///////////////////////////////////////////////////////////////////////
     // These state items represent the state transistions of the 
-	// ConnectBridgedSessionsWithDestination operation.
+    // ConnectBridgedSessionsWithDestination operation.
 
-	/**
-	 * Indicates the ConnectBridgedSessionsWithDestinationOperation started. 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + ConnectBridgedSessionsWithDestStartKeyMod
-	 */
+    /**
+     * Indicates the ConnectBridgedSessionsWithDestinationOperation started. 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + ConnectBridgedSessionsWithDestStartKeyMod
+     */
     class ConnectBridgedSessionsWithDestinationOpStart extends OperationStateItem
     {
         AsteriskSCF::SessionCommunications::V1::Session *sessionToReplace;
         string destination;
     };
-	const string ConnectBridgedSessionsWithDestStartKeyMod = ".START";
+    const string ConnectBridgedSessionsWithDestStartKeyMod = ".START";
 
-	/**
-	 * Indicates the ConnectBridgedSessionsWithDestinationOperation completed an AMI endpoint lookup(). 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + ConnectBridgedSessionsWithDestWaitLookupKeyMod
-	 */
+    /**
+     * Indicates the ConnectBridgedSessionsWithDestinationOperation completed an AMI endpoint lookup(). 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + ConnectBridgedSessionsWithDestWaitLookupKeyMod
+     */
     class ConnectBridgedSessionsWithDestinationOpWaitLookupState extends OperationStateItem
     {
         AsteriskSCF::Core::Endpoint::V1::EndpointSeq endpoints;
     };
     const string ConnectBridgedSessionsWithDestWaitLookupKeyMod = ".WAITLOOKUP";
 
-	/**
-	 * Indicates the ConnectBridgedSessionsWithDestinationOperation has created the bridge. 
-	 * The key (in the base state item) is the transactionId of this 
-	 * operation + ConnectBridgedSessionsWithDestBridgingKeyMod
-	 */
+    /**
+     * Indicates the ConnectBridgedSessionsWithDestinationOperation has created the bridge. 
+     * The key (in the base state item) is the transactionId of this 
+     * operation + ConnectBridgedSessionsWithDestBridgingKeyMod
+     */
     class ConnectBridgedSessionsWithDestinationOpBridgingState extends OperationStateItem
     {
-	    AsteriskSCF::SessionCommunications::V1::Bridge* bridge;
+        AsteriskSCF::SessionCommunications::V1::Bridge* bridge;
     };
-	const string ConnectBridgedSessionsWithDestBridgingKeyMod = ".BRIDGING";
+    const string ConnectBridgedSessionsWithDestBridgingKeyMod = ".BRIDGING";
 
     ///////////////////////////////////////////////////////////////////////
     // NOTE: There is no value in replicating the ConnectBridgedSessions 
-	// operation. No intermediate results are obtained to cache. 
+    // operation. No intermediate results are obtained to cache. 
 
 
     ///////////////////////////////////////////////////////////////////////
     // Endpoint locator state items
 
-	/**  
-	 * Represents an added endpoint locator. 
-	 * The key (in the base state item) is the locator id. 
-	 */
+    /**  
+     * Represents an added endpoint locator. 
+     * The key (in the base state item) is the locator id. 
+     */
     class EndpointLocatorState extends RoutingStateItem
     { 
         AsteriskSCF::Core::Routing::V1::RegExSeq regExList;
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index eae4091..6a4f69d 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -65,7 +65,8 @@ class BasicRoutingServiceApp : public IceBox::Service
 {
 public:
     BasicRoutingServiceApp() 
-        : mDone(false), 
+        : mImplementationId("BasicRoutingService"),
+          mDone(false), 
           mInitialized(false), 
           mRunning(false),
           mPublishTestInterface(false),
@@ -86,6 +87,12 @@ public:
     void onStandby();
     bool isActive();
 
+    /**
+     * Get an impementation-specific ID for createing service discovery guids. 
+     * This is not the same as the app name, which is configurable. 
+     */
+    std::string getImplementationId() {return mImplementationId;}
+
 public:   // Overrides of IceBox::Service
     virtual void start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
     virtual void stop();
@@ -101,6 +108,7 @@ private:
     void listenToStateReplicator();
     void stopListeningToStateReplicator();
 
+    const std::string mImplementationId; 
     bool mDone;
     bool mInitialized;
     bool mRunning;
@@ -357,21 +365,20 @@ void BasicRoutingServiceApp::setCategory(const Discovery::V1::ServiceManagementP
  */
 void BasicRoutingServiceApp::registerWithServiceLocator()
 {
-    try
-    {
-        // Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system discovery mechanisms.
-        mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
+    // Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system discovery mechanisms.
+    mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
 
-        if (mServiceLocatorManagement == 0)
-        {
-            lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected.";
-            return;
-        }
+    if (mServiceLocatorManagement == 0)
+    {
+        throw IceBox::FailureException(__FILE__, __LINE__, "Configuration error: Unable to obtain proxy for property `LocatorServiceManagement.Proxy'");
+    }
 
+    try
+    {
         // Register our RoutingAdmin interface with the Service Locator.
         Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RoutingAdminObjectId));
         RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
-        string adminServiceGuid("BasicRoutingServiceAdmin"); // Should be unique for reporting.
+        string adminServiceGuid(getImplementationId() + "." + Routing::V1::RoutingServiceAdminDiscoveryCategory); // Should be unique for reporting.
         mAdminManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(adminPrx, adminServiceGuid));
 
         setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory);
@@ -379,7 +386,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
         // Register our RegistryLocator interface with the Service Locator.
         Ice::ObjectPrx locatorObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RegistryLocatorObjectId));
         LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
-        string locatorServiceGuid("BasicRoutingServiceRegistryLocator");  // Should be unique for reporting.
+        string locatorServiceGuid(getImplementationId() + "." + Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);  // Should be unique for reporting.
         mRegistryLocatorManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(locatorRegistryPrx, locatorServiceGuid));
 
         setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
@@ -387,7 +394,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
         // Register the ComponentService interface with the Service Locator.
         Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
         ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-        string componentServiceGuid("BasicRoutingService");   // Should be unique for reporting.
+        string componentServiceGuid(getImplementationId() + "." + Routing::V1::ComponentServiceDiscoveryCategory);   // Should be unique for reporting.
         mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
 
         setCategory(mComponentServiceManagement, Routing::V1::ComponentServiceDiscoveryCategory);
@@ -401,15 +408,15 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
         // Register the SessionRouter interface with the Service Locator.
         Ice::ObjectPrx sessionRouterObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(SessionRouterObjectId));
         AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouterPrx = AsteriskSCF::SessionCommunications::V1::SessionRouterPrx::checkedCast(sessionRouterObjectPrx);
-        string sessionRouterGuid("SessionRouter");   // Should be unique
+        string sessionRouterGuid(getImplementationId() + "." + Routing::V1::SessionRouterDiscoveryCategory);   // Should be unique
         mSessionRouterManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(sessionRouterPrx, sessionRouterGuid));
 
         setCategory(mSessionRouterManagement, Routing::V1::SessionRouterDiscoveryCategory);
-
     }
-    catch(...)
+    catch(const std::exception& e)
     {
-        lg(Error) << "Major problems in " << mAppName << " registerWithServiceLocator()";
+        lg(Error) << "Unable to publish component interfaces in " << mAppName << BOOST_CURRENT_FUNCTION << ". Exception: " << e.what();
+        throw; // rethrow
     }
 }
 
@@ -489,12 +496,12 @@ void BasicRoutingServiceApp::initialize()
         getLoggerFactory().setLogOutput(mIceLogger->getLogger());
 
         // Create and configure the EndpointRegistry.
-        ScriptProcessor* scriptProcesor(new LuaScriptProcessor());
-        mEndpointRegistry = new EndpointRegistry(scriptProcesor, mEventPublisher, mReplicationContext);
+         mEndpointRegistry = new EndpointRegistry(ScriptProcessorPtr(new LuaScriptProcessor()), mEventPublisher, mReplicationContext);
 
         // Publish the LocatorRegistry interface.
         mAdapter->add(mEndpointRegistry, mCommunicator->stringToIdentity(RegistryLocatorObjectId));
 
+        // Check to see if we're configured to publish a test interface.
         mPublishTestInterface = (mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".ComponentTest", "no") == "yes");
 
         if (mPublishTestInterface)
@@ -505,23 +512,18 @@ void BasicRoutingServiceApp::initialize()
         }
 
         // Create the session context needed to construct operations.
-        SessionContext *rawSessionContext(new SessionContext(mAdapter, 
+        mSessionContext = SessionContextPtr(new SessionContext(mAdapter, 
                                                              mEndpointRegistry, 
                                                              mEventPublisher, 
                                                              mWorkQueue,
                                                              mReplicationContext));
-        SessionContextPtr sessionContextPtr(rawSessionContext); 
-        mSessionContext = sessionContextPtr;
                 
         // Create the replica cache. 
-        boost::shared_ptr<OperationReplicaCache> ptr(new OperationReplicaCache(mSessionContext));
-        mOperationReplicaCache = ptr;
+        mOperationReplicaCache = OperationReplicaCachePtr(new OperationReplicaCache(mSessionContext));
 
         // Create publish the SessionRouter interface.
-        SessionRouter *rawSessionRouter(new SessionRouter(mSessionContext, mOperationReplicaCache));
-        BasicSessionRouterPtr basicSessionPtr(rawSessionRouter);
-        mSessionRouter = basicSessionPtr;
-        mAdapter->add(rawSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId));
+        mSessionRouter = new SessionRouter(mSessionContext, mOperationReplicaCache);
+        mAdapter->add(mSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId));
 
         // Create and publish the Admin interface support.
         mAdminInteface = new RoutingAdmin(mEndpointRegistry);
@@ -556,9 +558,10 @@ void BasicRoutingServiceApp::initialize()
 
         mInitialized = true;
     }
-    catch(const Ice::Exception &exception)
+    catch(const Ice::Exception &e)
     {
-        lg(Error) << "Problems in " << mAppName << " initialization(): " << exception.what();
+        lg(Error) << "Problems in " << mAppName << BOOST_CURRENT_FUNCTION << e.what();
+        throw e;
     }
 
     locateBridgeManager();
diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index cb573f4..30b951b 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -79,7 +79,7 @@ typedef map<std::string, RegisteredLocator> EndpointLocatorMap;
 class EndpointRegistryPriv
 {
 public:
-    EndpointRegistryPriv(ScriptProcessor* scriptProcessor, 
+    EndpointRegistryPriv(const ScriptProcessorPtr& scriptProcessor, 
                          const RoutingEventsPtr& eventPublisher, 
                          const ReplicationContextPtr& replicationContext) :
             mScriptProcessor(scriptProcessor), 
@@ -241,7 +241,7 @@ public:
 
     boost::shared_mutex mLock;
 
-    boost::shared_ptr<ScriptProcessor> mScriptProcessor;
+    ScriptProcessorPtr mScriptProcessor;
     EndpointLocatorMap mEndpointLocatorMap;
     const RoutingEventsPtr mEventPublisher;
     ReplicationContextPtr mReplicationContext;
@@ -347,7 +347,7 @@ typedef IceUtil::Handle<LookupResultCollector> LookupResultCollectorPtr;
 /**
  * Constructor.
  */
-EndpointRegistry::EndpointRegistry(ScriptProcessor* scriptProcessor, 
+EndpointRegistry::EndpointRegistry(const ScriptProcessorPtr& scriptProcessor, 
                                    const RoutingEventsPtr& eventPublisher,
                                    const ReplicationContextPtr& replicationContext) :
     mImpl(new EndpointRegistryPriv(scriptProcessor, eventPublisher, replicationContext))
@@ -542,18 +542,9 @@ void EndpointRegistry::setEndpointLocatorDestinationIds(const std::string& locat
 /**
  * Configure this object with a ScriptProcessor.
  */
-void EndpointRegistry::setScriptProcessor(ScriptProcessor* scriptProcessor)
+void EndpointRegistry::setScriptProcessor(const ScriptProcessorPtr& scriptProcessor)
 {
-    if (scriptProcessor == mImpl->mScriptProcessor.get())
-    {
-        // Calling this method with a pointer to the scriptProcessor that's already held in the shared_ptr would
-        // result in deleting the very object we're trying to set.
-        return;
-    }
-
-    boost::shared_ptr<ScriptProcessor> ptr(scriptProcessor);
-
-    mImpl->mScriptProcessor = ptr;
+    mImpl->mScriptProcessor = scriptProcessor;
 }
 
 /**
diff --git a/src/EndpointRegistry.h b/src/EndpointRegistry.h
index 3f0b19d..8365562 100644
--- a/src/EndpointRegistry.h
+++ b/src/EndpointRegistry.h
@@ -21,6 +21,7 @@
 #include <AsteriskSCF/SmartProxy.h>
 
 #include "ReplicationContext.h"
+#include "ScriptProcessor.h"
 
 namespace AsteriskSCF
 {
@@ -28,12 +29,11 @@ namespace BasicRoutingService
 {
 
 class EndpointRegistryPriv;
-class ScriptProcessor;
 
 class EndpointRegistry : public AsteriskSCF::Core::Routing::V1::LocatorRegistry
 {
 public:
-    EndpointRegistry(ScriptProcessor* scriptProcessor, 
+    EndpointRegistry(const ScriptProcessorPtr& scriptProcessor, 
                      const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& eventPublisher,
                      const ReplicationContextPtr& replicationContext);
 
@@ -41,7 +41,7 @@ public:
      * Configure the EndpointRegistry to use a different scriptProcessor than the
      * one created with.
      */
-    void setScriptProcessor(ScriptProcessor* scriptProcessor);
+    void setScriptProcessor(const ScriptProcessorPtr& scriptProcessor);
 
 public:
     // LocatorRegistry overrides
diff --git a/src/ScriptProcessor.h b/src/ScriptProcessor.h
index cb1a988..b5184be 100644
--- a/src/ScriptProcessor.h
+++ b/src/ScriptProcessor.h
@@ -15,6 +15,8 @@
  */
 #pragma once
 
+#include <boost/shared_ptr.hpp>
+
 #include <AsteriskSCF/Core/Routing/RoutingIf.h>
 
 namespace AsteriskSCF
@@ -35,6 +37,7 @@ public:
     virtual void setPolicy(const std::string& policy) = 0;
 
 };
+typedef boost::shared_ptr<ScriptProcessor> ScriptProcessorPtr;
 
 } // BasicRoutingService
 } // AsteriskSCF

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list