[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "basecomponent" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jul 12 09:29:47 CDT 2011


branch "basecomponent" has been created
        at  1fc7ab7d9ac7ceb14de49f1f9c19b8d74d68286b (commit)

- Log -----------------------------------------------------------------
commit 1fc7ab7d9ac7ceb14de49f1f9c19b8d74d68286b
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jul 12 09:29:23 2011 -0500

    Routing service using base Component class.

diff --git a/config/routingtest.conf b/config/routingtest.conf
index a7fb9d0..fd4bfde 100644
--- a/config/routingtest.conf
+++ b/config/routingtest.conf
@@ -46,7 +46,7 @@ RoutingService.ThreadPool.Size=8
 RoutingService.ThreadPool.SizeMax=14
 RoutingService.ThreadPool.SizeWarn=9
 RoutingService.Standby=no
-RoutingService.StateReplicatorName=Replicator
+RoutingService.StateReplicatorId=Replicator
 RoutingService.ComponentTest=yes
 
 RoutingService2.Endpoints=tcp -p 10052
@@ -55,7 +55,7 @@ RoutingService2.ThreadPool.Size=8
 RoutingService2.ThreadPool.SizeMax=14
 RoutingService2.ThreadPool.SizeWarn=9
 RoutingService2.Standby=yes
-RoutingService2.StateReplicatorName=Replicator
+RoutingService2.StateReplicatorId=Replicator
 
 Replicator.InstanceName=Replicator
 Replicator.Endpoints=default -p 10054
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index e5c336f..9ccfef2 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -29,6 +29,7 @@
 #include <AsteriskSCF/Logger/IceLogger.h>
 #include <AsteriskSCF/logger.h>
 
+#include <AsteriskSCF/Component/Component.h>
 #include "AsteriskSCF/Threading/SimpleWorkQueue.h"
 #include "RoutingStateReplicatorListener.h"
 #include "LuaScriptProcessor.h"
@@ -37,8 +38,7 @@
 #include "RoutingAdmin.h"
 #include "SessionRouter.h"
 #include "OperationReplicaCache.h"
-#include "ReplicationContext.h"
-#include "TestContext.h"
+#include "RoutingReplicationContext.h"
 
 using namespace std;
 using namespace AsteriskSCF::SessionCommunications::V1;
@@ -48,6 +48,9 @@ using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::BasicRoutingService::V1;
+
+using namespace AsteriskSCF::Component;
+using namespace AsteriskSCF::Replication;
 using namespace AsteriskSCF::Discovery;
 
 namespace
@@ -61,73 +64,44 @@ namespace AsteriskSCF
 namespace BasicRoutingService
 {
 
-class ComponentServiceImpl;
-typedef ::IceUtil::Handle<ComponentServiceImpl> ComponentServiceImplPtr;
-
-class ReplicaControl;
-typedef ::IceUtil::Handle<ReplicaControl> ReplicaControlPtr;
-
-class BasicRoutingServiceApp : public IceBox::Service
+class BasicRoutingServiceApp : public Component
 {
 public:
     BasicRoutingServiceApp() 
-        : mImplementationId("BasicRoutingService"),
-          mDone(false), 
-          mInitialized(false), 
-          mRunning(false),
-          mPublishTestInterface(false),
+        : AsteriskSCF::Component::Component(lg, 
+                                      "BasicRoutingService"),
           mSessionContext(new SessionContext()),
           mWorkQueue( new AsteriskSCF::Threading::SimpleWorkQueue("SessionRouterWorkQueue")),
           mListeningToReplicator(false)
     {
     }
 
-    void resume();
-    void suspend();
-
-    void activated();
-    void onStandby();
-    bool isActive();
-
-    ////// Overrides of IceBox::Service
-
-    virtual void start(const string& name, const ::Ice::CommunicatorPtr& ic, const ::Ice::StringSeq& args);
-    virtual void stop();
-
 private:
-    void suspendService(bool shuttingDown);
-    void initialize();
+    // Required Component overrides
+    virtual void createPrimaryServices();
+    virtual void registerPrimaryServices();
+    virtual void createReplicationStateListeners();
+    virtual void stopListeningToStateReplicators();
+    virtual void listenToStateReplicators();
+    virtual void findRemoteServices();
+
+    // Other overrides
+    virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
+
+    LocatorRegistrationWrapperPtr registerService(const Ice::ObjectPrx& proxy, 
+                 const string& category,
+                 const string& service,
+                 const string& id = "");
+
     void locateBridgeManager();
     void locateStateReplicator();
-    void registerWithServiceLocator(bool includeBackplaneServices);
-    void deregisterFromServiceLocator(bool includeBackplaneServices);
-    void suspendRegisteredServants(bool includeBackplaneServices);
-    void unsuspendRegisteredServants(bool includeBackplaneServices);
-
-    void listenToStateReplicator();
-    void stopListeningToStateReplicator();
-
-    /**
-     * Get an impementation-specific ID for createing service discovery guids. 
-     * This is not the same as the app name, which is configurable. 
-     */
-    const std::string mImplementationId; 
-    bool mDone;
-    bool mInitialized;
-    bool mRunning;
-    bool mPublishTestInterface;
+
     SessionContextPtr mSessionContext;
     boost::shared_ptr<AsteriskSCF::Threading::SimpleWorkQueue> mWorkQueue;
 
-    std::string mAppName;
-    ServiceLocatorManagementPrx mServiceLocatorManagement;
-    ServiceLocatorPrx mServiceLocator;
-
-    ServiceManagementPrx mRegistryLocatorManagement;
-    ServiceManagementPrx mAdminManagement;
-    ServiceManagementPrx mComponentServiceManagement;
-    ServiceManagementPrx mReplicaManagement;
-    ServiceManagementPrx mSessionRouterManagement;
+    LocatorRegistrationWrapperPtr mAdminRegistration;
+    LocatorRegistrationWrapperPtr mRegistryLocatorRegistration;
+    LocatorRegistrationWrapperPtr mSessionRouterRegistration;
 
     // Our published interfaces.
     BasicSessionRouterPtr mSessionRouter;
@@ -136,36 +110,21 @@ private:
     RoutingServiceAdminPtr mAdminInteface;
     RoutingServiceAdminPrx mAdminPrx;
 
-    ComponentServiceImplPtr mComponentService;
-    ComponentServicePrx mComponentServicePrx;
-
-    ComponentTestPtr mComponentTest;
-    ComponentTestPrx mComponentTestPrx;
+    EndpointRegistryPtr mEndpointRegistry;
+    LocatorRegistryPrx mEndpointRegistryPrx;
 
+    // Remote services
     AsteriskSCF::Discovery::SmartProxy<BridgeManagerPrx> mBridgeManager;
+
+    // Support objects.
     RoutingServiceEventPublisherPtr mEventPublisher;
     boost::shared_ptr<OperationReplicaCache> mOperationReplicaCache;
 
-    EndpointRegistryPtr mEndpointRegistry;
-    LocatorRegistryPrx mEndpointRegistryPrx;
-
     // Replication support
-    ReplicationContextPtr mReplicationContext;
-    ReplicaPrx mReplicaPrx;
-
-    ReplicaControlPtr mReplicaControl;
     AsteriskSCF::Discovery::SmartProxy<RoutingStateReplicatorPrx> mStateReplicator;
     RoutingStateReplicatorListenerPtr mReplicatorListener;
-
     RoutingStateReplicatorListenerPrx mReplicatorListenerProxy;
     bool mListeningToReplicator;
-
-    // Implementation
-    ::Ice::ObjectAdapterPtr mServiceAdapter;
-    ::Ice::ObjectAdapterPtr mBackplaneAdapter;
-
-    ::Ice::CommunicatorPtr mCommunicator;
-
     boost::shared_mutex mReplicatorLock;
 };
 typedef ::IceUtil::Handle<BasicRoutingServiceApp> BasicRoutingServiceAppPtr;
@@ -176,176 +135,18 @@ static const string ComponentServiceId("BasicRoutingComponent");
 static const string SessionRouterObjectId("SessionRouter");
 static const string ReplicaServiceId("BasicRoutingServiceReplica");
 
-/**
- * This class provides implementation for the ComponentService interface.
- * Every Asterisk SCF component is expected to expose the ComponentService interface.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
-    ComponentServiceImpl(BasicRoutingServiceApp* app) :
-        mApp(app)
-    {
-    }
-
-public: // Overrides of the ComponentService interface.
-    void suspend(const ::Ice::Current&)
-    {
-        mApp->suspend();
-    }
-
-    void resume(const ::Ice::Current&)
-    {
-        mApp->resume();
-    }
-
-    void shutdown(const ::Ice::Current&)
-    {
-        mApp->stop();
-    }
-
-    void shutdownNotice()
-    {
-        mApp = 0;
-    }
-
-private:
-    BasicRoutingServiceAppPtr mApp;
-};
-
-/** 
- * This interface is published as a facet of the Component Service interface.
- * It exists to allow more elaborate interaction with a component during testing.
- */
-class ComponentTestImpl : public ComponentTest
-{
-public:
-    ComponentTestImpl(const TestContextPtr& testContext) :
-        mTestContext(testContext)
-    {
-    }
-
-    void setTestMode(const ::std::string& mode, const ::Ice::Current&)
-    {
-        mTestContext->setTestMode(mode);
-    }
-
-    void setTestModeWithArgs(const ::std::string& mode, 
-                             const ComponentTestParamSeq&, 
-                             const ::Ice::Current&)
-    {
-        mTestContext->setTestMode(mode);
-    }
-
-    void clearTestMode(const string&, const ::Ice::Current&)
-    {
-       mTestContext->clearTestMode();
-    }
-
-    void clearTestModes(const ::Ice::Current&)
-    {
-        mTestContext->clearTestMode();
-    }
-
-private:
-    TestContextPtr mTestContext;
-};
-
-/**
- * This class provides implementation for this component's Replica management interface.
- */
-class ReplicaControl : public Replica
-{
-public:
-    /**
-     * Constructor. 
-     *  @param app 
-     *  @param adapter The adapter is assumed to have been activated. 
-     */
-    ReplicaControl(BasicRoutingServiceApp* app, ::Ice::ObjectAdapterPtr adapter) : mApp(app), mAdapter(adapter)
-    { 
-    }
-
-    bool isActive(const ::Ice::Current&)
-    {
-        return mApp->isActive();
-    }
-
-    bool activate(const ::Ice::Current&)
-    {
-        mApp->activated();
-
-        for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); listener != mListeners.end(); ++listener)
-        {
-            (*listener)->activated(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
-        }
-
-        return true;
-    }
-
-    void standby(const ::Ice::Current&)
-    {
-        mApp->onStandby();
-
-        for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); 
-             listener != mListeners.end(); ++listener)
-        {
-            (*listener)->onStandby(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
-        }
-    }
-
-    void addListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const ::Ice::Current&)
-    {
-        mListeners.push_back(listener);
-    }
-
-    void removeListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const ::Ice::Current&)
-    {
-        mListeners.erase(std::remove(mListeners.begin(), mListeners.end(), listener), mListeners.end());
-    }
-
-private:
-    BasicRoutingServiceAppPtr mApp;
-
-    /**
-     * Pointer to the object adapter we exist on.
-     */
-    ::Ice::ObjectAdapterPtr mAdapter;
-
-    /**
-     * Listeners that we need to push state change notifications out to.
-     */
-    vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx> mListeners;
-};
-
-bool BasicRoutingServiceApp::isActive()
-{
-    // The Replication Context is tracking our current status. 
-    return mReplicationContext->isComponentActive();
-}
-
-void BasicRoutingServiceApp::activated()
-{
-    mReplicationContext->setComponentActive();
-    stopListeningToStateReplicator();
-}
-
-void BasicRoutingServiceApp::onStandby()
-{
-    mReplicationContext->setComponentStandby();
-    listenToStateReplicator();
-}
-
 /** 
  * Register as a listener to our state replicator. 
  * A component in standby mode will do this to monitor state changes
  * being sent from an active component. 
  */
