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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Aug 8 03:12:07 CDT 2011


branch "master" has been updated
       via  766aabb6ca4f52ba1d964930b1380e89577655d5 (commit)
      from  f738f0c7b03d342bae114b88c46fc0a70d22e5ec (commit)

Summary of changes:
 config/SipConfigurator.py                          |    1 +
 config/test_sip.conf                               |    6 +-
 .../SipSessionManager/SipConfigurationIf.ice       |   11 -
 .../SipSessionManager/SipStateReplicationIf.ice    |    5 -
 src/CMakeLists.txt                                 |    3 +-
 src/Component.cpp                                  |  627 +++++++++++++++++
 src/PJSipManager.cpp                               |   11 +-
 src/PJSipManager.h                                 |    9 +-
 src/PJSipRegistrarModule.cpp                       |   32 +-
 src/PJSipRegistrarModule.h                         |    6 +-
 src/PJSipRegistrarModuleConstruction.cpp           |    4 +-
 src/PJSipSessionModule.cpp                         |   49 +--
 src/PJSipSessionModule.h                           |   11 +-
 src/PJSipSessionModuleConstruction.cpp             |    9 +-
 src/SipEndpoint.cpp                                |   37 +-
 src/SipEndpoint.h                                  |    6 +-
 src/SipEndpointFactory.cpp                         |    4 +-
 src/SipEndpointFactory.h                           |    7 +-
 src/SipReplicationContext.h                        |   83 +++
 src/SipSession.cpp                                 |   22 +-
 src/SipSession.h                                   |    6 +-
 src/SipSessionManagerApp.cpp                       |  709 --------------------
 ...pp => SipStateReplicatorApp -basecomponent.cpp} |   78 +--
 src/SipStateReplicatorApp.cpp                      |   67 +--
 24 files changed, 823 insertions(+), 980 deletions(-)
 create mode 100644 src/Component.cpp
 create mode 100644 src/SipReplicationContext.h
 delete mode 100644 src/SipSessionManagerApp.cpp
 copy src/{SipStateReplicatorApp.cpp => SipStateReplicatorApp -basecomponent.cpp} (78%)


- Log -----------------------------------------------------------------
commit 766aabb6ca4f52ba1d964930b1380e89577655d5
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Aug 8 03:11:46 2011 -0500

    Use base Component class and expanded ServiceLocatorParams.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index f9d82c6..bafe933 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -258,6 +258,7 @@ class SipSectionVisitors(Configurator.SectionVisitors):
 # In order to do service locator based lookup we need to pass in a params object
 serviceLocatorParams = AsteriskSCF.Configuration.SipSessionManager.V1.SipConfigurationParams()
 serviceLocatorParams.category = AsteriskSCF.Configuration.SipSessionManager.V1.ConfigurationDiscoveryCategory
+serviceLocatorParams.service = 'default' 
 
 # Make a configurator application and let it run
 app = Configurator.ConfiguratorApp('Sip.config', SipSectionVisitors(), None, serviceLocatorParams)
diff --git a/config/test_sip.conf b/config/test_sip.conf
index 53416f1..3b5b45c 100644
--- a/config/test_sip.conf
+++ b/config/test_sip.conf
@@ -22,7 +22,7 @@ LocatorService.Proxy=LocatorService:tcp -p 4411
 
 # ID to use when registering with the routing service
 # Useful if registering multiple active SIP session managers
-Sip.RoutingId=pjsip
+Sip.RoutingDestinationId=pjsip
 
 # PJSIP Modules to register
 Sip.Modules=Session
@@ -30,8 +30,8 @@ Sip.Modules=Session
 # UDP Bind address.
 Sip.Transport.UdpBindAddr=0.0.0.0:5060
 
-# The name of the State replicator to use
-Sip.StateReplicatorName=default
+# The service name of the State replicator to use
+Sip.StateReplicatorService=default
 
 # Whether we are only a listener or not
 Sip.StateReplicatorListener=no
diff --git a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
index 9cdafe8..6bddae5 100644
--- a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
+++ b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
@@ -39,17 +39,6 @@ module V1
 const string ConfigurationDiscoveryCategory = "SipConfiguration";
 
 /**
- * Service locator parameters class for discovering the configuration service
- */
-unsliceable class SipConfigurationParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
-{
-    /**
-     * Unique name for the configuration service
-     */
-    string name;
-};
-
-/**
  * Local visitor class for visiting SIP configuration groups
  */
 local class SipConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
diff --git a/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice b/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
index 9f9cbec..655d213 100644
--- a/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
+++ b/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
@@ -39,11 +39,6 @@ module V1
    const string StateReplicatorComponentCategory = "SipStateReplicatorComponent";
    const string StateReplicatorDiscoveryCategory = "SipStateReplicator";
 
