[asterisk-scf-commits] asterisk-scf/release/routing.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Jun 3 14:18:22 CDT 2011


branch "master" has been updated
       via  7fcb7f067f0bff9f56f2563e67f47ea5ef63bbd9 (commit)
      from  7c31780a5e1ecc65464ab9c104da8d7d6508f54d (commit)

Summary of changes:
 config/README.txt                                  |   21 +-
 config/basicrouting.config                         |   25 --
 config/routing.conf                                |   40 ++++
 .../{routingtest-integ.config => routingtest.conf} |   10 +-
 config/routingtest.config                          |   34 ---
 src/BasicRoutingServiceApp.cpp                     |  245 +++++++++++++-------
 src/BasicRoutingStateReplicatorApp.cpp             |   57 +++---
 test/TestRouting.cpp                               |    8 +
 8 files changed, 251 insertions(+), 189 deletions(-)
 delete mode 100644 config/basicrouting.config
 create mode 100644 config/routing.conf
 rename config/{routingtest-integ.config => routingtest.conf} (93%)
 delete mode 100644 config/routingtest.config


- Log -----------------------------------------------------------------
commit 7fcb7f067f0bff9f56f2563e67f47ea5ef63bbd9
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Jun 3 14:17:04 2011 -0500

    Some cleanup:
      - Incorporated the cleanup of the Routing Service startup review, with exception of "standby by default".
      - Renamed the Ice config files.

diff --git a/config/README.txt b/config/README.txt
index 6c00267..3f79dbf 100644
--- a/config/README.txt
+++ b/config/README.txt
@@ -1,18 +1,21 @@
-To run the routing service with other Asterisk SCF components:
 
-  icebox  --Ice.Config=basicrouting.config
+To run the routing service alongside other Asterisk SCF components:
 
-To run the Routing Service tests as mulitple processes:
+  > icebox  --Ice.Config=routing.conf
 
-  icebox --Ice.Config=test_service_locator.config
+To run the Routing Service tests in a single process:
 
-  icebox  --Ice.Config=basicrouting.config
+  > icebox --Ice.Config=routingtest.conf
 
-  icebox  --Ice.Config=routingtest.config
+   -or- 
 
+  > make test
 
-To run the Routing Service tests in a single process, in the build directory:
+   -or-
 
-  make test
+  In VisualStudio, right-click RUN_TESTS project and select "build".
+
+
+Note: On windows, you will need to run iceboxd instead of icebox 
+      if you compiled in debug mode. 
 
-On windows, you may need to run iceboxd instead of icebox.
diff --git a/config/basicrouting.config b/config/basicrouting.config
deleted file mode 100644
index 476c2ea..0000000
--- a/config/basicrouting.config
+++ /dev/null
@@ -1,25 +0,0 @@
-# This is a configuration file for the Basic Routing Service
-
-IceBox.Service.BasicRoutingService=BasicRoutingService:create 
-
-IceBox.InheritProperties=1 
-
-BasicRoutingServiceAdapter.Endpoints=tcp -p 10050
-
-
-BasicRoutingServiceAdapter.ThreadPool.Size=4
-BasicRoutingServiceAdapter.ThreadPool.SizeMax=10
-BasicRoutingServiceAdapter.ThreadPool.SizeWarn=9
-
-# Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
-LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
-
-# Where to find the Service Locator.
-LocatorService.Proxy=LocatorService:tcp -p 4411
-
-# Endpoints for Icestorm events
-TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
-
-# Category for the bridge service
-BridgeManager.ServiceLocatorId=BridgeService
-
diff --git a/config/routing.conf b/config/routing.conf
new file mode 100644
index 0000000..21c2991
--- /dev/null
+++ b/config/routing.conf
@@ -0,0 +1,40 @@
+# This is a configuration file for the Basic Routing Service
+
+Ice.Default.CollocationOptimized=0
+Ice.Warn.UnknownProperties=0
+Ice.ThreadPool.Client.Size=4
+
+IceBox.Service.RoutingService=BasicRoutingService:create
+
+IceBox.InheritProperties=1 
+
+
+RoutingService.Endpoints=tcp -p 10050
+RoutingService.Backplane.Endpoints=tcp -p 10051
+RoutingService.ThreadPool.Size=4
+RoutingService.ThreadPool.SizeMax=10
+RoutingService.ThreadPool.SizeWarn=9
+
+RoutingService.Standby=no
+
+RoutingService.Standalone=yes
+
+#Replicator.InstanceName=Replicator
+#Replicator.Endpoints=default -p 10054
+#Replicator.ComponentService.Endpoints=default -p 10055
+#Replicator.ThreadPool.Size=4
+#Replicator.ThreadPool.SizeMax=10
+#Replicator.ThreadPool.SizeWarn=9
+
+# Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
+
+# Where to find the Service Locator.
+LocatorService.Proxy=LocatorService:tcp -p 4411
+
+# Endpoints for Icestorm events
+TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
+
+# Category for the bridge service
+BridgeManager.ServiceLocatorId=BridgeService
+
diff --git a/config/routingtest-integ.config b/config/routingtest.conf
similarity index 93%
rename from config/routingtest-integ.config
rename to config/routingtest.conf
index e38641b..a7fb9d0 100644
--- a/config/routingtest-integ.config
+++ b/config/routingtest.conf
@@ -41,7 +41,7 @@ BridgeManager.ServiceLocatorId=BridgeService
 # Routing Service properties
 
 RoutingService.Endpoints=tcp -p 10050