-void BasicRoutingServiceApp::listenToStateReplicator()
+void BasicRoutingServiceApp::listenToStateReplicators()
 {
     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock); 
+    RoutingReplicationContextPtr routingReplicationContext = 
+        static_pointer_cast<RoutingReplicationContext>(getReplicationContext());
 
-    if ((mReplicationContext->getReplicatorService() == 0) || (mListeningToReplicator == true))
+    if ((!routingReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == true))
     {
         return;
     }
@@ -353,10 +154,10 @@ void BasicRoutingServiceApp::listenToStateReplicator()
     try
     {
         // Are we in standby mode?
-        if (mReplicationContext->isComponentActive() == false)
+        if (routingReplicationContext->getState() == ACTIVE_IN_REPLICA_GROUP)
         {
             AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx oneWayStateReplicator = 
-                  AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx::uncheckedCast(mReplicationContext->getReplicatorService()->ice_oneway());
+                 RoutingStateReplicatorPrx::uncheckedCast(routingReplicationContext->getReplicator()->ice_oneway());
 
             oneWayStateReplicator->addListener(mReplicatorListenerProxy);
             mListeningToReplicator = true;
@@ -374,11 +175,13 @@ void BasicRoutingServiceApp::listenToStateReplicator()
  * A component in active mode doesn't neeed to listen to
  * state replication data. 
  */
-void BasicRoutingServiceApp::stopListeningToStateReplicator()
+void BasicRoutingServiceApp::stopListeningToStateReplicators()
 {
     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock); 
+    RoutingReplicationContextPtr routingReplicationContext = 
+        static_pointer_cast<RoutingReplicationContext>(getReplicationContext());
 
-    if ((mReplicationContext->getReplicatorService() == 0) || (mListeningToReplicator == false))
+    if ((!routingReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
     {
         return;
     }
@@ -386,10 +189,9 @@ void BasicRoutingServiceApp::stopListeningToStateReplicator()
     try
     {
         AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx oneWayStateReplicator = 
-                AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx::uncheckedCast(mReplicationContext->getReplicatorService()->ice_oneway());
+                AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx::uncheckedCast(routingReplicationContext->getReplicator()->ice_oneway());
 
         oneWayStateReplicator->removeListener(mReplicatorListenerProxy);
-
         mListeningToReplicator = false;
     }
     catch (const Ice::Exception& e)
@@ -400,20 +202,26 @@ void BasicRoutingServiceApp::stopListeningToStateReplicator()
 }
 
 /**
- * Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
- * other components can look up our interfaces.
+ * Helper function to wrap a service in a registration wrapper.
  */
-void setCategory(const AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx& serviceManagement, 
+LocatorRegistrationWrapperPtr BasicRoutingServiceApp::registerService(const Ice::ObjectPrx& proxy, 
                  const string& category,
                  const string& service,
-                 const string& id = "")
+                 const string& id)
 {
-    // Add category as a parameter to enable other components look this component up.
-    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams;
-    genericparams->category = category;
-    genericparams->service = service;
-    genericparams->id = id;
-    serviceManagement->addLocatorParams(genericparams, "");
+    string guid = getName() + "." + category;
+
+    // Configure how other components look this component up.
+    ServiceLocatorParamsPtr params = new ServiceLocatorParams;
+    params->category = category;
+    params->service = service;
+    params->id = getName();
+
+    LocatorRegistrationWrapperPtr wrapper = 
+            new LocatorRegistrationWrapper(getCommunicator(), getServiceLocatorManagementProperty(), proxy, 
+                guid, params);
+
+    return wrapper;
 }
 
 /**
@@ -423,154 +231,57 @@ void setCategory(const AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx& s
  * @param includeBackplaneServices If true, registers our management interfaces
  * in addition to all our other interfaces. 
  */
-void BasicRoutingServiceApp::registerWithServiceLocator(bool includeBackplaneServices)
+void BasicRoutingServiceApp::registerPrimaryServices()
 {
     try
     {
-       std::string serviceName = mCommunicator->getProperties()->getPropertyWithDefault(
-          mAppName + ".Service", "default");
+        std::string serviceName = getCommunicator()->getProperties()->getPropertyWithDefault(
+            getName() + ".Service", "default");
 
         // Register our RoutingAdmin interface with the Service Locator.
-        string adminServiceGuid(mImplementationId + "." + Routing::V1::RoutingServiceAdminDiscoveryCategory); // Should be unique for reporting.
-        mAdminManagement = mServiceLocatorManagement->addService(mAdminPrx, adminServiceGuid);
-        setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory, serviceName);
+        mAdminRegistration = registerService(mAdminPrx, 
+                                             Routing::V1::RoutingServiceAdminDiscoveryCategory, 
+                                             serviceName, 
+                                             getName());
+        bool registered =  registerPrimaryService(mAdminRegistration);
+
 
         // Register our RegistryLocator interface with the Service Locator.
-        string locatorServiceGuid(mImplementationId + "." + Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);  // Should be unique for reporting.
-        mRegistryLocatorManagement = mServiceLocatorManagement->addService(mEndpointRegistryPrx, locatorServiceGuid);
-        setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory, serviceName);
+        mRegistryLocatorRegistration = registerService(mEndpointRegistryPrx,
+                                                       Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory,
+                                                       serviceName,
+                                                       getName());
+        registered =  registerPrimaryService(mRegistryLocatorRegistration);
+                      
 
         // Register the SessionRouter interface with the Service Locator.
-        string sessionRouterGuid(mImplementationId + "." + Routing::V1::SessionRouterDiscoveryCategory);   // Should be unique
-        mSessionRouterManagement = mServiceLocatorManagement->addService(mSessionRouterPrx, sessionRouterGuid);
-        setCategory(mSessionRouterManagement, Routing::V1::SessionRouterDiscoveryCategory, serviceName);
-
-        if (includeBackplaneServices)
-        {
-            // Register the ComponentService interface with the Service Locator.
-            // Note that this interface goes on the management adapter.
-            string componentServiceGuid(mImplementationId + "." + Routing::V1::ComponentServiceDiscoveryCategory);   // Should be unique for reporting.
-            mComponentServiceManagement = mServiceLocatorManagement->addService(mComponentServicePrx, componentServiceGuid);
-            setCategory(mComponentServiceManagement, ComponentServiceId, serviceName, mImplementationId); 
-
-            if (mPublishTestInterface)
-            {
-                // Register our test servant as a facet of the ComponentService interface.
-                mComponentTestPrx = ComponentTestPrx::uncheckedCast(
-                    mBackplaneAdapter->addFacet(mComponentTest, 
-                                                mComponentServicePrx->ice_getIdentity(), 
-                                                AsteriskSCF::System::Component::V1::ComponentTestFacet));
-            }
-
-            // Register the Replica interface with the Service Locator.
-            mReplicaManagement = mServiceLocatorManagement->addService(mReplicaPrx, mImplementationId + ".Replica");
-            setCategory(mReplicaManagement, ReplicaServiceId, serviceName, mImplementationId + ".Replica");  
-        }
+        mSessionRouterRegistration = registerService(mSessionRouterPrx,
+                                                     Routing::V1::SessionRouterDiscoveryCategory,
+                                                     serviceName,
+                                                     getName());
+        registered = registerPrimaryService(mSessionRouterRegistration);
     }
     catch(const std::exception& e)
     {
-        lg(Error) << "Unable to publish component interfaces in " << mAppName << BOOST_CURRENT_FUNCTION << ". Exception: " << e.what();
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION << 
+            ". Exception: " << e.what();
         throw; // rethrow
     }
 }
 
 /**
- * Deregister this component's interfaces from the Service Locator.
- *
- * @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. 
- */
-void BasicRoutingServiceApp::deregisterFromServiceLocator(bool includeBackplaneServices)
-{
-    try
-    {
-        mRegistryLocatorManagement->unregister();
-        mAdminManagement->unregister();
-        mSessionRouterManagement->unregister();
-
-        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(const std::exception& e)
-    {
-        lg(Error) << BOOST_CURRENT_FUNCTION << e.what();
-    }
-}
-
-/**
  * Locate the BridgeManager using the Service Locator.
  */
 void BasicRoutingServiceApp::locateBridgeManager()
 {
     try
     {
-       std::string serviceName = mCommunicator->getProperties()->getPropertyWithDefault(
-          mAppName + ".BridgeServiceName", "default");
+       std::string serviceName = getCommunicator()->getProperties()->getPropertyWithDefault(
+          getName() + ".BridgeServiceName", "default");
 
         mBridgeManager = AsteriskSCF::Discovery::SmartProxy<BridgeManagerPrx>(
-            mServiceLocator,
-            new ServiceLocatorParams(BridgeServiceDiscoveryCategory, serviceName, ""),
+            getServiceLocator(),
+            new ServiceLocatorParams(BridgeManagerDiscoveryCategory, serviceName, ""),
             lg);
     }
     catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
@@ -586,245 +297,106 @@ void BasicRoutingServiceApp::locateBridgeManager()
  */
 void BasicRoutingServiceApp::locateStateReplicator()
 {
-    std::string serviceName = mCommunicator->getProperties()->getPropertyWithDefault(
-          mAppName + ".ReplicatorServiceName", "default");
+    if (getReplicationContext()->getState() == ACTIVE_STANDALONE)
+    {
+        return;
+    }
 
     ServiceLocatorParamsPtr replicatorParams = new ServiceLocatorParams;
     replicatorParams->category = BasicRoutingService::V1::StateReplicatorDiscoveryCategory;    
-    replicatorParams->service = serviceName;
-    replicatorParams->id = mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".StateReplicatorName", "default");
+    replicatorParams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
+          getName() + ".StateReplicatorService", "default");
+    replicatorParams->id = getCommunicator()->getProperties()->getPropertyWithDefault(
+         getName() + ".StateReplicatorId", "default");
 
     try
     {
-        AsteriskSCF::Discovery::SmartProxy<RoutingStateReplicatorPrx> replicator(mServiceLocator, replicatorParams, lg);
-        mReplicationContext->setReplicatorService(replicator);
+        RoutingReplicationContextPtr routingReplicationContext = 
+            static_pointer_cast<RoutingReplicationContext>(getReplicationContext());
+
+        ReplicatorSmartPrx replicator(getServiceLocator(), replicatorParams, lg);
+        routingReplicationContext->setReplicator(replicator);
     }
     catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
     {
-        lg(Error) << "StateReplicator not found. Check configuration.";
+        lg(Error) << getName() << ": StateReplicator not found. Check configuration.";
         throw;
     }
 }
 
 /**
- * Create the primary functional objects of this component.
- *   @param appName Name of the application or component.
+ * Override of factory method to create our replication context. 
  */
-void BasicRoutingServiceApp::initialize()
+ReplicationContextPtr BasicRoutingServiceApp::createReplicationContext(ReplicationStateType state)
+{
+    RoutingReplicationContextPtr context(new RoutingReplicationContext(state));
+    return context;
+}
+
+void BasicRoutingServiceApp::createPrimaryServices()
 {
     try
     {
-        // Create the adapter that our functional services are published on.
-        mServiceAdapter = mCommunicator->createObjectAdapter(mAppName);
-
-        // Create an adapter that is bound to the dedicated (non-movable) address of this component. 
-        mBackplaneAdapter = mCommunicator->createObjectAdapter(mAppName + ".Backplane");
-
-        // 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");
-
-        string standbyProp = mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".Standby", "no");
-        bool active = (standbyProp == "no") || (standbyProp == "false");
+        // Get the replication context specific to routing. 
+        RoutingReplicationContextPtr routingReplicationContext = 
+            static_pointer_cast<RoutingReplicationContext>(getReplicationContext());
 
-        // Create the replication context.
-        mReplicationContext = ReplicationContextPtr(new ReplicationContext(active, standalone));
-
-        mEventPublisher = new RoutingServiceEventPublisher(mServiceAdapter);
-
-        // setup the logger
-        ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mServiceAdapter);
-        getLoggerFactory().setLogOutput(mIceLogger->getLogger());
+        // Create a helper class for publishing events. 
+        mEventPublisher = new RoutingServiceEventPublisher(getServiceAdapter());
 
         // Create and configure the EndpointRegistry.
-        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");
-
-        if (mPublishTestInterface)
-        {
-            // Create and publish the ComponentTest servant. This will be exposed
-            // as a facet of ComponentService.
-            mComponentTest = new ComponentTestImpl(mReplicationContext->getTestContext());
-        }
+        mEndpointRegistry = new EndpointRegistry(ScriptProcessorPtr(new LuaScriptProcessor()), mEventPublisher, routingReplicationContext);
+        mEndpointRegistryPrx = LocatorRegistryPrx::uncheckedCast(getServiceAdapter()->add(
+            mEndpointRegistry, getCommunicator()->stringToIdentity(RegistryLocatorObjectId)));
 
         // Create the session context needed to construct operations.
-        mSessionContext = SessionContextPtr(new SessionContext(mServiceAdapter, 
-                                                             mEndpointRegistry, 
-                                                             mEventPublisher, 
-                                                             mWorkQueue,
-                                                             mReplicationContext));
+       mSessionContext = SessionContextPtr(new SessionContext(getServiceAdapter(), 
+                                                                mEndpointRegistry, 
+                                                                mEventPublisher, 
+                                                                mWorkQueue,
+                                                                routingReplicationContext));
                 
         // Create the replica cache. 
         mOperationReplicaCache = OperationReplicaCachePtr(new OperationReplicaCache(mSessionContext));
 
-        // Create publish the SessionRouter interface.
+        // Create the SessionRouter interface.
         mSessionRouter = new SessionRouter(mSessionContext, mOperationReplicaCache);
         mSessionRouterPrx = SessionRouterPrx::uncheckedCast(
-             mServiceAdapter->add(mSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId)));
+                getServiceAdapter()->add(mSessionRouter, getCommunicator()->stringToIdentity(SessionRouterObjectId)));
 
         // Create and publish the Admin interface support.
         mAdminInteface = new RoutingAdmin(mEndpointRegistry);
         mAdminPrx = RoutingServiceAdminPrx::uncheckedCast(
-            mServiceAdapter->add(mAdminInteface, mCommunicator->stringToIdentity(RoutingAdminObjectId)));
-
-        // Create and publish the ComponentService interface on the backplane adapter. 
-        mComponentService = new ComponentServiceImpl(this);
-        mComponentServicePrx = ComponentServicePrx::uncheckedCast(
-            mBackplaneAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId)));
-
-        // Create and publish our Replica interface on the management adapter. This interface allows this component
-        // to be activated or placed in standby mode. 
-        mReplicaControl = new ReplicaControl(this, mBackplaneAdapter);
-        mReplicaPrx = ReplicaPrx::uncheckedCast(
-            mBackplaneAdapter->add(mReplicaControl, mCommunicator->stringToIdentity(ReplicaServiceId)));
-
-        // Create and publish our state replicator listener interface on the backplane adapter. 
-        mReplicatorListener = new RoutingStateReplicatorListenerImpl(mEndpointRegistry, mOperationReplicaCache);
-        RoutingStateReplicatorListenerPrx replicatorListener = RoutingStateReplicatorListenerPrx::uncheckedCast(mBackplaneAdapter->addWithUUID(mReplicatorListener));
-        mReplicatorListenerProxy = RoutingStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
-
-        if (active)
-        {
-            activated();
-        } 
-        else
-        {
-            onStandby();
-        }
-
-        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.
-        mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
-
-        // Get a proxy to the interface for the Service Locator.
-        // This is so we can find the other components we depend on.
-        mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-
-        mInitialized = true;
+            getServiceAdapter()->add(mAdminInteface, getCommunicator()->stringToIdentity(RoutingAdminObjectId)));
     }