-   unsliceable class SipStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
-   {
-      string name;
-   };
-
    class SipStateItem
    {
       string key;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b1879b1..db983f0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,7 +8,8 @@ include_directories(${logger_dir}/include)
 include_directories(${astscf-ice-util-cpp_dir}/include)
 
 astscf_component_init(SipSessionManager)
-astscf_component_add_files(SipSessionManager SipSessionManagerApp.cpp)
+astscf_component_add_files(SipSessionManager Component.cpp)
+astscf_component_add_files(SipSessionManager SipReplicationContext.h)
 astscf_component_add_files(SipSessionManager SipSessionManagerEventPublisher.cpp)
 astscf_component_add_files(SipSessionManager SipSessionManagerEventPublisher.h)
 astscf_component_add_files(SipSessionManager SipSessionManagerEndpointLocator.cpp)
diff --git a/src/Component.cpp b/src/Component.cpp
new file mode 100644
index 0000000..7c42cbc
--- /dev/null
+++ b/src/Component.cpp
@@ -0,0 +1,627 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, 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 <pjlib.h>
+
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+#include <IceBox/IceBox.h>
+#include <IceUtil/UUID.h>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/Core/Routing/RoutingIf.h>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <AsteriskSCF/Discovery/SmartProxy.h>
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+
+#include "SipSessionManagerEventPublisher.h"
+#include "SipSessionManagerEndpointLocator.h"
+#include "SipEndpointFactory.h"
+#include "PJSipSessionModule.h"
+#include "PJSipManager.h"
+#include "SipSession.h"
+#include "SipStateReplicator.h"
+#include "SipConfiguration.h"
+#include "SipRegistrarListener.h"
+#include "SipReplicationContext.h"
+
+using namespace std;
+using namespace AsteriskSCF::SipSessionManager;
+using namespace AsteriskSCF::Configuration::SipSessionManager::V1;
+using namespace AsteriskSCF::Core;
+using namespace AsteriskSCF::Core::Routing::V1;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::System::Hook::V1;
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
+using namespace AsteriskSCF::SIP::Registration::V1;
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::Replication;
+using namespace AsteriskSCF::Discovery;
+
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionGateway");
+}
+
+namespace AsteriskSCF
+{
+namespace SipSessionManager
+{
+class SipAuthExtensionPoint : public AuthExtensionPoint
+{
+public:
+    SipAuthExtensionPoint(const PJSipManagerPtr& manager)
+        : mPJSipManager(manager)
+    {
+    }
+    
+    void addAuthHook(
+            const AuthHookPrx &hook,
+            int priority,
+            const RequestTypeSeq &requestTypes,
+            const Ice::Current&)
+    {
+        mPJSipManager->addAuthHook(hook, priority, requestTypes);
+    }
+    
+    void removeAuthHook(const AuthHookPrx &hook, const Ice::Current&)
+    {
+        mPJSipManager->removeAuthHook(hook);
+    }
+    
+    void clearAuthHooks(const Ice::Current&)
+    {
+        mPJSipManager->clearAuthHooks();
+    }
+private:
+    PJSipManagerPtr mPJSipManager;
+};
+
+typedef IceUtil::Handle<SipAuthExtensionPoint> SipAuthExtensionPointPtr;
+
+
+/**
+ * This private class initializes the startup and controls the shutdown of the component.
+ */
+class Component : public AsteriskSCF::Component::Component
+{
+public:
+    Component() 
+        :  AsteriskSCF::Component::Component(lg, ComponentServiceDiscoveryCategory),
+           mListeningToReplicator(false)
+    {
+    }
+
+    ~Component()
+    {
+    }
+
+private:
+    // Required base Component overrides
+    virtual void createPrimaryServices();
+    virtual void preparePrimaryServicesForDiscovery();
+    virtual void createReplicationStateListeners();
+    virtual void stopListeningToStateReplicators();
+    virtual void listenToStateReplicators();
+    virtual void findRemoteServices();
+
+    // Notification overrides
+    virtual void onPreInitialize();
+    virtual void onPostInitialize();
+    virtual void onStop();
+
+    // Other base Component overrides
+    virtual void createBackplaneServices();
+    virtual void prepareBackplaneServicesForDiscovery();
+    virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
+    virtual void unregisterFromRemoteServices();    
+    virtual void registerWithRemoteServices();
+
+    // Our own implementation operations. 
+    void registerWithRoutingService();
+    void unregisterFromRoutingService();
+
+    void registerWithServiceLocator();
+    void unregisterFromServiceLocator();
+    void locateRoutingService();
+    void locateSessionRouter();
+    void locateStateReplicator();
+
+    void registerPJSipModules();
+
+    bool mListeningToReplicator;
+
+    // Unique Id for this component's EndpointLocator. 
+    // Used when registering with routing service. 
+    std::string mRoutingId;
+
+    // Configuration 
+    LocatorRegistrationWrapperPtr mConfigurationRegistration;
+    ConfigurationServicePtr mConfigurationService;
+    ConfigurationServicePrx mConfigurationServiceProxy;
+
+    // State Replication listener
+    SipStateReplicatorListenerPtr mReplicatorListener;
+    SipStateReplicatorListenerPrx mReplicatorListenerProxy;
+
+    // Implementation support classes
+    boost::shared_ptr<SipSessionManagerEventPublisher> mEventPublisher;
+    Routing::V1::EndpointLocatorPtr mEndpointLocator;
+    boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
+    PJSipManagerPtr mPJSipManager;
+
+    // Servants and their proxies
+    SipAuthExtensionPointPtr mAuthExtension;
+    AuthExtensionPointPrx mAuthExtensionPrx;
+    LocatorRegistrationWrapperPtr mAuthExtensionRegistration;
+
+    RegistrarListenerPtr mDefaultRegistrarListener;
+    RegistrarListenerPrx mDefaultRegistrarListenerPrx;
+
+    // Remote references
+    AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> mSessionRouter;
+    AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> mRoutingServiceLocatorRegistry;
+};
+
+static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
+static const string ReplicaServiceId("SipChannelReplica");
+static const string AuthServiceId("SipAuthExtensionPoint");
+static const string RegistrarListenerId("SipRegistrarListener");
+
+/**
+ * Override of factory method to create our custom replication context. 
+ */
+ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
+{
+    SipReplicationContextPtr context(new SipReplicationContext(state));
+    return context;
+}
+
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void Component::preparePrimaryServicesForDiscovery()
+{
+    try
+    {
+        // Wrap our authentication extensions point for the Service Locator.
+        mAuthExtensionRegistration = wrapServiceForRegistration(mAuthExtensionPrx, 
+                                                                 AsteriskSCF::SIP::V1::AuthExtensionPointCategory);
+        managePrimaryService(mAuthExtensionRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION << 
+            ". Exception: " << e.what();
+        throw; // rethrow
+    }
+}
+
+/**
+ * Prepare this component's backplane interfaces for discovery via the Service Locator.
+ */
+void Component::prepareBackplaneServicesForDiscovery()
+{
+    // Insure the default Component services are prepped. 
+    AsteriskSCF::Component::Component::prepareBackplaneServicesForDiscovery();
+
+    try
+    {
+        // Wrap our configuration interface for the Service Locator.
+        mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServiceProxy, 
+                                                                ConfigurationDiscoveryCategory);
+        manageBackplaneService(mConfigurationRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION <<  " : " << e.what();
+    }
+}
+
+/**
+ * Get a reference to the Routing Service interface that we care about, and cache it in the Data Model.
+ * This will allow us to lookup endpoints anywhere in the Asterisk SCF system.
+ */
+void Component::locateRoutingService()
+{
+    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+    genericparams->category = Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
+    genericparams->service =
+        getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingService", "default");
+
+    AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> pw(getServiceLocator(), genericparams, lg);
+    mRoutingServiceLocatorRegistry = pw;
+
+    // This exists here since it may need to be known before actually contacting the routing service
+    mRoutingId = getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingDestinationId", "pjsip");
+}
+
+void Component::locateStateReplicator()
+{
+    if (getReplicationContext()->getState() == ACTIVE_STANDALONE)
+    {
+        return;
+    }
+
+    ServiceLocatorParamsPtr replicatorParams = new ServiceLocatorParams();
+    replicatorParams->category = StateReplicatorDiscoveryCategory;
+    replicatorParams->service =
+        getCommunicator()->getProperties()->getPropertyWithDefault("Sip.StateReplicatorService", "default");
+
+    try
+    {
+        AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(getServiceLocator(), replicatorParams, lg);
+        SipReplicationContextPtr sipReplicationContext = 
+            static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+        sipReplicationContext->setReplicator(pw);
+
+        // Since we're not in standalone mode, we'll get our configuration updates routed via the
+        // replicator service. 
+	    ConfigurationReplicatorPrx configurationReplicator = ConfigurationReplicatorPrx::checkedCast(
+            sipReplicationContext->getReplicator().initialize(), ReplicatorFacet);
+	    configurationReplicator->registerConfigurationService(mConfigurationServiceProxy);
+    }
+    catch (...)
+    {
+        lg(Error) << "State replicator could not be found, operating without.";
+    }
+}
+
+void Component::listenToStateReplicators()
+{
+    SipReplicationContextPtr sipReplicationContext = 
+        static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+    if (mListeningToReplicator == true)
+    {
+        return;
+    }
+
+    if (!sipReplicationContext->getReplicator().isInitialized())
+    {
+        lg(Error) << getName() << " : State replicator could not be found. Unable to listen for state updates!";
+        return;
+    }
+
+    try
+    {
+        // Are we in standby mode?
+        if (sipReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+        {
+            sipReplicationContext->getReplicator()->addListener(mReplicatorListenerProxy);
+            mListeningToReplicator = true;
+        }
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
+}
+
+/** 
+ * Unregister as a listener to our state replicator. 
+ * A component in active mode doesn't neeed to listen to
+ * state replication data. 
+ */
+void Component::stopListeningToStateReplicators()
+{
+    SipReplicationContextPtr sipReplicationContext = 
+        static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+    if ((!sipReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+    {
+        return;
+    }
+
+    try
+    {
+        sipReplicationContext->getReplicator()->removeListener(mReplicatorListenerProxy);
+        mListeningToReplicator = false;
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
+}
+
+/**
+ * Get a reference to the routine service.
+ */
+void Component::locateSessionRouter()
+{
+    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+    genericparams->category = Routing::V1::SessionRouterDiscoveryCategory;
+    genericparams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
+            "SessionRouter.Service", "default");
+
+    SmartProxy<SessionRouterPrx> pw(getServiceLocator(), genericparams, lg);
+    mSessionRouter = pw;
+}
+
+void Component::registerPJSipModules()
+{
+    SipReplicationContextPtr sipReplicationContext = 
+        static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+    Ice::PropertiesPtr props = getCommunicator()->getProperties();
+    Ice::StringSeq moduleNames = props->getPropertyAsList("Sip.Modules");
+    for (Ice::StringSeq::iterator i = moduleNames.begin();
+         i != moduleNames.end();
+         ++i)
+    {
+        //We should probably delegate the responsibility of mapping
+        //module names to modules to the PJSIP session manager instead.
+        //Since there's only a single configurable module at the moment,
+        //we'll just do it here instead.
+        if ((*i) == "Session")
+        {
+            mPJSipManager->registerSessionModule(mEndpointFactory,
+                mSessionRouter, 
+                getServiceLocator(), 
+                sipReplicationContext, 
+                getServiceAdapter(), 
+                getServiceLocatorManagement());
+        }
+        else if ((*i) == "Logging" || (*i) == "Logger")
+        {
+            mPJSipManager->registerLoggingModule();
+        }
+        else if (*i == "Registrar")
+        {
+            mPJSipManager->registerRegistrarModule(mDefaultRegistrarListenerPrx, 
+                                                   sipReplicationContext, 
+                                                   getServiceAdapter());
+        }
+    }
+    lg(Debug) << "Registered PJSIP modules";
+}
+
+/**
+ * Pre-init notification from the base component. Allows us
+ * to initialize things before the base component does anything
+ * else. 
+ */
+void Component::onPreInitialize()
+{
+    try
+    {
+        // Initialize PJSIP
+        // NOTE: Should use PJSipManager::create now. 
+        mPJSipManager = PJSipManager::create(getCommunicator()->getProperties());
+        lg(Debug) << "Created PJSIP manager";
+
+        //As nice as it is of IceBox to provide us with a communicator,
+        //we're going to create our own so that we can provide it with a threadhook.
+        //Yes, this could be done via a plugin, but this is easier. Go away.
+        Ice::InitializationData id;
+        id.threadHook = new pjlibHook();
+        id.properties = getCommunicator()->getProperties();
+
+        setCommunicator(Ice::initialize(id));
+    }
+    catch(const std::exception& e)
+    {
+        lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
+    }
+}
+
+/**
+ * Register our own Endpoint Locator with the Routing Service so that
+ * the endpoints that this channel manages can be accessed from any
+ * Session Manager in the Asterisk SCF system.
+ */
+void Component::registerWithRoutingService()
+{
+    try
+    {
+        RegExSeq destinations;
+
+        mEndpointFactory->generateRoutingDestinations(destinations);
+
+        EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
+            getServiceAdapter()->createDirectProxy(getCommunicator()->stringToIdentity(EndpointLocatorObjectId)));
+        mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION <<  " : " << e.what();
+    }
+}
+
+/**
+ * Unregister our own Endpoint Locator from the Routing SErvice.
+ */
+void Component::unregisterFromRoutingService()
+{
+    try
+    {
+        mRoutingServiceLocatorRegistry->removeEndpointLocator(mRoutingId);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION <<  " : " << e.what();
+    }
+}
+
+/**
+ * This operation is called by the base Component class
+ * at times such as activation, or resumed, to allow us to
+ * add our own proxies with remote services. 
+ */
+void Component::registerWithRemoteServices() 
+{
+    // Register our Endpoint Locator so that we can provide endpoints to the
+    // Routing Service for the endpoints we manage.
+    registerWithRoutingService();
+}
+
+/**
+ * This operation is called by the base Component class
+ * at times such as standy, or paused, to allow us to
+ * remove our own proxies from remote services. 
+ */
+void Component::unregisterFromRemoteServices() 
+{
+    unregisterFromRoutingService();
+}
+
+/**
+ * Post-init notification from the base component. Allows us
+ * to initialize things after the base component does common
+ * initialization. 
+ */
+void Component::onPostInitialize()
+{
+    try
+    {
+        registerPJSipModules();
+    }
+    catch(const std::exception& e)
+    {
+        lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
+    }
+}
+
+/**
+ * Create the objects that implement the main services this component provides 
+ * the system.
+ */
+void Component::createPrimaryServices()
+{
+    try
+    {
+        SipReplicationContextPtr sipReplicationContext = 
+            static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+        mEventPublisher.reset(new SipSessionManagerEventPublisher(getServiceAdapter()));
+        lg(Debug) << "Created SIP Session Manager event publisher";
+
+        mEndpointFactory.reset(new SipEndpointFactory(getServiceAdapter(), 
+               mPJSipManager, getServiceLocator(), sipReplicationContext));
+        lg(Debug) << "Created SIP endpoint factory";
+
+	    // Locate the Routing Service so that we can do routing. This is done here so it can be
+        // passed to the configuration service. 
+        // (NOTE: I suspect that since we're using a smart pointer, 
+        // this could be deferred to findRemoteServices)
+	    locateRoutingService();
+
+        // Create and configure our Endpoint Locator.
+        mEndpointLocator = new SipSessionManagerEndpointLocator(mEndpointFactory);
+        getServiceAdapter()->add(mEndpointLocator, getCommunicator()->stringToIdentity(EndpointLocatorObjectId));
+        lg(Debug) << "Got proxy to endpoint locator";
+
+        // Create our RegistrarListener
+        mDefaultRegistrarListener = new SipDefaultRegistrarListener(mEndpointFactory);
+        mDefaultRegistrarListenerPrx = RegistrarListenerPrx::uncheckedCast(
+            getServiceAdapter()->add(mDefaultRegistrarListener, getCommunicator()->stringToIdentity(RegistrarListenerId)));
+        lg(Debug) << "Added default registrar listener to object adapter";
+
+        // Create our SipAuthExtensionPoint servant. 
+        mAuthExtension = new SipAuthExtensionPoint(mPJSipManager);
+        mAuthExtensionPrx = AuthExtensionPointPrx::uncheckedCast(
+             getServiceAdapter()->add(mAuthExtension, getCommunicator()->stringToIdentity(AuthServiceId)));
+        lg(Debug) << "Added Authentication extension point to object adapter";
+
+    }
+    catch(const Ice::Exception& e)
+    {
+       lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+    }
+}
+
+void Component::createBackplaneServices()
+{
+    // Include the base Component services. 
+    AsteriskSCF::Component::Component::createBackplaneServices();
+
+    try
+    {
+        // Create and publish our Configuration interface support.
+        mConfigurationService = createConfigurationServant(mPJSipManager, mEndpointFactory, mRoutingId, mRoutingServiceLocatorRegistry);
+        mConfigurationServiceProxy = ConfigurationServicePrx::uncheckedCast(
+            getBackplaneAdapter()->addWithUUID(mConfigurationService));
+        lg(Debug) << "Created SIP Configuration Implementation";
+
+    }
+    catch(const Ice::Exception& e)
+    {
+       lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+    }
+}
+
+void Component::createReplicationStateListeners()
+{
+    try
+    {
+       // Create and publish our state replicator listener interface.
+        mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory, mPJSipManager);
+        SipStateReplicatorListenerPrx replicatorListener = SipStateReplicatorListenerPrx::uncheckedCast(
+             getBackplaneAdapter()->addWithUUID(mReplicatorListener));
+        mReplicatorListenerProxy = SipStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
+            
+        lg(Debug) << "Got proxy to SIP state replicator";
+    }
+    catch(const Ice::Exception &e)
+    {
+        lg(Error) << getName() << " in " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+        throw;
+    }
+}
+
+void Component::findRemoteServices() 
+{
+    // Locate the Session Router so we can REALLY do routing.
+    locateSessionRouter();
+
+    // Locate the State Replicator so we can fail over.
+    locateStateReplicator();
+}
+
+/**
+ * Notification from the component that we're stopping. 
+ */
+void Component::onStop()
+{
+    // Remove our endpoint locator from the routing service.
+    unregisterFromRoutingService();
+}
+
+extern "C"
+{
+ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new AsteriskSCF::SipSessionManager::Component;
+}
+}
+
+}; // end SipSessionManager
+}; // end AsteriskSCF
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 1618b4e..4d60459 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -128,14 +128,13 @@ void PJSipManager::registerSessionModule(const boost::shared_ptr<SipEndpointFact
         const AsteriskSCF::Discovery::SmartProxy<
             AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         const Ice::ObjectAdapterPtr& adapter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& serviceLocatorManagement
     )
 {
     mSessionModule = new PJSipSessionModule(mEndpoint, endpointFactoryPtr, sessionRouter,
-        serviceLocator, stateReplicator, replica, adapter, serviceLocatorManagement);
+        serviceLocator, replicationContext, adapter, serviceLocatorManagement);
 }
 
 void PJSipManager::registerLoggingModule()
@@ -145,10 +144,10 @@ void PJSipManager::registerLoggingModule()
 
 void PJSipManager::registerRegistrarModule(
         const RegistrarListenerPrx& defaultListener,
-        const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx>& stateReplicator,
-        Ice::ObjectAdapterPtr& adapter)
+        const SipReplicationContextPtr& replicationContext,
+        const Ice::ObjectAdapterPtr& adapter)
 {
-    mRegistrarModule = new PJSipRegistrarModule(mEndpoint, defaultListener, stateReplicator);
+    mRegistrarModule = new PJSipRegistrarModule(mEndpoint, defaultListener, replicationContext);
     //The registrar implements a published interface, so we need to add it to
     //the object adapter
     adapter->add(mRegistrarModule->getRegistrar(),
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index e26acf1..fe25567 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -35,6 +35,7 @@
 #include "Transports.h"
 #include "SipModule.h"
 #include "PJSipRegistrarModule.h"
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -90,8 +91,7 @@ public:
         const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
             sessionRouter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         const Ice::ObjectAdapterPtr& adapter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& serviceLocatorManagement
         );
@@ -112,9 +112,8 @@ public:
      */
     void registerRegistrarModule(
             const AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx& defaultListener,
-            const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx>& stateReplicator,
-            Ice::ObjectAdapterPtr& adapter);
-
+            const SipReplicationContextPtr& replicationContext,
+            const Ice::ObjectAdapterPtr& adapter);
 
     //
     // TODO: move this transport collection stuff to a transport manager or something.
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index c7cde7f..b9232a9 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -22,6 +22,7 @@
 
 #include "PJSipRegistrarModule.h"
 #include "PJSipManager.h"
