[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "basecomponentsquash" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Aug 2 15:15:47 CDT 2011


branch "basecomponentsquash" has been created
        at  eced3288035be10a4b390bbb434fa8afe4e3ad92 (commit)

- Log -----------------------------------------------------------------
commit eced3288035be10a4b390bbb434fa8afe4e3ad92
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jun 28 20:53:16 2011 -0500

    Changes required for using a base Component class and also changes to ServiceLocator.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index 980cded..adb4c0f 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -170,8 +170,9 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             self.visit_endpoint(config, section)
 
 # In order to do service locator based lookup we need to pass in a params object
-serviceLocatorParams = AsteriskSCF.SIP.V1.SipConfigurationParams()
+serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
 serviceLocatorParams.category = AsteriskSCF.SIP.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 b96ee9c..640ef9f 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/local-slice/SipConfigurationIf.ice b/local-slice/SipConfigurationIf.ice
index ddfe65d..ee45b3a 100644
--- a/local-slice/SipConfigurationIf.ice
+++ b/local-slice/SipConfigurationIf.ice
@@ -33,17 +33,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/local-slice/SipStateReplicationIf.ice b/local-slice/SipStateReplicationIf.ice
index aae6991..43b71c2 100644
--- a/local-slice/SipStateReplicationIf.ice
+++ b/local-slice/SipStateReplicationIf.ice
@@ -32,11 +32,6 @@ module V1
    const string StateReplicatorComponentCategory = "SipStateReplicatorComponent";
    const string StateReplicatorDiscoveryCategory = "SipStateReplicator";
 
-   unsliceable class SipStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
-   {
-      string mName;
-   };
-
    class SipStateItem
    {
       string key;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5aa8e59..eb4f032 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,8 @@ include_directories(${API_INCLUDE_DIR})
 asterisk_scf_slice_include_directories(${API_SLICE_DIR})
 
 asterisk_scf_component_init(SipSessionManager)
-asterisk_scf_component_add_file(SipSessionManager SipSessionManagerApp.cpp)
+asterisk_scf_component_add_file(SipSessionManager Component.cpp)
+asterisk_scf_component_add_file(SipSessionManager SipReplicationContext.h)
 asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEventPublisher.cpp)
 asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEventPublisher.h)
 asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEndpointLocator.cpp)