-    catch(const ::Ice::Exception &e)
+    catch(const Ice::Exception& e)
     {
-        lg(Error) << "Problems in " << mAppName << BOOST_CURRENT_FUNCTION << e.what();
-        throw e;
-    }
-
-    locateBridgeManager();
-    locateStateReplicator();
-}
-
-/**
- * Implementation of the required IceBox::Service start method.
- */
-void BasicRoutingServiceApp::start(const string& name, const ::Ice::CommunicatorPtr& communicator, const ::Ice::StringSeq&)
-{
-    lg(Info) << "Starting...";
-
-    mCommunicator = communicator;
-    mAppName = name;
-
-    if (!mInitialized)
-    {
-        initialize();
-    }
-    else
-    {
-        mServiceAdapter->activate();
-        mBackplaneAdapter->activate();
+        lg(Error) << "Unable to create services in " << getName() << BOOST_CURRENT_FUNCTION << 
+            ". Exception: " << e.what();
+        throw;
     }
-
-    // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-    // can be located.
-    registerWithServiceLocator(true);
-    
-    // Register with the state replicator in case we are in standby mode. 
-    listenToStateReplicator();
-
-    mRunning = true;
-    lg(Info) << "Started";
 }
 
-/**
- * Things we do to resume operation after a pause().
- */
-void BasicRoutingServiceApp::resume()
+void BasicRoutingServiceApp::createReplicationStateListeners()
 {
-    if (!mRunning)
+    try
     {
-        // If we're in standby by mode, listen for state replication.
-       listenToStateReplicator();
-
-        // Reactivate the service adapter. 
-        mServiceAdapter->activate();
-
-        // Re-enable lookups of our interfaces in the ServiceLocator. 
-        unsuspendRegisteredServants(false);
+        // Create and publish our state replicator listener interface on the backplane adapter. 
+        mReplicatorListener = new RoutingStateReplicatorListenerImpl(mEndpointRegistry, mOperationReplicaCache);
+        RoutingStateReplicatorListenerPrx replicatorListener = RoutingStateReplicatorListenerPrx::uncheckedCast(getBackplaneAdapter()->addWithUUID(mReplicatorListener));
+        mReplicatorListenerProxy = RoutingStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
     }
-
-    mRunning = true;
-}
-
-/** 
- * Utility function to suspend the service for a suspend() or stop().
- */
-void BasicRoutingServiceApp::suspendService(bool shuttingDown)
-{
-    if (mRunning)
+    catch(const Ice::Exception &e)
     {
-        // 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 service adapter. 
-        // The adapter that services the ComponentService stays active. 
-        mServiceAdapter->deactivate();
+        lg(Error) << "Problems in " << getName() << " " << BOOST_CURRENT_FUNCTION << e.what();
+        throw;
     }
-
-    mRunning = false;
 }
 