-RoutingService.ComponentService.Endpoints=tcp -p 10051
+RoutingService.Backplane.Endpoints=tcp -p 10051
 RoutingService.ThreadPool.Size=8
 RoutingService.ThreadPool.SizeMax=14
 RoutingService.ThreadPool.SizeWarn=9
@@ -50,7 +50,7 @@ RoutingService.StateReplicatorName=Replicator
 RoutingService.ComponentTest=yes
 
 RoutingService2.Endpoints=tcp -p 10052
-RoutingService2.ComponentService.Endpoints=tcp -p 10053
+RoutingService2.Backplane.Endpoints=tcp -p 10053
 RoutingService2.ThreadPool.Size=8
 RoutingService2.ThreadPool.SizeMax=14
 RoutingService2.ThreadPool.SizeWarn=9
@@ -59,7 +59,7 @@ RoutingService2.StateReplicatorName=Replicator
 
 Replicator.InstanceName=Replicator
 Replicator.Endpoints=default -p 10054
-Replicator.ComponentService.Endpoints=default -p 10055
+Replicator.Backplane.Endpoints=default -p 10055
 Replicator.ThreadPool.Size=8
 Replicator.ThreadPool.SizeMax=14
 Replicator.ThreadPool.SizeWarn=9
@@ -83,8 +83,8 @@ BackupLocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10052
 SessionRouter.Proxy=SessionRouter:tcp -p 10050
 BackupSessionRouter.Proxy=SessionRouter:tcp -p 10052
 
-Replica.Proxy=BasicRoutingServiceReplica:tcp -p 10050
-BackupReplica.Proxy=BasicRoutingServiceReplica:tcp -p 10052
+Replica.Proxy=BasicRoutingServiceReplica:tcp -p 10051
+BackupReplica.Proxy=BasicRoutingServiceReplica:tcp -p 10053
 
 RoutingComponent.Proxy=BasicRoutingComponent:tcp -p 10051
 
diff --git a/config/routingtest.config b/config/routingtest.config
deleted file mode 100644
index c35f7ea..0000000
--- a/config/routingtest.config
+++ /dev/null
@@ -1,34 +0,0 @@
-# This is a configuration file for the Routing Service Test driver.
-
-
-IceBox.Service.RoutingTest=RoutingTest:create --log_level=all
-
-IceBox.InheritProperties=1 
-
-# Test adapter
-TestRoutingAdapterOut.Endpoints=tcp -p 10070
-TestRoutingAdapterIn.Endpoints=tcp -p 10071
-
-
-# Where to find the ServiceLocatorManagement interface. 
-# We need the ServiceLocatorManagement interface in order to register our test version of the BridgeManger. 
-LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
-
-# Where to look for the Routing Service LocatorRegistry interface
-LocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10050
-
-SessionRouter.Proxy=SessionRouter:tcp -p 10050
-
-# Endpoints for Icestorm events
-TopicManager.Proxy=IceStorm/TopicManager:default -p 10000
-
-# Id to use to lookup the Bridge Manager.
-BridgeManager.ServiceLocatorId=BridgeService
-
-TestRoutingAdapterIn.ThreadPool.Size=4
-TestRoutingAdapterIn.ThreadPool.SizeMax=10
-TestRoutingAdapterIn.ThreadPool.SizeWarn=9
-
-TestRoutingAdapterOut.ThreadPool.Size=4
-TestRoutingAdapterOut.ThreadPool.SizeMax=10
-TestRoutingAdapterOut.ThreadPool.SizeWarn=9
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 38f768d..99f1669 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -64,8 +64,8 @@ namespace BasicRoutingService
 class ComponentServiceImpl;
 typedef ::IceUtil::Handle<ComponentServiceImpl> ComponentServiceImplPtr;
 