+#include "SipReplicationContext.h"
 
 using namespace AsteriskSCF::SIP::Registration::V1;
 using namespace AsteriskSCF::System::Logging;
@@ -383,13 +384,13 @@ class ReplicateState : public Work
 {
 public:
     ReplicateState(
-            const AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx& stateReplicator,
+            const SipReplicationContextPtr& replicationContext,
             const std::string &aor,
             const BindingWrapperSeq& existingBindings,
             const BindingWrapperSeq& newBindings,
             const BindingWrapperSeq& removedBindings,
             const RegistrarIPtr& registrar)
-        : mStateReplicator(stateReplicator), mAOR(aor), mExistingBindings(existingBindings), mNewBindings(newBindings),
+        : mReplicationContext(replicationContext), mAOR(aor), mExistingBindings(existingBindings), mNewBindings(newBindings),
         mRemovedBindings(removedBindings), mRegistrar(registrar) { }
 
     void execute()
@@ -402,7 +403,7 @@ public:
                 SipRegistrarStateItemPtr newItem(new SipRegistrarStateItem(mAOR, mAOR, newDict, true));
                 SipStateItemSeq items;
                 items.push_back(newItem);
-                mStateReplicator->setState(items);
+                mReplicationContext->getReplicator()->setState(items);
             }
             
             if (!mExistingBindings.empty())