-/** 
- * Handle a notice from the ComponentService. 
- */
-void BasicRoutingServiceApp::suspend()
+void BasicRoutingServiceApp::findRemoteServices() 
 {
-    lg(Info) << "Suspending...";
-
-    suspendService(false);
-
-    lg(Info) << "Suspended.";
-}
-
-/**
- * Implementation of the required IceBox::Service stop method.
- */
-void BasicRoutingServiceApp::stop()
-{
-    lg(Info) << "Stopping...";
-
-    suspendService(true);
-
-    deregisterFromServiceLocator(true);
-
-    // Turn off our management interface. 
-    // Only a start() directly from IceBox can restart us now. 
-    mBackplaneAdapter->deactivate();
-
-    lg(Info) << "Stopped.";
+    locateBridgeManager();
+    locateStateReplicator();
 }
 
 } // end BasicRoutingService
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 53674ea..2a1c1af 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -34,10 +34,7 @@ asterisk_scf_component_add_file(BasicRoutingService SessionListener.h)
 asterisk_scf_component_add_file(BasicRoutingService SessionListener.cpp)
 asterisk_scf_component_add_file(BasicRoutingService OperationReplicaCache.h)
 asterisk_scf_component_add_file(BasicRoutingService OperationReplicaCache.cpp)