-class ReplicaManagement;
-typedef ::IceUtil::Handle<ReplicaManagement> ReplicaManagementPtr;
+class ReplicaControl;
+typedef ::IceUtil::Handle<ReplicaControl> ReplicaControlPtr;
 
 class BasicRoutingServiceApp : public IceBox::Service
 {
@@ -99,8 +99,10 @@ private:
     void initialize();
     void locateBridgeManager();
     void locateStateReplicator();
-    void registerWithServiceLocator(bool includeComponentService);
-    void deregisterFromServiceLocator(bool includeComponentService);
+    void registerWithServiceLocator(bool includeBackplaneServices);
+    void deregisterFromServiceLocator(bool includeBackplaneServices);
+    void suspendRegisteredServants(bool includeBackplaneServices);
+    void unsuspendRegisteredServants(bool includeBackplaneServices);
 
     void listenToStateReplicator();
     void stopListeningToStateReplicator();
@@ -124,21 +126,34 @@ private:
     ServiceManagementPrx mRegistryLocatorManagement;
     ServiceManagementPrx mAdminManagement;
     ServiceManagementPrx mComponentServiceManagement;
+    ServiceManagementPrx mReplicaManagement;
     ServiceManagementPrx mSessionRouterManagement;
 
     // Our published interfaces.
     BasicSessionRouterPtr mSessionRouter;
+    SessionRouterPrx mSessionRouterPrx;
+
     RoutingServiceAdminPtr mAdminInteface;
+    RoutingServiceAdminPrx mAdminPrx;
+
     ComponentServiceImplPtr mComponentService;
+    ComponentServicePrx mComponentServicePrx;
+
     ComponentTestPtr mComponentTest;
+    ComponentTestPrx mComponentTestPrx;
+
     AsteriskSCF::Discovery::SmartProxy<BridgeManagerPrx> mBridgeManager;
     RoutingServiceEventPublisherPtr mEventPublisher;
     boost::shared_ptr<OperationReplicaCache> mOperationReplicaCache;
+
     EndpointRegistryPtr mEndpointRegistry;
+    LocatorRegistryPrx mEndpointRegistryPrx;
 
     // Replication support
     ReplicationContextPtr mReplicationContext;
-    ReplicaManagementPtr mReplicaManagement;
+    ReplicaPrx mReplicaPrx;
+
+    ReplicaControlPtr mReplicaControl;
     AsteriskSCF::Discovery::SmartProxy<RoutingStateReplicatorPrx> mStateReplicator;
     RoutingStateReplicatorListenerPtr mReplicatorListener;
 
@@ -146,8 +161,9 @@ private:
     bool mListeningToReplicator;
 
     // Implementation
-    ::Ice::ObjectAdapterPtr mAdapter;
-    ::Ice::ObjectAdapterPtr mComponentServiceAdapter;
+    ::Ice::ObjectAdapterPtr mServiceAdapter;
+    ::Ice::ObjectAdapterPtr mBackplaneAdapter;
+
     ::Ice::CommunicatorPtr mCommunicator;
 
     boost::shared_mutex mReplicatorLock;
@@ -238,7 +254,7 @@ private:
 /**
  * This class provides implementation for this component's Replica management interface.
  */
-class ReplicaManagement : public Replica
+class ReplicaControl : public Replica
 {
 public:
     /**
@@ -246,7 +262,7 @@ public:
      *  @param app 
      *  @param adapter The adapter is assumed to have been activated. 
      */
-    ReplicaManagement(BasicRoutingServiceApp* app, ::Ice::ObjectAdapterPtr adapter) : mApp(app), mAdapter(adapter)
+    ReplicaControl(BasicRoutingServiceApp* app, ::Ice::ObjectAdapterPtr adapter) : mApp(app), mAdapter(adapter)
     { 
     }
 
@@ -399,57 +415,49 @@ void setCategory(const AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx& s
  * Register this component's primary public interfaces with the Service Locator.
  * This enables other Asterisk SCF components to locate the interfaces we are publishing.
  *
- * @param includeComponentService If true, registers our ComponentService interface
- * in addition to all our other interfaces. While it is not uncommon to need to 
- * re-register most of our interfaces due to a pause()/resume(), we only deregister
- * the ComponentService during shutdown. So this variable would typically be true only 
- * during initial startup. 
+ * @param includeBackplaneServices If true, registers our management interfaces
+ * in addition to all our other interfaces. 
  */
-void BasicRoutingServiceApp::registerWithServiceLocator(bool includeComponentService)
+void BasicRoutingServiceApp::registerWithServiceLocator(bool includeBackplaneServices)
 {
     try
     {
         // Register our RoutingAdmin interface with the Service Locator.
-        ::Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RoutingAdminObjectId));
-        RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
         string adminServiceGuid(mImplementationId + "." + Routing::V1::RoutingServiceAdminDiscoveryCategory); // Should be unique for reporting.
-        mAdminManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(adminPrx, adminServiceGuid));
-
+        mAdminManagement = mServiceLocatorManagement->addService(mAdminPrx, adminServiceGuid);
         setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory);
 
         // Register our RegistryLocator interface with the Service Locator.
-        ::Ice::ObjectPrx locatorObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RegistryLocatorObjectId));
-        LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
         string locatorServiceGuid(mImplementationId + "." + Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);  // Should be unique for reporting.