diff --git a/src/Component.cpp b/src/Component.cpp
new file mode 100644
index 0000000..521c0ef
--- /dev/null
+++ b/src/Component.cpp
@@ -0,0 +1,568 @@
+/*
+ * 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 "SipReplicationContext.h"
+
+using namespace std;
+using namespace AsteriskSCF::SipSessionManager;
+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::SessionCommunications::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
+{
+
+/**
+ * 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, AsteriskSCF::SIP::V1::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 configureEndpoints();
+    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;
+    PJSipManager *mPJSipManager;
+
+    // Remote references
+    AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> mSessionRouter;
+    AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> mRoutingServiceLocatorRegistry;
+};
+
+static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
+static const string ReplicaServiceId("SipChannelReplica");
+
+/**
+ * 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()
+{
+    // This is a required override. As a gateway, this component doesn't expose 
+    // any interfaces on it's primary service adapter. 
+}
+
+/**
+ * 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 = SIP::V1::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::configureEndpoints()
+{
+    // NOTE: This is probably gone in latest branch. 
+    Ice::PropertiesPtr props = getCommunicator()->getProperties();
+    Ice::StringSeq endpointNames = props->getPropertyAsList("Sip.Endpoints");
+    for (Ice::StringSeq::iterator i = endpointNames.begin();
+         i != endpointNames.end();
+         ++i)
+    {
+        SipEndpointPtr endpoint = mEndpointFactory->createEndpoint(*i, props);
+    }
+}
+
+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);
+        }
+        else if ((*i) == "Logging" || (*i) == "Logger")
+        {
+            mPJSipManager->registerLoggingModule();
+        }
+    }
+    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 = new PJSipManager(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
+    {
+        // NOTE: This goes away in merge. 
+        configureEndpoints();
+
+        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";
+    }
+    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();
+
+    //
+    // TODO: This is probably a mistake. Many things access the PJSipManager instance and will continue
+    // to do so until all of the threads have completed. It really should be reference counted.
+    //
+    delete mPJSipManager;
+}
+
+extern "C"
+{
+ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new Component;
+}
+}
+
+}; // end SipSessionManager
+}; // end AsteriskSCF
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index ffd2854..6e7aebd 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -80,12 +80,11 @@ 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<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
+        const SipReplicationContextPtr& stateReplicationContext
     )
 {
     mSessionModule = new PJSipSessionModule(mEndpoint, endpointFactoryPtr, sessionRouter,
-        serviceLocator, stateReplicator, replica);
+        serviceLocator, stateReplicationContext);
 }
 
 void PJSipManager::registerLoggingModule()
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 9138770..6224419 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -30,6 +30,7 @@
 
 #include "PJSipSessionModule.h"
 #include "PJSipLoggingModule.h"
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -73,8 +74,7 @@ public:
         const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
             sessionRouter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
+        const SipReplicationContextPtr& stateReplicationContext
         );
 
     /**
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 74fe6f3..80b3ae5 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -19,7 +19,7 @@
 #include "SipEndpointFactory.h"
 #include "SipSession.h"
 #include "PJSipManager.h"
-#include "SipStateReplicator.h"
+#include "SipReplicationContext.h"
 
 #include <IceUtil/UUID.h>
 
@@ -251,56 +251,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.";
-            }
-
-            AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator = 
-                AsteriskSCF::SIP::V1::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.";
-            }
-
-            AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator =
-                AsteriskSCF::SIP::V1::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 73fd186..ffa799b 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"
 
@@ -89,8 +89,7 @@ public:
         const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
             sessionRouter,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
+        const SipReplicationContextPtr& replicationContext);
     pj_status_t load(pjsip_endpoint *endpoint);
     pj_status_t start();
     pj_status_t stop();
@@ -126,8 +125,7 @@ private:
     boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
     AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> mSessionRouter;
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
-    AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::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 14e0718..bcdd1c2 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -101,11 +101,10 @@ 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<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
-    const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
+        const SipReplicationContextPtr& replicationContext)
     : mName(moduleName), mEndpointFactory(endpointFactoryPtr),
       mSessionRouter(sessionRouter), mServiceLocator(serviceLocator),
-      mStateReplicator(stateReplicator), mReplica(replica), mEndpoint(endpt)
+      mReplicationContext(replicationContext), mEndpoint(endpt)
 {
     sessionModule = this;
     mModule.name = pj_str(moduleName);
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 3ff806f..7db57a1 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -46,9 +46,9 @@ public:
     SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
             const std::string& name, PJSipManager *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)
     {
     };
     
@@ -95,7 +95,7 @@ public:
     /**
      *
      */
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
 };
 
 /**
@@ -104,8 +104,8 @@ public:
 SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
         const std::string& name, const Ice::PropertyDict& props, PJSipManager *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 SipReplicationContextPtr& replicationContext)
+    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
 {
     lg(Debug) << "Constructing SIP endpoint " << name;
 
@@ -117,8 +117,8 @@ SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shar
 }
 
 SipEndpoint::SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, PJSipManager *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 AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const SipReplicationContextPtr& replicationContext)
+    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
 {
     lg(Debug) << "Constructing SIP endpoint " << name;
 
@@ -277,7 +277,7 @@ 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->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, true);
     mImplPriv->mSessions.push_back(session);
     std::cout << "And now we're returing a session proxy..." << std::endl;
     return session->getSessionProxy();
@@ -286,7 +286,7 @@ 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->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false);
     mImplPriv->mSessions.push_back(session);
     return session;
 }
@@ -297,7 +297,7 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
         const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
 {
     SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, mediaid, mediasession,
-            sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica, false);
+            sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, false);
     mImplPriv->mSessions.push_back(session);
     return session;
 }
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 40a8e25..21cdd62 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -34,7 +34,7 @@
 #include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
 
 #include "SipSession.h"
-
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -214,10 +214,10 @@ public:
     SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
             const std::string& name, const Ice::PropertyDict& props, PJSipManager *manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-            const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
+            const SipReplicationContextPtr& replicationContext);
 
     SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, PJSipManager *manager,
-        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica);
+        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const SipReplicationContextPtr& replicationContext);
 
     bool operator==(const std::string &name) const;
 
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index 09c4704..e5a1892 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -28,14 +28,15 @@ SipEndpointPtr SipEndpointFactory::createEndpoint(const std::string& destination
     prefix.append(destination);
     Ice::PropertyDict endpointProps = props->getPropertiesForPrefix(prefix);
     SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), destination, endpointProps, mManager,
-            mServiceLocator, mReplica);
+            mServiceLocator, mReplicationContext);
     mEndpoints.push_back(endpoint);
     return endpoint;
 }
 
 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 48cfd97..6d75b84 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -21,6 +21,7 @@
 #include <boost/enable_shared_from_this.hpp>
 
 #include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -37,8 +38,8 @@ class SipEndpointFactory : public boost::enable_shared_from_this<SipEndpointFact
 public:
     SipEndpointFactory(const Ice::ObjectAdapterPtr& adapter, PJSipManager *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(const std::string& destination, const Ice::PropertiesPtr& props);
 
@@ -73,7 +74,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..bf2021d
--- /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::SIP::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 63df653..92ab1b1 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -86,9 +86,9 @@ public:
     SipSessionPriv(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
         const std::string& destination, PJSipManager *manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
+        const SipReplicationContextPtr& replicationContext)
         : mAdapter(adapter), mDialog(0), mInviteSession(0), mEndpoint(endpoint), mDestination(destination),
-          mManager(manager), mServiceLocator(serviceLocator), mReplica(replica) { };
+          mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext) { };
 
     AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo()
     {
@@ -245,7 +245,7 @@ public:
 
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
 
-    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+    SipReplicationContextPtr mReplicationContext;
 
     SessionWorkPtr mSessionWork;
 };
@@ -313,8 +313,8 @@ void SipSession::initializePJSIPStructs()
 SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
         const std::string& destination,  const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
         PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool ipv6, bool isUAC)
-    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica))
+        const SipReplicationContextPtr& replicationContext, bool ipv6, bool isUAC)
+    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext))
 {
     if (listener != 0)
     {
@@ -346,8 +346,8 @@ SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPt
         const Ice::Identity& mediaid, const AsteriskSCF::Media::V1::SessionPrx& mediasession,
         const AsteriskSCF::Media::V1::StreamSourceSeq& sources, const AsteriskSCF::Media::V1::StreamSinkSeq& sinks,
         PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool isUAC)
-    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica))
+        const SipReplicationContextPtr& replicationContext, bool isUAC)
+    : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext))
 {
     mImplPriv->mSessionProxy =
         AsteriskSCF::SessionCommunications::V1::SessionPrx::uncheckedCast(adapter->add(this, sessionid));
@@ -853,7 +853,7 @@ public:
         mSessionPriv->mAdapter->remove(mSessionPriv->mMediaSessionProxy->ice_getIdentity());
         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 2a60c76..d737bd7 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -32,10 +32,10 @@
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.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 <SipStateReplicationIf.h>
+#include "SipReplicationContext.h"
 
 namespace AsteriskSCF
 {
@@ -96,14 +96,14 @@ public:
     SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
         const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, PJSipManager *manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         bool ipv6, bool isUAC);
 
     SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&, const Ice::Identity&,
         const Ice::Identity&, const AsteriskSCF::Media::V1::SessionPrx&,
         const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&,
         PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+        const SipReplicationContextPtr& replicationContext,
         bool isUAC);
 
     bool operator==(const SipSession &other) const;
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
deleted file mode 100644
index 7e4bb4e..0000000
--- a/src/SipSessionManagerApp.cpp
+++ /dev/null
@@ -1,663 +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"
-
-using namespace std;
-using namespace AsteriskSCF::SipSessionManager;
-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::SessionCommunications::V1;
-using namespace AsteriskSCF::System::Configuration::V1;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
-}
-
-namespace AsteriskSCF
-{
-namespace SipSessionManager
-{
-
-/**
- * This private class initializes the startup and controls the shutdown of the component.
- */
-class SipSessionManager : public IceBox::Service
-{
-public:
-    SipSessionManager() : mDone(false) {}
-    ~SipSessionManager()
-    {
-        // Smart pointers do your thing.
-        mReplicaService = 0;
-        mComponentService = 0;
-	mConfigurationService = 0;
-        mGlobalAdapter = 0;
-        mLocalAdapter = 0;
-    }
-
-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 configureEndpoints();
-    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;
-    std::string mConfigCompareGuid;
-    ReplicaPtr mReplicaService;
-    ComponentServicePtr mComponentService;
-    ConfigurationServicePtr mConfigurationService;
-    ConfigurationServicePrx mConfigurationServiceProxy;
-    PJSipManager *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;
-};
-
-static const string ComponentServiceId("SipChannelComponent");
-static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
-static const string ReplicaServiceId("SipChannelReplica");
-
-/**
- * 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);
-
-	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"));
-    }
-
-    SIP::V1::SipStateReplicatorParamsPtr replicatorParams = new SIP::V1::SipStateReplicatorParams();
-    replicatorParams->category = SIP::V1::StateReplicatorDiscoveryCategory;
-    replicatorParams->mName =
-        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::configureEndpoints()
-{
-    Ice::PropertiesPtr props = mCommunicator->getProperties();
-    Ice::StringSeq endpointNames = props->getPropertyAsList("Sip.Endpoints");
-    for (Ice::StringSeq::iterator i = endpointNames.begin();
-         i != endpointNames.end();
-         ++i)
-    {
-        SipEndpointPtr endpoint = mEndpointFactory->createEndpoint(*i, props);
-    }
-}
-
-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);
-        }
-        else if (*i == "Logging" || *i == "Logger")
-        {
-            mPJSipManager->registerLoggingModule();
-        }
-    }
-    lg(Debug) << "Registered PJSIP modules";
-}
-
-void SipSessionManager::deregisterFromStateReplicator()
-{
-    if (!mConfigCompareGuid.empty())
-    {
-        mServiceLocatorManagement->removeCompare(mConfigCompareGuid);
-    }
-
-    if (mConfigurationManagement)
-    {
-	mConfigurationManagement->unregister();
-    }
-
-    if (mReplicaService->isActive() == true)
-    {
-        return;
-    }
-
-    mStateReplicator->removeListener(mReplicatorListenerProxy);
-}
-
-/**
- * Create the primary functional objects of this component.
- *   @param appName Name of the application or component.
- */
-void SipSessionManager::initialize(const string& appName, const Ice::CommunicatorPtr& ic)
-{
-    try
-    {
-        mAppName = appName;
-
-        // Initialize PJSIP
-        mPJSipManager = new PJSipManager(ic->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 = ic->getProperties();
-
-        mCommunicator = Ice::initialize(id);
-
-        // Create the global adapter.
-        mGlobalAdapter = mCommunicator->createObjectAdapter("SipSessionManagerAdapter");
-        lg(Debug) << "Created global object adapter";
-
-        // Create the local adapter.
-        mLocalAdapter = mCommunicator->createObjectAdapter("SipSessionManagerLocalAdapter");
-        lg(Debug) << "Created local object adapter";
-
-        mEventPublisher.reset(new SipSessionManagerEventPublisher(mLocalAdapter));
-        lg(Debug) << "Created SIP Session Manager event publisher";
-
-        // We're not actually registering with the service locator at this point, but
-        // several components we create could really use the proxy, so we create
-        // it now.
-        mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-
-        // Create and publish our Replica interface support.
-        mReplicaService = new ReplicaImpl(mLocalAdapter);
-        mLocalAdapter->add(mReplicaService, mCommunicator->stringToIdentity(ReplicaServiceId));
-        lg(Debug) << "Created SIP Replica Implementation";
-
-        mEndpointFactory.reset(new SipEndpointFactory(mGlobalAdapter, mPJSipManager, mServiceLocator, mReplicaService));
-        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.
-	locateRoutingService();
-
-        // Create and publish our Configuration interface support.
-        mConfigurationService = createConfigurationServant(mPJSipManager, mEndpointFactory, mRoutingId, mRoutingServiceLocatorRegistry);
-        mConfigurationServiceProxy = ConfigurationServicePrx::uncheckedCast(mLocalAdapter->addWithUUID(
-		mConfigurationService));
-        lg(Debug) << "Created SIP Configuration Implementation";
-
-        // Create and configure our Endpoint Locator.
-        mEndpointLocator = new SipSessionManagerEndpointLocator(mEndpointFactory);
-        mGlobalAdapter->add(mEndpointLocator, mCommunicator->stringToIdentity(EndpointLocatorObjectId));
-        lg(Debug) << "Got proxy to endpoint locator";
-
-        // Create and publish our ComponentService interface support.
-        mComponentService = new ComponentServiceImpl(*this);
-        mLocalAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId));
-        lg(Debug) << "Added component service to object adapter";
-
-        // Create and publish our state replicator listener interface.
-        mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory, mPJSipManager);
-        mReplicatorListenerProxy =
-            SipStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
-        lg(Debug) << "Got proxy to SIP state replicator";
-
-        mGlobalAdapter->activate();
-        mLocalAdapter->activate();
-        lg(Debug) << "Activated object adapters";
-
-        configureEndpoints();
-        lg(Debug) << "Endpoints configured";
-    }
-    catch(...)
-    {
-        lg(Critical) << "Major problems in " << mAppName << " initialization()";
-    }
-}
-
-/**
- * Overload of the IceBox::Service::start method.
- */
-void SipSessionManager::start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq&)
-{
-    // Initialize this component.
-    initialize(name, ic);
-
-    // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-    // can be located.
-    registerWithServiceLocator();
-
-    // Locate the Session Router so we can REALLY do routing.
-    locateSessionRouter();
-
-    // Locate the State Replicator so we can fail over!
-    locateStateReplicator();
-
-    registerPJSipModules();
-
-    // Register with the state replicator if we are a listener
-    registerWithStateReplicator();
-
-    // Register our Endpoint Locator so that we can provide endpoints to the
-    // Routing Service for the endpoints we manage.
-    if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorListener", "no") != "yes")
-    {
-        //Only register with the routing service if we're the primary SIP instance.
-        registerWithRoutingService();
-    }
-}
-
-/**
- * Overload of the IceBox::Service::stop method.
- */
-void SipSessionManager::stop()
-{
-    // Remove our interfaces from the service locator.
-    deregisterFromServiceLocator();
-
-    // Remove our endpoint locator from the routing service.
-    deregisterFromRoutingService();
-
-    // Remove our state listener
-    deregisterFromStateReplicator();
-
-    //
-    // TODO: This is probably a mistake. Many things access the PJSipManager instance and will continue
-    // to do so until all of the threads have completed. It really should be reference counted.
-    //
-    delete mPJSipManager;
-    mCommunicator->destroy();
-}
-
-extern "C"
-{
-ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
-{
-    return new SipSessionManager;
-}
-}
-
-}; // end SipSessionManager
-}; // end AsteriskSCF
diff --git a/src/SipStateReplicatorApp.cpp b/src/SipStateReplicatorApp - Copy.cpp
similarity index 87%
copy from src/SipStateReplicatorApp.cpp
copy to src/SipStateReplicatorApp - Copy.cpp
index a93b109..868fa7c 100644
--- a/src/SipStateReplicatorApp.cpp
+++ b/src/SipStateReplicatorApp - Copy.cpp	
@@ -112,44 +112,6 @@ private:
     SipStateReplicatorService& mService; // TODO: Reference?
 };
 