-asterisk_scf_component_add_file(BasicRoutingService ReplicationContext.h)
-asterisk_scf_component_add_file(BasicRoutingService ReplicationContext.cpp)
-asterisk_scf_component_add_file(BasicRoutingService TestContext.h)
-asterisk_scf_component_add_file(BasicRoutingService TestContext.cpp)
+asterisk_scf_component_add_file(BasicRoutingService RoutingReplicationContext.h)
 asterisk_scf_component_add_file(BasicRoutingService RoutingStateReplicatorListener.h)
 asterisk_scf_component_add_file(BasicRoutingService RoutingStateReplicatorListener.cpp)
 asterisk_scf_component_add_ice_libraries(BasicRoutingService IceStorm)
@@ -47,6 +44,7 @@ target_link_libraries(BasicRoutingService ${LUA_LIBRARIES})
 target_link_libraries(BasicRoutingService logging-client)
 target_link_libraries(BasicRoutingService Threading)
 target_link_libraries(BasicRoutingService asterisk-scf-api)
+target_link_libraries(BasicRoutingService ice-util-cpp)
 asterisk_scf_component_install(BasicRoutingService)
 
 asterisk_scf_component_init(BasicRoutingStateReplicator)
diff --git a/src/ConnectBridgedSessionsWithDestinationOperation.cpp b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
index ca07b82..38fd0d3 100644
--- a/src/ConnectBridgedSessionsWithDestinationOperation.cpp
+++ b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
@@ -46,7 +46,7 @@ class ConnectBridgedSessionsWithDestReplicatingListener :
 {
 public:
     ConnectBridgedSessionsWithDestReplicatingListener(ConnectBridgedSessionsWithDestinationOperationPtr op, 
-                                                      const ReplicationContextPtr& replication)  
+                                                      const RoutingReplicationContextPtr& replication)  
                                                          : mOperationId(op->getOperationId()),
                                                            mOperation(op), 
                                                            mReplicationContext(replication)
@@ -77,7 +77,7 @@ public:
                      opStart(new ConnectBridgedSessionsWithDestinationOpStart());
                 opStart->operationId = mOperation->getOperationId();
                 opStart->key = mOperation->getOperationId() + 
-                     AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestStartKeyMod;
+                     ConnectBridgedSessionsWithDestStartKeyMod;
                 opStart->sessionToReplace = mOperation->getSessionToReplace();
                 opStart->destination = mOperation->getDestination();
 
@@ -92,7 +92,7 @@ public:
                  waitLookup(new ConnectBridgedSessionsWithDestinationOpWaitLookupState());
             waitLookup->operationId = mOperation->getOperationId();
             waitLookup->key = mOperation->getOperationId() + 
-                 AsteriskSCF::BasicRoutingService::V1::RouteSessionOpWaitLookupKeyMod;
+                 RouteSessionOpWaitLookupKeyMod;
             waitLookup->endpoints = mOperation->getLookupResult();
             waitLookup->remainingSessions = mOperation->getRemainingSessions();
 
@@ -110,7 +110,7 @@ public:
         RoutingStateItemSeq setItems;
 
         setItems.push_back(item);
-        mReplicationContext->getReplicatorService()->setState(setItems);
+        mReplicationContext->getReplicator()->setState(setItems);
         
         // Cache the replicated items.
         mReplicatedState.push_back(item);
@@ -134,7 +134,7 @@ public:
             {
                 // We just completed the entire operation. 
                 // Remove the items that represented this operation's state transitions from the state replicator.
-                mReplicationContext->getReplicatorService()->removeStateForItems(mReplicatedState);
+                mReplicationContext->getReplicator()->removeStateForItems(mReplicatedState);
             }
         }
         catch(...)
@@ -168,7 +168,7 @@ public:
                  bridgeOp(new ConnectBridgedSessionsWithDestinationOpBridgingState());
             bridgeOp->operationId = mOperation->getOperationId();
             bridgeOp->key = mOperation->getOperationId() + 