-        mRegistryLocatorManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(locatorRegistryPrx, locatorServiceGuid));
-
+        mRegistryLocatorManagement = mServiceLocatorManagement->addService(mEndpointRegistryPrx, locatorServiceGuid);
         setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
 
         // 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(mImplementationId + "." + Routing::V1::SessionRouterDiscoveryCategory);   // Should be unique
-        mSessionRouterManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(sessionRouterPrx, sessionRouterGuid));
-
+        mSessionRouterManagement = mServiceLocatorManagement->addService(mSessionRouterPrx, sessionRouterGuid);
         setCategory(mSessionRouterManagement, Routing::V1::SessionRouterDiscoveryCategory);
 
-        if (includeComponentService)
+        if (includeBackplaneServices)
         {
             // Register the ComponentService interface with the Service Locator.
-            // Note that this interface has it's own adapter.
-            ::Ice::ObjectPrx componentServiceObjectPrx = mComponentServiceAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
-            ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
+            // Note that this interface goes on the management adapter.
             string componentServiceGuid(mImplementationId + "." + Routing::V1::ComponentServiceDiscoveryCategory);   // Should be unique for reporting.
-            mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
-
-            setCategory(mComponentServiceManagement, Routing::V1::ComponentServiceDiscoveryCategory);
+            mComponentServiceManagement = mServiceLocatorManagement->addService(mComponentServicePrx, componentServiceGuid);
+            setCategory(mComponentServiceManagement, ComponentServiceId); // This really needs a custom comparator.
 
             if (mPublishTestInterface)
             {
                 // Register our test servant as a facet of the ComponentService interface.
-                mComponentServiceAdapter->addFacet(mComponentTest, componentServicePrx->ice_getIdentity(), AsteriskSCF::System::Component::V1::ComponentTestFacet);
+                mComponentTestPrx = ComponentTestPrx::uncheckedCast(
+                    mBackplaneAdapter->addFacet(mComponentTest, 
+                                                mComponentServicePrx->ice_getIdentity(), 
+                                                AsteriskSCF::System::Component::V1::ComponentTestFacet));
             }
+
+            // Register the Replica interface with the Service Locator.
+            string replicaServiceGuid(mImplementationId + "." + "ReplicaControl");   // Should be unique for reporting.
+            mReplicaManagement = mServiceLocatorManagement->addService(mReplicaPrx, replicaServiceGuid);
+            setCategory(mReplicaManagement, ReplicaServiceId);  // This really needs a custom comparator.
         }
     }
     catch(const std::exception& e)
@@ -460,15 +468,13 @@ void BasicRoutingServiceApp::registerWithServiceLocator(bool includeComponentSer
 }
 
 /**
- * Deregister this component's primary public interfaces from the Service Locator.
- * This is done at shutdown, and whenever we want to keep other services from locating
- * our interfaces.
+ * Deregister this component's interfaces from the Service Locator.
  *
- * @param includeComponentService If true, deregisters our ComponentService interface
+ * @param includeBackplaneServices If true, deregisters our management interfaces
  * in addition to all our other interfaces, making this component unreachable from the 
- * rest of Asterisk SCF. Should only be done during shutdown.
+ * rest of Asterisk SCF. 
  */