-class SipStateReplicatorCompare : public ServiceLocatorParamsCompare
-{
-public:
-    SipStateReplicatorCompare(const string&  name) : mName(name) {}
-    bool isSupported(const ServiceLocatorParamsPtr &params, const Ice::Current &)
-    {
-        SipStateReplicatorParamsPtr sipParams = SipStateReplicatorParamsPtr::dynamicCast(params);
-        if (sipParams->mName == mName)
-        {
-            return true;
-        }
-        return false;
-    }
-private:
-    string mName;
-};
-
-typedef IceUtil::Handle<SipStateReplicatorCompare> SipStateReplicatorComparePtr;
-
-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;
-
 class ConfigurationReplicatorI : public ConfigurationReplicator
 {
 public:
@@ -222,11 +184,14 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
 
         ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams();
         discoveryParams->category = AsteriskSCF::SIP::V1::StateReplicatorDiscoveryCategory;
+        discoveryParams->service = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Service", "default");
 
-        string replicatorName = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Name", "default");
-        SipStateReplicatorCompare* nameCompare = new SipStateReplicatorCompare(replicatorName);
+        ServiceLocatorParamsPtr nameParams = new ServiceLocatorParams;
+        nameParams->category = AsteriskSCF::SIP::V1::StateReplicatorDiscoveryCategory;
+        nameParams->service = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Service", "default");
+        nameParams->id = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Name", "default");
         ServiceLocatorParamsComparePrx compareProxy =
-            ServiceLocatorParamsComparePrx::uncheckedCast(mAdapter->addWithUUID(nameCompare));
+            ServiceLocatorParamsComparePrx::uncheckedCast(mAdapter->addWithUUID(nameParams));
 
         string compareGuid = IceUtil::generateUUID();
         mServiceLocatorManagement->addCompare(compareGuid, compareProxy);
@@ -237,12 +202,15 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
             mServiceLocatorManagement->addService(mConfigurationPublisher, ""));
 
         // Populate the configuration parameters with details so we can be found