-                    AsteriskSCF::BasicRoutingService::V1::RouteSessionOpBridgingKeyMod;
+                    RouteSessionOpBridgingKeyMod;
             bridgeOp->bridge = mOperation->getBridge();
 
             pushState(bridgeOp);
@@ -185,7 +185,7 @@ private:
     RoutingStateItemSeq mReplicatedState;
     std::string mOperationId;
     ConnectBridgedSessionsWithDestinationOperationPtr mOperation;
-    ReplicationContextPtr mReplicationContext;
+    RoutingReplicationContextPtr mReplicationContext;
 
 }; // end ConnectBridgedSessionsWithDestReplicatingListener
 
@@ -210,7 +210,7 @@ void ConnectBridgedSessionsWithDestinationOperation::initStateMachine()
 ConnectBridgedSessionsWithDestinationOperation::ConnectBridgedSessionsWithDestinationOperation(
                           const AMD_SessionRouter_connectBridgedSessionsWithDestinationPtr& cb,
                           const std::string& operationId,
-                          const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionToReplace, 
+                          const SessionPrx& sessionToReplace, 
                           const ::std::string& destination, 
                           const ::Ice::Current& current,
                           const SessionContextPtr& context,
@@ -234,7 +234,7 @@ ConnectBridgedSessionsWithDestinationOperation::ConnectBridgedSessionsWithDestin
 ConnectBridgedSessionsWithDestinationOperationPtr ConnectBridgedSessionsWithDestinationOperation::create(
                           const AMD_SessionRouter_connectBridgedSessionsWithDestinationPtr& cb,
                           const std::string& operationId,
-                          const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionToReplace, 
+                          const SessionPrx& sessionToReplace, 
                           const ::std::string& destination, 
                           const ::Ice::Current& current,
                           const SessionContextPtr& context,
@@ -249,7 +249,8 @@ ConnectBridgedSessionsWithDestinationOperationPtr ConnectBridgedSessionsWithDest
                                                         context,
                                                         listener) );
 
-    boost::shared_ptr<SimpleStateMachine<ConnectBridgedSessionsWithDestinationOp::OperationState>::StateMachineListener> replicatingListener(new ConnectBridgedSessionsWithDestReplicatingListener(op, context->replicationContext));
+    boost::shared_ptr<SimpleStateMachine<ConnectBridgedSessionsWithDestinationOp::OperationState>::StateMachineListener> 
+        replicatingListener(new ConnectBridgedSessionsWithDestReplicatingListener(op, context->replicationContext));
     op->addStateMachineListener(replicatingListener);
 
     return op;
@@ -282,7 +283,8 @@ ConnectBridgedSessionsWithDestinationOperation::~ConnectBridgedSessionsWithDesti
         lg(Debug) << "ConnectBridgedSessionsWithDestinationOperation() being destroyed for " << mDestination ;
 }
 
-void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const AsteriskSCF::BasicRoutingService::V1::OperationStateItemPtr& stateItem)
+void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(
+    const OperationStateItemPtr& stateItem)
 {
     ConnectBridgedSessionsWithDestinationOpStartPtr start;
     ConnectBridgedSessionsWithDestinationOpWaitLookupStatePtr waitLookup;
@@ -302,7 +304,8 @@ void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const Asteris
     }
 }
 
-void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestinationOpStartPtr& item)
+void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(
+    const ConnectBridgedSessionsWithDestinationOpStartPtr& item)
 {
     mSessionToReplace = item->sessionToReplace;
     mDestination = item->destination;
@@ -311,13 +314,15 @@ void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const Asteris
     mReplicatedStates.push_back(ConnectBridgedSessionsWithDestinationOp::STATE_LOOKUP);
 }
 
-void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestinationOpWaitLookupStatePtr& item)
+void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(
+    const ConnectBridgedSessionsWithDestinationOpWaitLookupStatePtr& item)
 {
     mLookupResult = item->endpoints;
     mReplicatedStates.push_back(ConnectBridgedSessionsWithDestinationOp::STATE_WAIT_LOOKUP_RESULTS);
 }
 
-void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(const AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestinationOpBridgingStatePtr& item)
+void ConnectBridgedSessionsWithDestinationOperation::reflectUpdate(
+    const ConnectBridgedSessionsWithDestinationOpBridgingStatePtr& item)
 {
     mBridge = item->bridge;
 
@@ -497,7 +502,7 @@ void ConnectBridgedSessionsWithDestinationOperation::establishBridgeState()
     // Test instrumentation
     if (mSessionContext->replicationContext->getTestContext().get() != 0)
     {
-        if (mSessionContext->replicationContext->getTestContext()->getTestMode() == "ConnectBridgedSessWithDestFailover")
+        if (mSessionContext->replicationContext->getTestContext()->hasTestMode("ConnectBridgedSessWithDestFailover"))
         {
             // We're going to just shutdown this operation right here, with no replies to the caller. 
             // This is so that an external test can verify the replica can take it the rest of the way.
diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index 8756701..6c4a1c0 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -81,7 +81,7 @@ class EndpointRegistryPriv
 public:
     EndpointRegistryPriv(const ScriptProcessorPtr& scriptProcessor, 
                          const RoutingEventsPtr& eventPublisher, 
-                         const ReplicationContextPtr& replicationContext) :
+                         const RoutingReplicationContextPtr& replicationContext) :
             mScriptProcessor(scriptProcessor), 
             mEventPublisher(eventPublisher),
             mReplicationContext(replicationContext)
@@ -123,7 +123,7 @@ public:
      */
     void forwardRemoveEndpointLocator(const std::string& locatorId, Event::OperationResult result)
     {
-        if (!mReplicationContext->isComponentActive())
+        if (!mReplicationContext->isActive())
         {
             return;
         }
@@ -140,7 +140,7 @@ public:
                 addEndpointItem->key = locatorId;
                 removeItems.push_back(addEndpointItem);
 
-                mReplicationContext->getReplicatorService()->removeStateForItems(removeItems);
+                mReplicationContext->getReplicator()->removeStateForItems(removeItems);
             }
             catch(const Ice::Exception& e)
             {
@@ -160,7 +160,7 @@ public:
                                    const EndpointLocatorPrx& locator, 
                                    Event::OperationResult result)
     {
-        if (!mReplicationContext->isComponentActive())
+        if (!mReplicationContext->isActive())
         {
             return;
         }
@@ -180,7 +180,7 @@ public:
 
                 setItems.push_back(addEndpointItem);
 
-                mReplicationContext->getReplicatorService()->setState(setItems);
+                mReplicationContext->getReplicator()->setState(setItems);
             }
             catch(const Ice::Exception& e)
             {
@@ -197,7 +197,7 @@ public:
                                             const EndpointLocatorPrx& locator, 
                                             OperationResult result)
     {
-        if (!mReplicationContext->isComponentActive())
+        if (!mReplicationContext->isActive())
         {
             return;
         }
@@ -215,7 +215,7 @@ public:
                     removeItem->key = locatorId;
                     removeItems.push_back(removeItem);
 
-                    mReplicationContext->getReplicatorService()->removeStateForItems(removeItems);
+                    mReplicationContext->getReplicator()->removeStateForItems(removeItems);
 
                     // Now add the item with the new values. 
                     RoutingStateItemSeq setItems;
@@ -226,7 +226,7 @@ public:
 
                     setItems.push_back(addEndpointItem);
 
-                    mReplicationContext->getReplicatorService()->setState(setItems);
+                    mReplicationContext->getReplicator()->setState(setItems);
                 }
             }
             catch(const Ice::Exception& e)
@@ -254,7 +254,7 @@ public:
     ScriptProcessorPtr mScriptProcessor;
     EndpointLocatorMap mEndpointLocatorMap;
     const RoutingEventsPtr mEventPublisher;
-    ReplicationContextPtr mReplicationContext;
+    RoutingReplicationContextPtr mReplicationContext;
 };
 
 /**
@@ -361,7 +361,7 @@ typedef IceUtil::Handle<LookupResultCollector> LookupResultCollectorPtr;
  */
 EndpointRegistry::EndpointRegistry(const ScriptProcessorPtr& scriptProcessor, 
                                    const RoutingEventsPtr& eventPublisher,
-                                   const ReplicationContextPtr& replicationContext) :
+                                   const RoutingReplicationContextPtr& replicationContext) :
     mImpl(new EndpointRegistryPriv(scriptProcessor, eventPublisher, replicationContext))
 {
 }