@@ -411,7 +412,7 @@ public:
                 SipRegistrarStateItemPtr existingItem(new SipRegistrarStateItem(mAOR, mAOR, existingDict, false));
                 SipStateItemSeq items;
                 items.push_back(existingItem);
-                mStateReplicator->setState(items);
+                mReplicationContext->getReplicator()->setState(items);
             }
 
             if (!mRemovedBindings.empty())
@@ -420,7 +421,7 @@ public:
                 SipRegistrarStateItemPtr removedItem(new SipRegistrarStateItem(mAOR, mAOR, removedDict, false));
                 SipStateItemSeq items;
                 items.push_back(removedItem);
-                mStateReplicator->removeStateForItems(items);
+                mReplicationContext->getReplicator()->removeStateForItems(items);
             }
         }
         catch (const Ice::TwowayOnlyException&)
@@ -434,7 +435,7 @@ public:
 
     }
 private:
-    AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx mStateReplicator;
+    SipReplicationContextPtr mReplicationContext;
     const std::string mAOR;
     BindingWrapperSeq mExistingBindings;
     BindingWrapperSeq mNewBindings;
@@ -448,24 +449,7 @@ void PJSipRegistrarModule::replicateState(
         const BindingWrapperSeq& newBindings,
         const BindingWrapperSeq& removedBindings)
 {
-
-    AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx oneWayStateReplicator;
-    try
-    {
-        oneWayStateReplicator = AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx::uncheckedCast(mStateReplicator->ice_oneway());
-    }
-    catch (const Ice::NoEndpointException&)
-    {
-        lg(Error) << "No endpoint when attempting to create oneway proxy for state replication in registrar";
-        return;
-    }
-    catch (const Ice::Exception& ex)
-    {
-        lg(Error) << "Caught exception while attempting to create oneway proxy for state replication in registrar\n" << ex.what();
-        return;
-    }
-
-    mRegistrar->getQueue()->enqueueWork(new ReplicateState(oneWayStateReplicator, aor, existingBindings, newBindings, removedBindings, mRegistrar));
+    mRegistrar->getQueue()->enqueueWork(new ReplicateState(mReplicationContext, aor, existingBindings, newBindings, removedBindings, mRegistrar));
 }
 
 //XXX This and the method that queues this work should
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index 6105e5d..82cc137 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -22,6 +22,7 @@
 
 #include "SipStateReplicator.h"
 #include "PJSipModule.h"
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -30,6 +31,7 @@ namespace SipSessionManager
 {
 
 class BindingWrapper;
+
 typedef IceUtil::Handle<BindingWrapper> BindingWrapperPtr;
 typedef std::vector<BindingWrapperPtr> BindingWrapperSeq;
 typedef std::map<std::string, BindingWrapperSeq> BindingWrapperDict;
@@ -99,7 +101,7 @@ public:
     PJSipRegistrarModule(
             pjsip_endpoint *endpt,
             const AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx& defaultListener,
-            const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx>& stateReplicator);
+            const SipReplicationContextPtr& replicationContext);
     pj_status_t load(pjsip_endpoint *endpoint);
     pj_status_t start();
     pj_status_t stop();