-        SipConfigurationParamsPtr configurationParams = new SipConfigurationParams();
+        ServiceLocatorParamsPtr configurationParams = new ServiceLocatorParams();
         configurationParams->category = ConfigurationDiscoveryCategory;
-        configurationParams->name = ic->getProperties()->getPropertyWithDefault("SipConfiguration.Name", "");
+        configurationParams->service = ic->getProperties()->getPropertyWithDefault("SipConfiguration.Service", "default");
+        configurationParams->id = ic->getProperties()->getPropertyWithDefault("SipConfiguration.Name", "");
 
         // Add our custom comparator so we can support multiple simultaneous configuration sinks
-        SipConfigurationComparePtr configNameCompare = new SipConfigurationCompare(configurationParams->name);
+        ServiceLocatorParamsPtr configNameCompare = new ServiceLocatorParams;
+        configurationParams->category = ConfigurationDiscoveryCategory;
+        configNameCompare->id = configurationParams->id;
         ServiceLocatorParamsComparePrx configCompareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
             mAdapter->addWithUUID(configNameCompare));
 
diff --git a/src/SipStateReplicatorApp.cpp b/src/SipStateReplicatorApp.cpp
index a93b109..28ed3cb 100644
--- a/src/SipStateReplicatorApp.cpp
+++ b/src/SipStateReplicatorApp.cpp
@@ -112,44 +112,6 @@ private:
     SipStateReplicatorService& mService; // TODO: Reference?
 };
 