diff --git a/src/EndpointRegistry.h b/src/EndpointRegistry.h
index 4e7e32e..e1413c5 100644
--- a/src/EndpointRegistry.h
+++ b/src/EndpointRegistry.h
@@ -21,7 +21,7 @@
 #include <AsteriskSCF/Discovery/SmartProxy.h>
 
 #include "BasicRoutingStateReplicationIf.h"
-#include "ReplicationContext.h"
+#include "RoutingReplicationContext.h"
 #include "ScriptProcessor.h"
 
 namespace AsteriskSCF
@@ -36,7 +36,7 @@ class EndpointRegistry : public AsteriskSCF::Core::Routing::V1::LocatorRegistry
 public:
     EndpointRegistry(const ScriptProcessorPtr& scriptProcessor, 
                      const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& eventPublisher,
-                     const ReplicationContextPtr& replicationContext);
+                     const RoutingReplicationContextPtr& replicationContext);
 
     /**
      * Configure the EndpointRegistry to use a different scriptProcessor than the
diff --git a/src/ReplicationContext.h b/src/ReplicationContext.h
deleted file mode 100644
index 1e82e00..0000000
--- a/src/ReplicationContext.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010-2011, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#pragma once
-
-#include <boost/shared_ptr.hpp>
-
-#include <AsteriskSCF/Discovery/SmartProxy.h>
-#include "BasicRoutingStateReplicationIf.h"
-#include "TestContext.h"
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx> ReplicatorServicePrx;
-
-class ReplicationContextPriv;
-
-/** 
- * This class provides the component's classes with the context needed to perform replication. 
- */
-class ReplicationContext 
-{
-public:
-    ReplicationContext(bool componentIsActive, bool standalone);
-
-    /**
-     * Returns true if this component is active, non-standalone and has a valid
-     * proxy to it's state replicator. 
-     */
-    bool isReplicating();
-
-    /**
-     * Indicates whether this component is in active (as opposed to standby) mode. 
-     */
-    bool isComponentActive();
-
-    /**
-     * If true, the component is in standalone mode. 
-     * @see isReplicating
-     */
-    bool isStandalone();
-
-    void setComponentActive();
-    void setComponentStandby();
-
-    /**
-     * Get a reference to the state replicator service. 
-     */
-    ReplicatorServicePrx getReplicatorService();
-
-    /** 
-     * Sets the reference to the state replicator service. 
-     */
-    void setReplicatorService(const ReplicatorServicePrx& service);
-
-    /**
-     * Access to a test context to support advanced unit tests.
-     */
-    TestContextPtr getTestContext();
-
-private:
-    boost::shared_ptr<ReplicationContextPriv> mImpl;
-};
-typedef boost::shared_ptr<ReplicationContext> ReplicationContextPtr;
-
-} // end BasicRoutingService
-} // end AsteriskSCF
diff --git a/src/RouteSessionOperation.cpp b/src/RouteSessionOperation.cpp
index 80c15e8..3adbfc9 100644
--- a/src/RouteSessionOperation.cpp
+++ b/src/RouteSessionOperation.cpp
@@ -17,10 +17,12 @@
 #include <boost/bind.hpp>
 
 #include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Component/TestContext.h>
 
 #include "BasicRoutingStateReplicationIf.h"
+#include "RoutingReplicationContext.h"
 #include "RouteSessionOperation.h"
-#include "TestContext.h"
+
 
 using namespace AsteriskSCF;
 using namespace AsteriskSCF::Core::Routing::V1;
@@ -48,7 +50,7 @@ class RouteSessionReplicatingListener :
 {
 public:
     RouteSessionReplicatingListener(RouteSessionOperationPtr op, 
-                                    const ReplicationContextPtr& replicationContext)  
+                                    const RoutingReplicationContextPtr& replicationContext)  
                                        : mTransactionId(op->getOperationId()),
                                          mOperation(op), 
                                          mReplicationContext(replicationContext)
@@ -110,7 +112,7 @@ public:
         RoutingStateItemSeq setItems;
 
         setItems.push_back(item);
-        mReplicationContext->getReplicatorService()->setState(setItems);
+        mReplicationContext->getReplicator()->setState(setItems);
         
         // Cache the replication state items.
         mReplicatedState.push_back(item);
@@ -135,7 +137,7 @@ public:
             {
                 // We just completed the entire operation. 
                 // Remove the items that represented this operation's state transitions.
-                mReplicationContext->getReplicatorService()->removeStateForItems(mReplicatedState);
+                mReplicationContext->getReplicator()->removeStateForItems(mReplicatedState);
             }
         }
         catch(...)
@@ -186,7 +188,7 @@ private:
     RoutingStateItemSeq mReplicatedState;
     std::string mTransactionId;
     RouteSessionOperationPtr mOperation;