-void BasicRoutingServiceApp::deregisterFromServiceLocator(bool includeComponentService)
+void BasicRoutingServiceApp::deregisterFromServiceLocator(bool includeBackplaneServices)
 {
     try
     {
@@ -476,14 +482,72 @@ void BasicRoutingServiceApp::deregisterFromServiceLocator(bool includeComponentS
         mAdminManagement->unregister();
         mSessionRouterManagement->unregister();
 
-        if (includeComponentService)
+        if (includeBackplaneServices)
         {
             mComponentServiceManagement->unregister();
+            mReplicaManagement->unregister();
+        }
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << BOOST_CURRENT_FUNCTION << e.what();
+    }
+}
+
+/**
+ * Suspends this component's primary public interfaces 
+ * within the Service Locator. When suspended in this manner, the ServiceLocator
+ * will not consider the component during lookup requests. 
+ *
+ * @param includeBackplaneServices If true, affects our management interfaces
+ * in addition to all our other interfaces.
+ */
+void BasicRoutingServiceApp::suspendRegisteredServants(bool includeBackplaneServices)
+{
+    try
+    {
+        mRegistryLocatorManagement->suspend();
+        mAdminManagement->suspend();
+        mSessionRouterManagement->suspend();
+
+        if (includeBackplaneServices)
+        {
+            mComponentServiceManagement->suspend();
+        
+            mReplicaManagement->suspend();
+        }
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << BOOST_CURRENT_FUNCTION << e.what();
+    }
+}
+
+/**
+ * Unsuspends this component's primary public interfaces 
+ * within the Service Locator. This allows them to be 
+ * located again via the Service Locator. 
+ *
+ * @param includeBackplaneServices If true, affects our management interfaces
+ * in addition to all our other interfaces.
+ */
+void BasicRoutingServiceApp::unsuspendRegisteredServants(bool includeBackplaneServices)
+{
+    try
+    {
+        mRegistryLocatorManagement->unsuspend();
+        mAdminManagement->unsuspend();
+        mSessionRouterManagement->unsuspend();
+
+        if (includeBackplaneServices)
+        {
+            mComponentServiceManagement->unsuspend();
+            mReplicaManagement->unsuspend();
         }
     }
-    catch(...)
+    catch(const std::exception& e)
     {
-        lg(Error) << "Had trouble in deregisterFromServiceLocator().";
+        lg(Error) << BOOST_CURRENT_FUNCTION << e.what();
     }
 }
 
@@ -526,7 +590,6 @@ void BasicRoutingServiceApp::locateStateReplicator()
         lg(Error) << "StateReplicator not found. Check configuration.";
         throw;
     }