-class SipStateReplicatorCompare : public ServiceLocatorParamsCompare
-{
-public:
-    SipStateReplicatorCompare(const string&  name) : mName(name) {}
-    bool isSupported(const ServiceLocatorParamsPtr &params, const Ice::Current &)
-    {
-        SipStateReplicatorParamsPtr sipParams = SipStateReplicatorParamsPtr::dynamicCast(params);
-        if (sipParams->mName == mName)
-        {
-            return true;
-        }
-        return false;
-    }
-private:
-    string mName;
-};
-
-typedef IceUtil::Handle<SipStateReplicatorCompare> SipStateReplicatorComparePtr;
-
-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;
-
 class ConfigurationReplicatorI : public ConfigurationReplicator
 {
 public:
@@ -222,33 +184,20 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
 
         ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams();
         discoveryParams->category = AsteriskSCF::SIP::V1::StateReplicatorDiscoveryCategory;
-
-        string replicatorName = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Name", "default");
-        SipStateReplicatorCompare* nameCompare = new SipStateReplicatorCompare(replicatorName);
-        ServiceLocatorParamsComparePrx compareProxy =
-            ServiceLocatorParamsComparePrx::uncheckedCast(mAdapter->addWithUUID(nameCompare));
-
-        string compareGuid = IceUtil::generateUUID();
-        mServiceLocatorManagement->addCompare(compareGuid, compareProxy);
-        mStateReplicationManagement->addLocatorParams(discoveryParams, compareGuid);
+        discoveryParams->service = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Service", "default");
+        discoveryParams->id = ic->getProperties()->getPropertyWithDefault("SipStateReplicator.Name", "default");
... 28 lines suppressed ...


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list