@@ -153,7 +155,7 @@ private:
 
     pjsip_endpoint *mEndpoint;
     RegistrarIPtr mRegistrar;
-    AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx> mStateReplicator;
+    SipReplicationContextPtr mReplicationContext;
 };
 
 typedef IceUtil::Handle<PJSipRegistrarModule> PJSipRegistrarModulePtr;
diff --git a/src/PJSipRegistrarModuleConstruction.cpp b/src/PJSipRegistrarModuleConstruction.cpp
index 45958bc..42aebfe 100644
--- a/src/PJSipRegistrarModuleConstruction.cpp
+++ b/src/PJSipRegistrarModuleConstruction.cpp
@@ -76,8 +76,8 @@ static void registrarOnTsxState(pjsip_transaction *tsx, pjsip_event *event)
 PJSipRegistrarModule::PJSipRegistrarModule(
         pjsip_endpoint *endpt,
         const RegistrarListenerPrx& defaultListener,
-        const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx>& stateReplicator)
-    : mEndpoint(endpt), mRegistrar(new RegistrarI(defaultListener)), mStateReplicator(stateReplicator)
+        const SipReplicationContextPtr& replicationContext)
+    : mEndpoint(endpt), mRegistrar(new RegistrarI(defaultListener)), mReplicationContext(replicationContext)
 {
     registrarModule = this;
     mModule.name = pj_str(registrarModuleName);
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 44a1469..9f8de91 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -21,6 +21,7 @@
 #include "PJSipManager.h"
 #include "SipStateReplicator.h"
 #include "SipTelephonyEventSource.h"
+#include "SipReplicationContext.h"
 
 #include <IceUtil/UUID.h>
 #include <boost/lexical_cast.hpp>
@@ -300,54 +301,16 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
         }
     }
     lg(Debug) << "========== End State Replication Dump ==========";
-    if (mReplica->isActive() == true)
+    if (mReplicationContext->isReplicating() == true)
     {
-        if (setItems.size() != 0 && mStateReplicator)
+        if (setItems.size() != 0)
         {
-            Ice::ObjectPrx oneway;
-            try
-            {
-                oneway = mStateReplicator->ice_oneway();
-            }
-            catch (const Ice::NoEndpointException&)
-            {
-                lg(Error) << "No endpoint for oneway invocation of setState() for state replication.";
-            }
-
-            SipStateReplicatorPrx oneWayStateReplicator = SipStateReplicatorPrx::uncheckedCast(oneway);
-
-            try
-            {
-                oneWayStateReplicator->setState(setItems);
-            }
-            catch (const Ice::TwowayOnlyException&)
-            {
-                lg(Error) << "setState() is not oneway.";
-            }
+            mReplicationContext->getReplicator().tryOneWay()->setState(setItems);
         }
 
-        if (removeItems.size() != 0 && mStateReplicator)
+        if (removeItems.size() != 0)
         {
-            Ice::ObjectPrx oneway;
-            try
-            {
-                oneway = mStateReplicator->ice_oneway();
-            }
-            catch (const Ice::NoEndpointException&)
-            {
-                lg(Error) << "No endpoint for oneway invocation of removeState() for state replication.";
-            }
-
-            SipStateReplicatorPrx oneWayStateReplicator = SipStateReplicatorPrx::uncheckedCast(oneway);
-
-            try
-            {
-                oneWayStateReplicator->removeState(removeItems);
-            }
-            catch (const Ice::TwowayOnlyException&)
-            {
-                lg(Error) << "removeState() is not oneway.";
-            }
+            mReplicationContext->getReplicator().tryOneWay()->removeState(removeItems);
         }
     }
 }
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index e7f6e62..27eda44 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -24,11 +24,11 @@
 #include <boost/thread/shared_mutex.hpp>
 
 #include <AsteriskSCF/Discovery/SmartProxy.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
 #include <AsteriskSCF/System/ThreadPool/ThreadPoolIf.h>
 #include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
 
-#include "SipStateReplicator.h"
+#include "SipEndpointFactory.h"
+#include "SipReplicationContext.h"
 #include "SipSession.h"
 #include "PJSipModule.h"
 
@@ -104,11 +104,11 @@ public:
         const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
             sessionRouter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         const Ice::ObjectAdapterPtr& adapter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& serviceLocatorManagement);
     ~PJSipSessionModule();
+
     pj_status_t load(pjsip_endpoint *endpoint);
     pj_status_t start();
     pj_status_t stop();
@@ -156,8 +156,7 @@ private:
     boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
     AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> mSessionRouter;
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
-    AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> mStateReplicator;
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
     pjsip_endpoint *mEndpoint;
     AsteriskSCF::System::ThreadPool::V1::PoolPtr mPool;
     AsteriskSCF::System::WorkQueue::V1::QueuePtr mPoolQueue;
diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index 7d86a95..97d88ee 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -38,6 +38,7 @@ namespace SipSessionManager
 using namespace AsteriskSCF::WorkQueue;
 using namespace AsteriskSCF::ThreadPool;
 using namespace AsteriskSCF::SessionCommunications::ExtensionPoints::V1;
+using namespace AsteriskSCF::Core::Discovery::V1;
 
 static char moduleName[] = "PJSipSessionModule";
 
@@ -122,13 +123,12 @@ PJSipSessionModule::PJSipSessionModule(pjsip_endpoint *endpt,
     const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
     const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
     const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-    const AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx>& stateReplicator,
-    const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+    const SipReplicationContextPtr& replicationContext,
     const Ice::ObjectAdapterPtr& adapter,
     const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& serviceLocatorManagement)
     : mName(moduleName), mEndpointFactory(endpointFactoryPtr),
       mSessionRouter(sessionRouter), mServiceLocator(serviceLocator),
-      mStateReplicator(stateReplicator), mReplica(replica), mEndpoint(endpt),
+      mReplicationContext(replicationContext), mEndpoint(endpt),
       mSessionCreationExtensionPoint(new SipSessionCreationExtensionPoint()), mAdapter(adapter)
 {
     sessionModule = this;
@@ -149,7 +149,8 @@ PJSipSessionModule::PJSipSessionModule(pjsip_endpoint *endpt,
         SessionCreationExtensionPointPrx::uncheckedCast(extensionPointObjPrx);
 
     mSessionCreationExtensionPointService = serviceLocatorManagement->addService(extensionPointPrx, SessionCreationExtensionPointId);
-    mSessionCreationExtensionPointService->addLocatorParams(new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams(SessionCreationHookLocatorCategory), "");
+    // TBD... how to access the Component's service and instance ids. 
+    mSessionCreationExtensionPointService->addLocatorParams(new ServiceLocatorParams(SessionCreationHookLocatorCategory, "default", ""), "");
 
     mPoolQueue = new AsteriskSCF::WorkQueue::WorkQueue();
     mPoolListener = new PJSipSessionModuleThreadPoolListener(); 
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index f8e0cf5..52912e2 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -168,9 +168,9 @@ public:
     SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
             const std::string& name, const PJSipManagerPtr& manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-            const AsteriskSCF::System::Component::V1::ReplicaPtr& replica) :
+            const SipReplicationContextPtr& replicationContext) :
         mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator),
-        mReplica(replica)
+        mReplicationContext(replicationContext)
     {
     };
     
@@ -222,19 +222,23 @@ public:
     /**
      *
      */
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
 };
 
 SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, 