-    ReplicationContextPtr mReplicationContext;
+    RoutingReplicationContextPtr mReplicationContext;
 };
 
 /**
@@ -444,7 +446,7 @@ void RouteSessionOperation::establishBridgeState()
     // Test instrumentation
     if (mSessionContext->replicationContext->getTestContext().get() != 0)
     {
-        if (mSessionContext->replicationContext->getTestContext()->getTestMode() == "RouteSessionFailover")
+        if (mSessionContext->replicationContext->getTestContext()->hasTestMode( "RouteSessionFailover"))
         {
             // We're going to just shutdown this operation right here, with no replies to the caller. 
             // This is so that an external test can verify the replica can take it the rest of the way.
diff --git a/src/ReplicationContext.cpp b/src/RoutingReplicationContext.cpp
similarity index 98%
rename from src/ReplicationContext.cpp
rename to src/RoutingReplicationContext.cpp
index ad58952..e09ae31 100644
--- a/src/ReplicationContext.cpp
+++ b/src/RoutingReplicationContext.cpp
@@ -25,10 +25,13 @@ namespace AsteriskSCF
 namespace BasicRoutingService
 {
 
-class ReplicationContextPriv
+class ReplicationContextPriv 
 {
 public:
     ReplicationContextPriv(bool componentIsActive, bool standalone) : 
+
+
+
                     mActive(componentIsActive),
                     mStandalone(standalone),
                     mTestContext(new TestContext())
diff --git a/src/RoutingReplicationContext.h b/src/RoutingReplicationContext.h
new file mode 100644
index 0000000..373c471
--- /dev/null
+++ b/src/RoutingReplicationContext.h
@@ -0,0 +1,91 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/Discovery/SmartProxy.h>
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+#include <AsteriskSCF/Component/TestContext.h>
+#include "BasicRoutingStateReplicationIf.h"
+
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx> ReplicatorSmartPrx;
+
+/** 
+ * This class provides the component's classes with the context needed to perform replication. 
+ */
+class RoutingReplicationContext : public AsteriskSCF::Replication::ReplicationContext
+{
+public:
+    RoutingReplicationContext(AsteriskSCF::Replication::ReplicationStateType state) : 
+        AsteriskSCF::Replication::ReplicationContext(state)
+    {
+    }
+
+    // Override
+     virtual bool isReplicating() 
+     {
+         // If the base context says we aren't replicating, we aren't. 
+         if (!ReplicationContext::isReplicating())
+         {
+             return false;
+         }
+
+         // Do we have a replicator proxy?
+         if (mReplicator.isInitialized())
+         {
+             return true;
+         }
+
+         return false;
+     }
+
+    /**
+     * Get a reference to the state replicator service. 
+     */
+    ReplicatorSmartPrx getReplicator()
+    {
+        return mReplicator;
+    }
+
+    /** 
+     * Sets the reference to the state replicator service. 
+     */
+    void setReplicator(const ReplicatorSmartPrx& replicator)
+    {
+        mReplicator = replicator;
+    }
+
+    /**
+     * Access to a test context to support advanced unit tests.
+     */
+    AsteriskSCF::Component::TestContextPtr getTestContext()
+    {
+        return mTestContext;
+    }
+
+private:
+    ReplicatorSmartPrx mReplicator;
+    AsteriskSCF::Component::TestContextPtr mTestContext;
+};
+typedef boost::shared_ptr<RoutingReplicationContext> RoutingReplicationContextPtr;
+
+} // end BasicRoutingService
+} // end AsteriskSCF
diff --git a/src/SessionRouterOperation.h b/src/SessionRouterOperation.h
index 6c0ad93..19ba933 100644
--- a/src/SessionRouterOperation.h
+++ b/src/SessionRouterOperation.h
@@ -27,7 +27,7 @@
 #include <AsteriskSCF/Discovery/SmartProxy.h>
 #include <AsteriskSCF/Core/Routing/RoutingIf.h>
 #include <AsteriskSCF/logger.h>
-#include "ReplicationContext.h"
+#include "RoutingReplicationContext.h"
 
 #include "SessionListener.h"
 #include "EndpointRegistry.h"
@@ -51,7 +51,7 @@ public:
                     const EndpointRegistryPtr& registryArg,
                     const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& publisherArg,
                     const boost::shared_ptr<AsteriskSCF::Threading::WorkQueue>& workQueueArg,
-                    const ReplicationContextPtr& replicationContextArg)
+                    const RoutingReplicationContextPtr& replicationContextArg)
                           :  adapter(adapterArg),
                              endpointRegistry(registryArg),
                              eventPublisher(publisherArg),
@@ -66,7 +66,7 @@ public:
     const EndpointRegistryPtr endpointRegistry;
     const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr eventPublisher;
     const boost::shared_ptr<AsteriskSCF::Threading::WorkQueue> workQueue;
-    const ReplicationContextPtr replicationContext;
+    const RoutingReplicationContextPtr replicationContext;
 
     AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx> bridgeManager;
 
diff --git a/src/TestContext.cpp b/src/TestContext.cpp
deleted file mode 100644
index 0d13006..0000000
--- a/src/TestContext.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010-2011, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#include <boost/thread/shared_mutex.hpp>
-#include <boost/thread/locks.hpp>
-
-#include "TestContext.h"
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-
-class TestContextPriv
-{
-public:
-    TestContextPriv() : mTestSet(false)
-    {
-    }
-
-    bool mTestSet;
-    std::string mTestMode;
-
-    boost::shared_mutex mLock;
-};
-
-TestContext::TestContext() : mImpl(new TestContextPriv()) 
-{
-}
-
-/**
- * Indicates whether a test mode has been set for unit testing. 
- */
-bool TestContext::hasTestMode() 
-{
-    boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
-    return mImpl->mTestSet;
-}
-
-/**
- * Gets the current test mode.
- */
-std::string TestContext::getTestMode() 
-{
-    boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
-    return mImpl->mTestMode;
-}
-
-/**
- * Sets the current test mode. 
- */
-void TestContext::setTestMode(std::string mode) 
-{
-    boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-    mImpl->mTestSet = true; 
-    mImpl->mTestMode = mode;
-}
-
-/**
- * Clears testing mode.
- */
-void TestContext::clearTestMode()
-{
-    boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-    mImpl->mTestSet = false;
-    mImpl->mTestMode = "";
-}
-
-} // end BasicRoutingService
-} // end AsteriskSCF
diff --git a/src/TestContext.h b/src/TestContext.h
deleted file mode 100644
index 9a2973c..0000000
--- a/src/TestContext.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010-2011, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#pragma once
-
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-class TestContextPriv;
-
-/** 
- * This class provides the component's classes with the context needed for testing.
- */
-class TestContext 
-{
-public:
-    TestContext() ;
-
-    /**
-     * Indicates whether a test mode has been set for unit testing. 
-     */
-    bool hasTestMode();
-
-    /**
-     * Gets the current test mode.
-     */
-    std::string getTestMode();
-
-    /**
-     * Sets the current test mode. 
-     */
-    void setTestMode(std::string mode);
-
-    /**
-     * Clears testing mode.
-     */
-    void clearTestMode();
-
-private:
-    boost::shared_ptr<TestContextPriv> mImpl;
-};
-typedef boost::shared_ptr<TestContext> TestContextPtr;
-
-} // end BasicRoutingService
-} // end AsteriskSCF
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 67f94e2..ab3252c 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -192,7 +192,7 @@ struct GlobalIceFixture
 
         if (SharedTestData::instance.serviceLocatorManagement == 0)
         {
-            cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. Tests can't run without it. (not yet, anyway)" << endl;
+            cout << "Unable to obtain proxy to LocatorServiceManagement interface. Check config file. Tests can't run without it. (not yet, anyway)" << endl;
             return;
         }
 
@@ -210,7 +210,7 @@ struct GlobalIceFixture
         std::string serviceName =SharedTestData::instance.communicatorIn->getProperties()->getPropertyWithDefault(
               "RoutingService.BridgeServiceName", "default");
         ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
-        genericparams->category = BridgeServiceDiscoveryCategory;
+        genericparams->category = BridgeManagerDiscoveryCategory;
         genericparams->service = serviceName;
         management->addLocatorParams(genericparams, "");
     }

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list