-
 }
 
 /**
@@ -537,32 +600,33 @@ void BasicRoutingServiceApp::initialize()
 {
     try
     {
-        // Create the primary adapter.
-        mAdapter = mCommunicator->createObjectAdapter(mAppName);
+        // Create the adapter that our functional services are published on.
+        mServiceAdapter = mCommunicator->createObjectAdapter(mAppName);
 
-        // Create a separate adapter just for the component service. This is 
-        // to make it easy to deactivate all of our interfaces other than the
-        // component service for suspend()/resume().  
-        mComponentServiceAdapter = mCommunicator->createObjectAdapter(mAppName + ".ComponentService");
+        // Create an adapter that is bound to the dedicated (non-movable) address of this component. 
+        mBackplaneAdapter = mCommunicator->createObjectAdapter(mAppName + ".Backplane");
 
-        bool active = !(mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".Standby", "no") == "yes");
+        // NOTE: In the near future, Standalone instances are the only instances that default to being active. 
+        // When that is in place, non-standalone instances will need to be made active via the Replica interface. 
+        string standaloneProp = mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".Standalone", "no");
+        bool standalone = (standaloneProp == "yes") || (standaloneProp == "true");
 
-        bool standalone = (mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".Standalone", "no") == "yes");
+        string standbyProp = mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".Standby", "no");
+        bool active = (standbyProp == "no") || (standbyProp == "false");
 
         // Create the replication context.
         mReplicationContext = ReplicationContextPtr(new ReplicationContext(active, standalone));
 
-        mEventPublisher = new RoutingServiceEventPublisher(mAdapter);
+        mEventPublisher = new RoutingServiceEventPublisher(mServiceAdapter);
 
         // setup the logger
-        ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mAdapter);
+        ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mServiceAdapter);
         getLoggerFactory().setLogOutput(mIceLogger->getLogger());
 
         // Create and configure the EndpointRegistry.
-         mEndpointRegistry = new EndpointRegistry(ScriptProcessorPtr(new LuaScriptProcessor()), mEventPublisher, mReplicationContext);
-
-        // Publish the LocatorRegistry interface.
-        mAdapter->add(mEndpointRegistry, mCommunicator->stringToIdentity(RegistryLocatorObjectId));
+        mEndpointRegistry = new EndpointRegistry(ScriptProcessorPtr(new LuaScriptProcessor()), mEventPublisher, mReplicationContext);
+        mEndpointRegistryPrx = LocatorRegistryPrx::uncheckedCast(
+            mServiceAdapter->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");
@@ -575,7 +639,7 @@ void BasicRoutingServiceApp::initialize()
         }
 
         // Create the session context needed to construct operations.
-        mSessionContext = SessionContextPtr(new SessionContext(mAdapter, 
+        mSessionContext = SessionContextPtr(new SessionContext(mServiceAdapter, 
                                                              mEndpointRegistry, 
                                                              mEventPublisher, 
                                                              mWorkQueue,
@@ -586,24 +650,28 @@ void BasicRoutingServiceApp::initialize()
 
         // Create publish the SessionRouter interface.
         mSessionRouter = new SessionRouter(mSessionContext, mOperationReplicaCache);
-        mAdapter->add(mSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId));
+        mSessionRouterPrx = SessionRouterPrx::uncheckedCast(
+             mServiceAdapter->add(mSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId)));
 
         // Create and publish the Admin interface support.
         mAdminInteface = new RoutingAdmin(mEndpointRegistry);
-        mAdapter->add(mAdminInteface, mCommunicator->stringToIdentity(RoutingAdminObjectId));
+        mAdminPrx = RoutingServiceAdminPrx::uncheckedCast(
+            mServiceAdapter->add(mAdminInteface, mCommunicator->stringToIdentity(RoutingAdminObjectId)));
 
-        // Create and publish the ComponentService interface on it's own dedicated adapter. 
+        // Create and publish the ComponentService interface on the backplane adapter. 
         mComponentService = new ComponentServiceImpl(this);
-        mComponentServiceAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId));
+        mComponentServicePrx = ComponentServicePrx::uncheckedCast(
+            mBackplaneAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId)));
 
-        // Create and publish our Replica interface support. This interface allows this component
+        // Create and publish our Replica interface on the management adapter. This interface allows this component
         // to be activated or placed in standby mode. 
-        mReplicaManagement = new ReplicaManagement(this, mAdapter);
-        mAdapter->add(mReplicaManagement, mCommunicator->stringToIdentity(ReplicaServiceId));
+        mReplicaControl = new ReplicaControl(this, mBackplaneAdapter);
+        mReplicaPrx = ReplicaPrx::uncheckedCast(
+            mBackplaneAdapter->add(mReplicaControl, mCommunicator->stringToIdentity(ReplicaServiceId)));
 
-        // Create and publish our state replicator listener interface.
+        // Create and publish our state replicator listener interface on the backplane adapter. 
         mReplicatorListener = new RoutingStateReplicatorListenerImpl(mEndpointRegistry, mOperationReplicaCache);
-        RoutingStateReplicatorListenerPrx replicatorListener = RoutingStateReplicatorListenerPrx::uncheckedCast(mAdapter->addWithUUID(mReplicatorListener));
+        RoutingStateReplicatorListenerPrx replicatorListener = RoutingStateReplicatorListenerPrx::uncheckedCast(mBackplaneAdapter->addWithUUID(mReplicatorListener));
         mReplicatorListenerProxy = RoutingStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
 
         if (active)
@@ -615,8 +683,8 @@ void BasicRoutingServiceApp::initialize()
             onStandby();
         }
 
-        mAdapter->activate();
-        mComponentServiceAdapter->activate();
+        mServiceAdapter->activate();
+        mBackplaneAdapter->activate();
 
         // Get a proxy to the management interface for the Service Locator manager.
         // This isso we can add ourselves into the system discovery mechanisms.
@@ -654,8 +722,8 @@ void BasicRoutingServiceApp::start(const string& name, const ::Ice::Communicator
     }
     else
     {
-        mAdapter->activate();
-        mComponentServiceAdapter->activate();
+        mServiceAdapter->activate();
+        mBackplaneAdapter->activate();
     }
 
     // Plug into the Asterisk SCF discovery system so that the interfaces we provide
@@ -679,12 +747,11 @@ void BasicRoutingServiceApp::resume()
         // If we're in standby by mode, listen for state replication.
        listenToStateReplicator();
 
-        // Plug back into the Asterisk SCF discovery system so that the interfaces we provide
-        // can be located.
-        registerWithServiceLocator(false);
+        // Reactivate the service adapter. 
+        mServiceAdapter->activate();
 
-        // Reactivate the primary adapter. 
-        mAdapter->activate();
+        // Re-enable lookups of our interfaces in the ServiceLocator. 
+        unsuspendRegisteredServants(false);
     }
 
     mRunning = true;
@@ -697,15 +764,20 @@ void BasicRoutingServiceApp::suspendService(bool shuttingDown)
 {
     if (mRunning)
     {
-        // Deregister our servants.
-        deregisterFromServiceLocator(shuttingDown);
+        // Suspend lookups of our interfaces in the ServiceLocator. If shutting down,
+        // we'll be deregestering our interfaces with the ServiceLocator,
+        // so don't waste the bandwidth. 
+        if (!shuttingDown)
+        {
+            suspendRegisteredServants(false);
+        }
 
         // Remove our interfaces from the state replicator.
         stopListeningToStateReplicator();
 
-        // Deactive the primary adapter. 
+        // Deactive the service adapter. 
         // The adapter that services the ComponentService stays active. 
-        mAdapter->deactivate();
+        mServiceAdapter->deactivate();
     }
 
     mRunning = false;
@@ -732,12 +804,11 @@ void BasicRoutingServiceApp::stop()
 
     suspendService(true);
 
-    // Just in case we were in suspend() mode when told to stop.
-    mComponentServiceManagement->unregister();
+    deregisterFromServiceLocator(true);
 
-    // Turn off our ComponentService interface. 
+    // Turn off our management interface. 
     // Only a start() directly from IceBox can restart us now. 
-    mComponentServiceAdapter->deactivate();
+    mBackplaneAdapter->deactivate();
 
     lg(Info) << "Stopped.";
 }
diff --git a/src/BasicRoutingStateReplicatorApp.cpp b/src/BasicRoutingStateReplicatorApp.cpp
index 7da31d9..22fdab0 100644
--- a/src/BasicRoutingStateReplicatorApp.cpp
+++ b/src/BasicRoutingStateReplicatorApp.cpp
@@ -79,14 +79,17 @@ private:
 
     bool mRunning;
     bool mInitialized;
-    ::Ice::ObjectAdapterPtr mAdapter;
-    ::Ice::ObjectAdapterPtr mComponentServiceAdapter;
+    ::Ice::ObjectAdapterPtr mServiceAdapter;
+    ::Ice::ObjectAdapterPtr mBackplaneAdapter;
     ::Ice::CommunicatorPtr mCommunicator;
     ServiceLocatorManagementPrx mServiceLocatorManagement;
     Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
     Discovery::V1::ServiceManagementPrx mStateReplicationManagement;
     ConfiguredIceLoggerPtr mIceLogger;
     AsteriskSCF::BasicRoutingService::RoutingStateReplicatorIPtr mStateReplicator;
+
+    ComponentServicePrx mComponentServicePrx;
+    RoutingStateReplicatorPrx mStateReplicatorPrx;
 };
 typedef ::IceUtil::Handle<BasicRoutingStateReplicatorService> BasicRoutingStateReplicatorServicePtr;
 
@@ -161,28 +164,22 @@ void BasicRoutingStateReplicatorService::registerWithServiceLocator()
 {
     try
     {
-        // Get a proxy to our ComponentService interface and add it to the Service Locator.
+        // Add our ComponentService interface and add it to the Service Locator.
         // Note that this interface has its own adapter.
-        Ice::ObjectPrx componentServiceObjectPrx = mComponentServiceAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
-        ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-
         string componentServiceGuid(AsteriskSCF::BasicRoutingService::V1::StateReplicatorComponentCategory);
-        mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
+        mComponentServiceManagement = mServiceLocatorManagement->addService(mComponentServicePrx, componentServiceGuid);
         setCategory(mComponentServiceManagement,  AsteriskSCF::BasicRoutingService::V1::StateReplicatorComponentCategory);
 
-        // Get a proxy to our Replicator interface and add it to the Service Locator.
-        Ice::ObjectPrx stateReplicatorObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(ServiceDiscoveryId));
-        RoutingStateReplicatorPrx stateReplicatorPrx = RoutingStateReplicatorPrx::checkedCast(stateReplicatorObjectPrx);
-
+        // Add our Replicator interface and add it to the Service Locator.
         string stateReplicationGuid(AsteriskSCF::BasicRoutingService::V1::StateReplicatorDiscoveryCategory);
-        mStateReplicationManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(stateReplicatorPrx, stateReplicationGuid));
+        mStateReplicationManagement = mServiceLocatorManagement->addService(mStateReplicatorPrx, stateReplicationGuid);
 
         ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams();
         discoveryParams->category = AsteriskSCF::BasicRoutingService::V1::StateReplicatorDiscoveryCategory;
 
         string replicatorName = mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".InstanceName", "default");
         ServiceLocatorParamsComparePrx compareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
-                                                    mAdapter->addWithUUID(new BasicRoutingStateReplicatorCompare(replicatorName)));
+                                                    mServiceAdapter->addWithUUID(new BasicRoutingStateReplicatorCompare(replicatorName)));
 
         string compareGuid = IceUtil::generateUUID();
         mServiceLocatorManagement->addCompare(compareGuid, compareProxy);
@@ -200,17 +197,17 @@ void BasicRoutingStateReplicatorService::registerWithServiceLocator()
  * This is done at shutdown, and whenever we want to keep other services from locating
  * our interfaces.
  *
- * @param includeComponentService If true, deregisters our ComponentService interface
+ * @param includeBackplane If true, deregisters our backplane interfaces
  * in addition to all our other interfaces, making this component unreachable from the 
  * rest of Asterisk SCF. Should only be done during shutdown.
  */