-    boost::shared_ptr<SipEndpointFactory> factory, std::string name, 
-    const PJSipManagerPtr& manager,
-    const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, 
-    const AsteriskSCF::System::Component::V1::ReplicaPtr replica)
-    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replica))
+    const boost::shared_ptr<SipEndpointFactory>& factory,
+    std::string name, 
+    const PJSipManagerPtr& manager, 
+    const ServiceLocatorPrx& serviceLocator,
+    const SipReplicationContextPtr& replicationContext)
+    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
 {
     lg(Debug) << "Constructing SIP endpoint " << name;
 
-    mImplPriv->mEndpointProxy = AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::uncheckedCast(mImplPriv->mAdapter->addWithUUID(this));
+    mImplPriv->mEndpointProxy =
+        AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::uncheckedCast(
+            mImplPriv->mAdapter->addWithUUID(this));
+
 }
 
 void SipEndpoint::removeFromAdapter()
@@ -373,9 +377,10 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
     }
 
     SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listener, mImplPriv->mManager,
-        mImplPriv->mServiceLocator, mImplPriv->mReplica, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, true, mImplPriv->mConfig,
-        NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
-            mImplPriv->mConfig.transportConfig.enableNAT));
+        mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, 
+	true, mImplPriv->mConfig, NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
+        mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
+        mImplPriv->mConfig.transportConfig.enableNAT));
 
     mImplPriv->mSessions.push_back(session);
     std::cout << "And now we're returing a session proxy..." << std::endl;
@@ -385,8 +390,10 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
 AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination)
 {
     SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, 0, mImplPriv->mManager,
-        mImplPriv->mServiceLocator, mImplPriv->mReplica, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false, mImplPriv->mConfig,
-        NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
+        mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false, 
+	mImplPriv->mConfig, 
+	NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
+            mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
             mImplPriv->mConfig.transportConfig.enableNAT)
         );
 
@@ -402,7 +409,7 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
                                                                          const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
 {
     SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, controllerid, mediaid, mediasessions,
-            sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica, false, mImplPriv->mConfig,
+            sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, false, mImplPriv->mConfig,
             NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
                 mImplPriv->mConfig.transportConfig.enableNAT));
     mImplPriv->mSessions.push_back(session);
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index d4afefc..89c166b 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -36,6 +36,7 @@
 #include <AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.h>
 
 #include "SipSession.h"
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -269,10 +270,9 @@ class SipEndpointImplPriv;
 class SipEndpoint : public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
 {
 public:
-
-    SipEndpoint(const Ice::ObjectAdapterPtr& adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, 
+    SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory, std::string name, 
         const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, 
-        const AsteriskSCF::System::Component::V1::ReplicaPtr replica);
+        const SipReplicationContextPtr& replicationContext);
 
     bool operator==(const std::string &name) const;
 
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index 49724d6..ce8de77 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -30,10 +30,10 @@ namespace AsteriskSCF
 {
 namespace SipSessionManager
 {
-
 SipEndpointPtr SipEndpointFactory::createEndpoint(std::string endpointName)
 {
-    SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), endpointName, mManager, mServiceLocator, mReplica);
+    SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), endpointName, mManager, 
+        mServiceLocator, mReplicationContext);
     mEndpoints.push_back(endpoint);
     return endpoint;
 }
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 4239503..13a63ed 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -23,6 +23,7 @@
 #include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.h>
 #include <AsteriskSCF/SIP/SIPRegistrarIf.h>
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -39,8 +40,8 @@ class SipEndpointFactory : public boost::enable_shared_from_this<SipEndpointFact
 public:
     SipEndpointFactory(const Ice::ObjectAdapterPtr& adapter, const PJSipManagerPtr& manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica) :
-        mAdapter(adapter), mManager(manager), mServiceLocator(serviceLocator), mReplica(replica) { };
+        const SipReplicationContextPtr& replicationContext) :
+        mAdapter(adapter), mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext) {};
 
     SipEndpointPtr createEndpoint(std::string);
 
@@ -74,7 +75,7 @@ private:
     /**
      * A pointer to the replica information.
      */
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
 };
 
 }; // end SipSessionManager
diff --git a/src/SipReplicationContext.h b/src/SipReplicationContext.h
new file mode 100644
index 0000000..84e3ef3
--- /dev/null
+++ b/src/SipReplicationContext.h
@@ -0,0 +1,83 @@
+/*
+ * 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 "SipStateReplicationIf.h"
+
+namespace AsteriskSCF
+{
+namespace SipSessionManager
+{
+typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx> ReplicatorSmartPrx;
+
+/** 
+ * This class provides the component's classes with the context needed to perform replication. 
+ */
+class SipReplicationContext : public AsteriskSCF::Replication::ReplicationContext
+{
+public:
+    SipReplicationContext(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() == false)
+         {
+             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;
+    }
+
+private:
+    ReplicatorSmartPrx mReplicator;
+};
+typedef boost::shared_ptr<SipReplicationContext> SipReplicationContextPtr;
+
+} // end SipSessionManager
+} // end AsteriskSCF
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index aa2c3f5..3592529 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -101,10 +101,11 @@ public:
     SipSessionPriv(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
         const std::string& destination, const PJSipManagerPtr& manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         const NATEndpointOptions& natOptions)
         : mAdapter(adapter), mDialog(0), mInviteSession(0), mEndpoint(endpoint), mDestination(destination),
-          mManager(manager), mServiceLocator(serviceLocator), mReplica(replica), mNatOptions(natOptions), mSDP(0)
+          mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext), 
+	  mNatOptions(natOptions), mSDP(0)
     { 
     }
 
@@ -285,7 +286,7 @@ public:
 
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
 
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
 
     SessionWorkPtr mSessionWork;
 
@@ -778,11 +779,11 @@ void SipSession::setTelephonyEventSourcesAndSinks(const SipEndpointConfig& confi
  * Default constructor.
  */
 SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
-        const std::string& destination,  const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
+        const std::string& destination, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
         const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool /* ipv6 */, bool isUAC, const SipEndpointConfig &config,
+        const SipReplicationContextPtr& replicationContext, bool /* ipv6 */, bool isUAC, const SipEndpointConfig &config,
         const NATEndpointOptions& natOptions)
-    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica, natOptions))
+    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext, natOptions))
 {
     if (listener != 0)
     {
@@ -811,14 +812,15 @@ SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPt
  * Replica constructor.
  */
 SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
-                       const std::string& destination, const Ice::Identity& /* sessionid */,
+                       const std::string& destination, 
+                       const Ice::Identity& /* sessionid */,
                        const Ice::Identity& controllerid,
                        const Ice::Identity& mediaid, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq& mediasessions,
                        const AsteriskSCF::Media::V1::StreamSourceSeq& sources, const AsteriskSCF::Media::V1::StreamSinkSeq& sinks,
                        const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-                       const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool isUAC, const SipEndpointConfig &config,
+                       const SipReplicationContextPtr& replicationContext, bool isUAC, const SipEndpointConfig &config,
                        const NATEndpointOptions& natOptions)
-    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica, natOptions))
+    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext, natOptions))
 {
     activateIceObjects(mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
 
@@ -1664,7 +1666,7 @@ public:
         }
         mSessionPriv->mMediaSession = 0;
 
-        if (mSessionPriv->mReplica->isActive() == true)
+        if (mSessionPriv->mReplicationContext->isActive() == true)
         {
             //XXX This loop may be a candidate for making AMI-ified and returning "Suspended"
             // Release all the RTP sessions we are using
diff --git a/src/SipSession.h b/src/SipSession.h
index 10faf86..744b9ed 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -33,11 +33,11 @@
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.h>
 #include <AsteriskSCF/Media/MediaIf.h>
 #include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
 #include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
 #include <AsteriskSCF/System/NAT/NATTraversalIf.h>
 
 #include <SipStateReplicationIf.h>
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -113,14 +113,14 @@ public:
     SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
         const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const PJSipManagerPtr& manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         bool ipv6, bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
 
     SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&, const Ice::Identity&, const Ice::Identity&,
         const Ice::Identity&, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq&,
         const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&,
         const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
 
     bool operator==(const SipSession &other) const;
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
deleted file mode 100644
index 59dbf37..0000000
--- a/src/SipSessionManagerApp.cpp
+++ /dev/null
@@ -1,709 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010, 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 <pjlib.h>
-
-#include <Ice/Ice.h>
-#include <IceStorm/IceStorm.h>
-#include <IceBox/IceBox.h>
-#include <IceUtil/UUID.h>
-
-#include <boost/thread.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <AsteriskSCF/Core/Routing/RoutingIf.h>
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
-#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
-#include <AsteriskSCF/Discovery/SmartProxy.h>
-#include <AsteriskSCF/System/Component/ConfigurationIf.h>
-
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include <AsteriskSCF/logger.h>
-
-#include "SipSessionManagerEventPublisher.h"
-#include "SipSessionManagerEndpointLocator.h"
-#include "SipEndpointFactory.h"
-#include "PJSipSessionModule.h"
-#include "PJSipManager.h"
-#include "SipSession.h"
-#include "SipStateReplicator.h"
-#include "SipConfiguration.h"
-#include "SipRegistrarListener.h"
-
-using namespace std;
-using namespace AsteriskSCF::SipSessionManager;
-using namespace AsteriskSCF::Configuration::SipSessionManager::V1;
-using namespace AsteriskSCF::Core;
-using namespace AsteriskSCF::Core::Routing::V1;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::System::Component::V1;
-using namespace AsteriskSCF::System::Logging;
-using namespace AsteriskSCF::System::Hook::V1;
-using namespace AsteriskSCF::SessionCommunications::V1;
-using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
-using namespace AsteriskSCF::System::Configuration::V1;
-using namespace AsteriskSCF::SIP::Registration::V1;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
-}
-
-namespace AsteriskSCF
-{
-namespace SipSessionManager
-{
-
-class SipAuthExtensionPoint : public AuthExtensionPoint
-{
-public:
-    SipAuthExtensionPoint(const PJSipManagerPtr& manager)
-        : mPJSipManager(manager)
-    {
-    }
-    
-    void addAuthHook(
-            const AuthHookPrx &hook,
-            int priority,
-            const RequestTypeSeq &requestTypes,
-            const Ice::Current&)
-    {
-        mPJSipManager->addAuthHook(hook, priority, requestTypes);
-    }
-    
-    void removeAuthHook(const AuthHookPrx &hook, const Ice::Current&)
-    {
-        mPJSipManager->removeAuthHook(hook);
-    }
-    
-    void clearAuthHooks(const Ice::Current&)
-    {
-        mPJSipManager->clearAuthHooks();
-    }
-private:
-    PJSipManagerPtr mPJSipManager;
-};
-
-typedef IceUtil::Handle<SipAuthExtensionPoint> SipAuthExtensionPointPtr;
-
-/**
- * This private class initializes the startup and controls the shutdown of the component.
- */
-class SipSessionManager : public IceBox::Service
-{
-public:
-    SipSessionManager() : mDone(false) {}
-    ~SipSessionManager() { }
-
-public:
-    // Overloads of IceBox::Service
-    virtual void start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
-    virtual void stop();
-
-private:
-    void initialize(const string& appName, const Ice::CommunicatorPtr& ic);
-    void registerWithServiceLocator();
-    void deregisterFromServiceLocator();
-    void setCategory(const ServiceManagementPrx& serviceManagement, const string &category);
-    void locateRoutingService();
-    void locateSessionRouter();
-    void locateStateReplicator();
-    void registerWithStateReplicator();
-    void registerWithRoutingService();
-    void deregisterFromRoutingService();
-    void registerPJSipModules();
-    void deregisterFromStateReplicator();
-
-    bool mDone;
-    std::string mAppName;
-    Ice::CommunicatorPtr mCommunicator;
-
-    std::string mRoutingId;
-
-    // The global object adapter is for shared services that could be replicated from another server
-    Ice::ObjectAdapterPtr mGlobalAdapter;
-
-    // The local object adapter is for services unique to this instance of the service
-    Ice::ObjectAdapterPtr mLocalAdapter;
-
-    ServiceLocatorManagementPrx mServiceLocatorManagement;
-
-    ServiceManagementPrx mComponentServiceManagement;
-    ServiceManagementPrx mConfigurationManagement;
-    ServiceManagementPrx mAuthServiceManagement;
-    std::string mConfigCompareGuid;
-    ReplicaPtr mReplicaService;
-    ComponentServicePtr mComponentService;
-    ConfigurationServicePtr mConfigurationService;
-    ConfigurationServicePrx mConfigurationServiceProxy;
-    PJSipManagerPtr mPJSipManager;
-    SipStateReplicatorListenerPtr mReplicatorListener;
-    SipStateReplicatorListenerPrx mReplicatorListenerProxy;
-    boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
-    ServiceLocatorPrx mServiceLocator;
-    AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> mStateReplicator;
-    AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> mSessionRouter;
-    AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> mRoutingServiceLocatorRegistry;
-    boost::shared_ptr<SipSessionManagerEventPublisher> mEventPublisher;
-    Routing::V1::EndpointLocatorPtr mEndpointLocator;
-    SipAuthExtensionPointPtr mAuthService;
-    RegistrarListenerPtr mRegistrarListener;
-};
-
-static const string ComponentServiceId("SipChannelComponent");
-static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
-static const string ReplicaServiceId("SipChannelReplica");
-static const string AuthServiceId("SipAuthExtensionPoint");
-static const string RegistrarListenerId("SipRegistrarListener");
-
-/**
- * This class provides implementation for the ComponentService interface, which
- * every Asterisk SCF component is expected to publish.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
-    ComponentServiceImpl(SipSessionManager &service) : mService(service) {}
-
-public: // Overrides of the ComponentService interface.
-    virtual void suspend(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-    virtual void resume(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-    virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-private:
-    SipSessionManager& mService; // TODO reference?
-};
-
-/**
- * This class provides implementation for the Replica interface.
- */
-class ReplicaImpl : public Replica
-{
-public:
-    ReplicaImpl(const Ice::ObjectAdapterPtr& adapter) : mAdapter(adapter), mPaused(false), mActive(true) { }
-
-    bool isActive(const Ice::Current&)
-    {
-        return mActive;
-    }
-
-    bool activate(const Ice::Current&)
-    {
-        mActive = true;
-
-        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&)
-    {
-        mActive = false;
-
-        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:
-    /**
-     * 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 mPaused;
-
-    bool mActive;
-};
-
-/**
- * Comparator implementation for name based configuration service locating
- */
-class SipConfigurationCompare : public ServiceLocatorParamsCompare
-{
-public:
-    SipConfigurationCompare(const string& name) : mName(name) {}
-    bool isSupported(const ServiceLocatorParamsPtr &params, const Ice::Current &)
-    {
-        SipConfigurationParamsPtr configParams = SipConfigurationParamsPtr::dynamicCast(params);
-        if (configParams->name == mName)
-        {
-            return true;
-        }
-        return false;
-    }
-private:
-    string mName;
-};
-
-typedef IceUtil::Handle<SipConfigurationCompare> SipConfigurationComparePtr;
-
-/**
- * Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
- * other components can look up our interfaces.
- */
-void SipSessionManager::setCategory(const ServiceManagementPrx& serviceManagement, const string &category)
-{
-    // Add category as a parameter to enable other components look this component up.
-    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
-    genericparams->category = category;
-    serviceManagement->addLocatorParams(genericparams, "");
-}
-
-/**
- * Register this component's primary public interfaces with the Service Locator.
- * This enables other Asterisk SCF components to locate our interfaces.
- */
-void SipSessionManager::registerWithServiceLocator()
-{
-    try
-    {
-        // Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system
-        // discovery mechanisms.
-        mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(
-            mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
-
-        if (mServiceLocatorManagement == 0)
-        {
-            lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected.";
-            return;
-        }
-
-        // Get a proxy to our ComponentService interface and add it to the Service Locator.
-        Ice::ObjectPrx componentServiceObjectPrx =
-            mLocalAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
-        ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-
-        // The GUID passed in to add service needs to be unique for reporting.
-        string componentServiceGuid("SipSessionManager");
-        mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(
-            mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
-
-        setCategory(mComponentServiceManagement, AsteriskSCF::SIP::V1::ComponentServiceDiscoveryCategory);
-
-        // Hey look we have an Auth extension point to publish!
-        Ice::ObjectPrx authObjPrx = mLocalAdapter->createDirectProxy(mCommunicator->stringToIdentity(AuthServiceId));
-        AuthExtensionPointPrx authPrx = AuthExtensionPointPrx::checkedCast(authObjPrx);
-
-        std::string authServiceGuid("SipAuthExtensionPoint");
-        mAuthServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(authPrx, authServiceGuid));
-        setCategory(mAuthServiceManagement, AsteriskSCF::SIP::V1::AuthExtensionPointCategory);
-        if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.Standalone", "false") == "true")
-        {
-            // Publish the configuration service IceStorm topic so everybody gets configuration
-            mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
-        	mServiceLocatorManagement->addService(mConfigurationServiceProxy, ""));
-        
-            // Populate the configuration parameters with details so we can be found
-            SipConfigurationParamsPtr configurationParams = new SipConfigurationParams();
-            configurationParams->category = ConfigurationDiscoveryCategory;
-            configurationParams->name = mCommunicator->getProperties()->getPropertyWithDefault("SipConfiguration.Name", "");
-        
-            // Add our custom comparator so we can support multiple simultaneous configuration sinks
-            SipConfigurationComparePtr configNameCompare = new SipConfigurationCompare(configurationParams->name);
-            ServiceLocatorParamsComparePrx configCompareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
-        	mLocalAdapter->addWithUUID(configNameCompare));
-        
-            mConfigCompareGuid = IceUtil::generateUUID();
-            mServiceLocatorManagement->addCompare(mConfigCompareGuid, configCompareProxy);
-            mConfigurationManagement->addLocatorParams(configurationParams, mConfigCompareGuid);
-        }
-
-        // TBD... We may have other interfaces to publish to the Service Locator.
-    }
-    catch(...)
-    {
-        lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()";
-    }
-}
-
-/**
- * Register our own Endpoint Locator with the Routing Service so that
- * the endpoints that this channel manages can be accessed from any
- * Session Manager in the Asterisk SCF system.
- */
-void SipSessionManager::registerWithRoutingService()
-{
-    RegExSeq destinations;
-
-    mEndpointFactory->generateRoutingDestinations(destinations);
-
-    EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
-        mGlobalAdapter->createDirectProxy(mCommunicator->stringToIdentity(EndpointLocatorObjectId)));
-    mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
-}
-
-/**
- * Deregister our own Endpoint Locator from the Routing SErvice.
- */
-void SipSessionManager::deregisterFromRoutingService()
-{
-    mRoutingServiceLocatorRegistry->removeEndpointLocator(mRoutingId);
-}
-
-/**
- * Get a reference to the Routing Service interface that we care about, and cache it in the Data Model.
- * This will allow us to lookup endpoints anywhere in the Asterisk SCF system.
- */
-void SipSessionManager::locateRoutingService()
-{
-    if (mServiceLocator == 0)
-    {
-        mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-    }
-
-    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
-    genericparams->category = Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
-
-    AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> pw(mServiceLocator, genericparams, lg);
-    mRoutingServiceLocatorRegistry = pw;
-
-    // This exists here since it may need to be known before actually contacting the routing service
-    mRoutingId = mCommunicator->getProperties()->getPropertyWithDefault("Sip.RoutingId", "pjsip");
-}
-
-void SipSessionManager::locateStateReplicator()
-{
-    if (mServiceLocator == 0)
-    {
-        mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-    }
-
-    SipStateReplicatorParamsPtr replicatorParams = new SipStateReplicatorParams();
-    replicatorParams->category = StateReplicatorDiscoveryCategory;
-    replicatorParams->name =
-        mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorName", "default");
-
-    try
-    {
-        AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(mServiceLocator, replicatorParams, lg);
-        mStateReplicator = pw;
-    }
-    catch (...)
-    {
-        lg(Error) << "State replicator could not be found, operating without.";
-    }
-}
-
-void SipSessionManager::registerWithStateReplicator()
-{
-    if (mStateReplicator == 0)
-    {
-        return;
-    }
-
-    if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.Standalone", "false") == "false")
-    {
-	ConfigurationReplicatorPrx configurationReplicator = ConfigurationReplicatorPrx::checkedCast(
-	    mStateReplicator.initialize(), ReplicatorFacet);
-	configurationReplicator->registerConfigurationService(mConfigurationServiceProxy);
-    }
-
-    if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorListener", "no") == "yes")
-    {
-        mStateReplicator->addListener(mReplicatorListenerProxy);
-        mReplicaService->standby();
-    }
-}
-
-/**
- * Get a reference to the Session Routing Service interface that we care about, and cache it in the Data Model.
- * This will allow us to route sessions.
- */
-void SipSessionManager::locateSessionRouter()
-{
-    if (mServiceLocator == 0)
-    {
-        mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-    }
-
-    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
-    genericparams->category = Routing::V1::SessionRouterDiscoveryCategory;
-
-    AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> pw(mServiceLocator, genericparams, lg);
-    mSessionRouter = pw;
-}
-
-/**
- * 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.
- */
-void SipSessionManager::deregisterFromServiceLocator()
-{
-    try
-    {
-        mComponentServiceManagement->unregister();
-	if (mConfigurationManagement)
-	{
-	    mConfigurationManagement->unregister();
-	}
-    }
-    catch(...)
-    {
-        lg(Error) << "Had trouble in deregisterFromServiceLocator().";
-    }
-}
-
-void SipSessionManager::registerPJSipModules()
-{
-    Ice::PropertiesPtr props = mCommunicator->getProperties();
-    Ice::StringSeq moduleNames = props->getPropertyAsList("Sip.Modules");
-    for (Ice::StringSeq::iterator i = moduleNames.begin();
-         i != moduleNames.end();
-         ++i)
-    {
-        //We should probably delegate the responsibility of mapping
-        //module names to modules to the PJSIP session manager instead.
-        //Since there's only a single configurable module at the moment,
-        //we'll just do it here instead.
-        if (*i == "Session")
-        {
-            mPJSipManager->registerSessionModule(mEndpointFactory,
-                mSessionRouter, mServiceLocator, mStateReplicator, mReplicaService, mGlobalAdapter, mServiceLocatorManagement);
-        }
-        else if (*i == "Logging" || *i == "Logger")
-        {
-            mPJSipManager->registerLoggingModule();
-        }
... 421 lines suppressed ...


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list