-void BasicRoutingStateReplicatorService::deregisterFromServiceLocator(bool includeComponentService)
+void BasicRoutingStateReplicatorService::deregisterFromServiceLocator(bool includeBackplane)
 {
     try
     {
         mStateReplicationManagement->unregister();
 
-        if (includeComponentService)
+        if (includeBackplane)
         {
             mComponentServiceManagement->unregister();
         }
@@ -226,27 +223,29 @@ void BasicRoutingStateReplicatorService::initialize(const std::string& appName)
     mAppName = appName;
 
     // This is the primary adapter for this component.
-    mAdapter = mCommunicator->createObjectAdapter(mAppName);
+    mServiceAdapter = mCommunicator->createObjectAdapter(mAppName);
 
     // Create a separate adapter just for the component service. This is 
     // to make it easy to deactivate all of our interfaces other than the
     // component service to support suspend()/resume().
-    mComponentServiceAdapter = mCommunicator->createObjectAdapter(mAppName + ".ComponentService");
+    mBackplaneAdapter = mCommunicator->createObjectAdapter(mAppName + ".Backplane");
 
     // setup logging client
-    mIceLogger = createIceLogger(mAdapter);
+    mIceLogger = createIceLogger(mServiceAdapter);
     getLoggerFactory().setLogOutput(mIceLogger->getLogger());
 
     // Create and publish our ComponentService interface support on its own adapter.
-    mComponentServiceAdapter->add(new ComponentServiceImpl(this), mCommunicator->stringToIdentity(ComponentServiceId));
+    mComponentServicePrx = ComponentServicePrx::uncheckedCast(
+        mBackplaneAdapter->add(new ComponentServiceImpl(this), mCommunicator->stringToIdentity(ComponentServiceId)));
 
     // Create our instance of the StateReplicator template. 
     mStateReplicator = new RoutingStateReplicatorI();
-    mAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId));
+    mStateReplicatorPrx = RoutingStateReplicatorPrx::uncheckedCast(
+        mServiceAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId)));
 
     // Activate our adapters.
-    mAdapter->activate();
-    mComponentServiceAdapter->activate();
+    mServiceAdapter->activate();
+    mBackplaneAdapter->activate();
 
     // Get a proxy to the management interface for the Service Locator, so we can add 
     // ourselves into the system discovery mechanisms.
@@ -270,8 +269,8 @@ void BasicRoutingStateReplicatorService::start(const string &name, const Ice::Co
     }
     else
     {
-        mAdapter->activate();
-        mComponentServiceAdapter->activate();
+        mServiceAdapter->activate();
+        mBackplaneAdapter->activate();
     }
 
     // Plug into the Asterisk SCF discovery system so that the interfaces we provide
@@ -285,14 +284,14 @@ void BasicRoutingStateReplicatorService::resume()
 {
     if (!mRunning)
     {
-        mAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId));
+        mServiceAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId));
 
         // Plug back into the Asterisk SCF discovery system so that the interfaces we provide
         // can be located.
         registerWithServiceLocator();
 
         // Reactivate the primary adapter. 
-        mAdapter->activate();
+        mServiceAdapter->activate();
     }
 
     mRunning = true;
@@ -310,7 +309,7 @@ void BasicRoutingStateReplicatorService::suspendService(bool shuttingDown)
 
         // Deactive the primary adapter. 
         // The adapter that services the ComponentService stays active. 
-        mAdapter->deactivate();
+        mServiceAdapter->deactivate();
     }
 
     mRunning = false;
@@ -342,7 +341,7 @@ void BasicRoutingStateReplicatorService::stop()
 
     // Turn off our ComponentService interface. 
     // Only a start() directly from IceBox can restart us now. 
-    mComponentServiceAdapter->deactivate();
+    mBackplaneAdapter->deactivate();
 
     lg(Info) << "Stopped.";
 }
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 2dab880..edc04e3 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -152,6 +152,10 @@ struct GlobalIceFixture
                 throw "Invalid Replica";
             }
 
+            // Note: This would be done by Pacemaker-initiated script in the real system. Something
+            // external must activate one of the sevice instances. 
+            SharedTestData::instance.serviceReplicaMgmt->activate();
+
             // Get a ref to the Replica interface and cache it for testing.
             Ice::ObjectPrx replicaObj2 = SharedTestData::instance.communicatorOut->propertyToProxy("BackupReplica.Proxy");
             SharedTestData::instance.backupServiceReplicaMgmt = ReplicaPrx::checkedCast(replicaObj2);
@@ -843,6 +847,10 @@ BOOST_FIXTURE_TEST_CASE(FailoverConnectBridgedSessWithDest, PerTestFixture)
         SharedTestData::instance.mBridgeConnected = false;
         SharedTestData::instance.mSessionReplaced = false;
 
+        // Give the state replicator time to push the state transitions of the replicated 
+        // operation to the standby component. 
+        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
+
         // Switch standby component to active. 
         SharedTestData::instance.serviceReplicaMgmt->activate();
         BOOST_CHECK(SharedTestData::instance.serviceReplicaMgmt->isActive() == true);

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


-- 
asterisk-scf/release/routing.git



More information about the asterisk-scf-commits mailing list