[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "bridge_creation_extension_points" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Aug 12 09:57:12 CDT 2011


branch "bridge_creation_extension_points" has been created
        at  fea2dfd0fbe4cb77b2a210dca6ffa55d01f48a30 (commit)

- Log -----------------------------------------------------------------
commit fea2dfd0fbe4cb77b2a210dca6ffa55d01f48a30
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Aug 12 11:43:06 2011 -0230

    bridge creation extension point support

diff --git a/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice b/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
index 5a7892c..a9a1e5b 100644
--- a/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
+++ b/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
@@ -187,6 +187,12 @@ class BridgeStateItem extends ReplicatedStateItem
     string bridgeId;     
 
     /**
+     * The proxy that the bridge should "publish" through events. This 
+     * provides a mechanism to supported decorated bridges. 
+     */
+    AsteriskSCF::SessionCommunications::V1::Bridge* publishedBridge;
+
+    /**
      * The current activation state of the bridge. NOT the same
      * as the Component running state.
      **/
diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index a9cd9e1..8916ea6 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -92,10 +92,6 @@ public:
     void replaceSession_async(const AMD_Bridge_replaceSessionPtr& callbac, const SessionPrx& sessionToReplace,
             const SessionSeq& newSessions, const Ice::Current& current);
 
-    void setCookies(const BridgeCookies& cookies, const Ice::Current&);
-    void removeCookies(const BridgeCookies& cookies, const Ice::Current&);
-    BridgeCookies getCookies(const BridgeCookies& cookies, const Ice::Current&);
-
     //
     // BridgeServant methods
     //
@@ -116,16 +112,6 @@ public:
 
     void getAddSessionsTasks(QueuedTasks& tasks, const SessionSeq& sessions);
 
-    BridgeCookies getCookies()
-    {
-        BridgeCookies result;
-        for (BridgeCookieDict::const_iterator i = mState->cookies.begin(); i != mState->cookies.end(); ++i)
-        {
-            result.push_back(i->second);
-        }
-        return result;
-    }
-
 private:
 
     boost::shared_mutex mLock;
@@ -260,11 +246,10 @@ class RemoveSessionsNotify : public QueuedTask
 {
 public:
     RemoveSessionsNotify(const BridgeListenerMgrPtr& bridgeListeners,
-            const SessionsTrackerPtr& tracker, const BridgeCookies& cookies) :
+            const SessionsTrackerPtr& tracker) :
         QueuedTask("RemoveSessionsNotify"),
         mBridgeListeners(bridgeListeners),
-        mTracker(tracker),
-        mCookies(cookies)
+        mTracker(tracker)
     {
     }
     
@@ -274,7 +259,7 @@ protected:
         SessionSeq sessions = mTracker->getSessions();
         if (!sessions.empty())
         {
-            mBridgeListeners->sessionsRemoved(sessions, mCookies);
+            mBridgeListeners->sessionsRemoved(sessions);
         }
         return true;
     }
@@ -282,7 +267,6 @@ protected:
 private:
     BridgeListenerMgrPtr mBridgeListeners;
     SessionsTrackerPtr mTracker;
-    BridgeCookies mCookies;
 };
 
 class SetBridgeTask : public QueuedTask
@@ -384,26 +368,23 @@ private:
 class AddToListeners : public QueuedTask
 {
 public:
-    AddToListeners(const BridgeListenerMgrPtr& listeners, const SessionsTrackerPtr& tracker,
-        const BridgeCookies& cookies) :
+    AddToListeners(const BridgeListenerMgrPtr& listeners, const SessionsTrackerPtr& tracker) :
         QueuedTask("AddToListeners"),
         mListeners(listeners),
-        mTracker(tracker),
-        mCookies(cookies)
+        mTracker(tracker)
     {
     }
     
 protected:
     bool executeImpl()
     {
-        mListeners->sessionsAdded(mTracker->getSessions(), mCookies);
+        mListeners->sessionsAdded(mTracker->getSessions());
         return true;
     }
     
 private:
     BridgeListenerMgrPtr mListeners;
     SessionsTrackerPtr mTracker;
-    BridgeCookies mCookies;
 };
 
 class CheckShutdown : public QueuedTask
@@ -562,7 +543,7 @@ void BridgeImpl::addSessions_async(const AMD_Bridge_addSessionsPtr& callback, co
         SessionsTrackerPtr tracker(new SessionsTracker);
         QueuedTasks tasks;
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
-        tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
+        tasks.push_back(new AddToListeners(mListeners, tracker));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_addSessionsPtr>(callback, tracker));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
@@ -615,13 +596,7 @@ void BridgeImpl::removeSessions_async(const AMD_Bridge_removeSessionsPtr& callba
             }
         }
         QueuedTasks tasks;
-
-        BridgeCookies cookies;
-        {
-            boost::shared_lock<boost::shared_mutex> lock(mLock);
-            cookies = getCookies();
-        }
-        tasks.push_back(new RemoveSessionsNotify(mListeners, removed, cookies));
+        tasks.push_back(new RemoveSessionsNotify(mListeners, removed));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_removeSessionsPtr>(callback, removed));
         tasks.push_back(new CheckShutdown(this, mPrx));
         ExecutorPtr runner(new Executor(tasks, mLogger));
@@ -673,7 +648,7 @@ void BridgeImpl::shutdown(const Ice::Current& current)
         }
         mState->runningState = ShuttingDown;
 
-        mListeners->stopping(getCookies());
+        mListeners->stopping();
         update = createUpdate();
     }
     pushUpdate(update);
@@ -686,8 +661,8 @@ void BridgeImpl::shutdown(const Ice::Current& current)
         ResponseCodePtr responseCode = new ResponseCode;
         ShutdownSessionOperation shutdownOp(mSessionListenerPrx, responseCode, mLogger);
         mSessions->visitSessions(shutdownOp);
+        mListeners->stopped();
         boost::unique_lock<boost::shared_mutex> lock(mLock);
-        mListeners->stopped(getCookies());
         mLogger(Info) << objectIdFromCurrent(current) << ": is shutdown." ;
         mState->runningState = Destroyed;
         //
@@ -719,7 +694,7 @@ void BridgeImpl::destroy(const Ice::Current& current)
         }
         mState->runningState = Destroyed;
         mLogger(Info) << objectIdFromCurrent(current) << ": is now destroyed." ;
-        mListeners->stopped(getCookies());
+        mListeners->stopped();
         mSessionListener = 0;
         update = createUpdate();
     }
@@ -819,14 +794,9 @@ void BridgeImpl::replaceSession_async(const AMD_Bridge_replaceSessionPtr& callba
         
         SessionsTrackerPtr tracker(new SessionsTracker);
         QueuedTasks tasks;
-        BridgeCookies cookies;
-        {
-            boost::shared_lock<boost::shared_mutex> lock(mLock);
-            cookies = getCookies();
-        }
-        tasks.push_back(new RemoveSessionsNotify(mListeners, removeTracker, cookies));
+        tasks.push_back(new RemoveSessionsNotify(mListeners, removeTracker));
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, newSessions, tracker));
-        tasks.push_back(new AddToListeners(mListeners, tracker, cookies));
+        tasks.push_back(new AddToListeners(mListeners, tracker));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_replaceSessionPtr>(callback, tracker));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
@@ -842,68 +812,6 @@ void BridgeImpl::replaceSession_async(const AMD_Bridge_replaceSessionPtr& callba
     }
 }
 
-void BridgeImpl::setCookies(const BridgeCookies& cookies, const Ice::Current& current)
-{
-    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
-    BridgeStateItemPtr update;
-    {
-        boost::unique_lock<boost::shared_mutex> lock(mLock);
-        for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
-        {
-            if ((*i))
-            {
-                mState->cookies[(*i)->ice_id()] = (*i);
-            }
-        }
-        if (!cookies.empty())
-        {
-            update = createUpdate();
-        }
-    }
-    pushUpdate(update);
-}
-
-void BridgeImpl::removeCookies(const BridgeCookies& cookies, const Ice::Current& current)
-{
-    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
-    BridgeStateItemPtr update;
-    {
-        boost::unique_lock<boost::shared_mutex> lock(mLock);
-        bool dirty = false;
-        for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
-        {
-            BridgeCookieDict::iterator v = mState->cookies.find((*i)->ice_id());
-            if (v != mState->cookies.end())
-            {
-                dirty = true;
-                mState->cookies.erase(v);
-            }
-        }
-
-        if (dirty)
-        {
-            update = createUpdate();
-        }
-    }
-    pushUpdate(update);
-}
-
-BridgeCookies BridgeImpl::getCookies(const BridgeCookies& cookies, const Ice::Current& current)
-{
-    BridgeCookies result;
-    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
-    for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
-    {
-        BridgeCookieDict::const_iterator v = mState->cookies.find((*i)->ice_id());
-        if (v != mState->cookies.end())
-        {
-            result.push_back(v->second);
-        }
-    }
-    return result;
-}
-
 bool BridgeImpl::destroyed()
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
@@ -919,9 +827,9 @@ void BridgeImpl::destroyImpl()
         mState->runningState = Destroyed;
         mSessions = 0;
 
-        if (mPrx)
+        if (mObjAdapter && mState)
         {
-            mObjAdapter->remove(mPrx->ice_getIdentity());
+            mObjAdapter->remove(mObjAdapter->getCommunicator()->stringToIdentity(mState->bridgeId));
         }
     }
     catch (const Ice::Exception&)
@@ -947,14 +855,14 @@ void BridgeImpl::shutdownImpl(const Ice::Current& current)
     shutdown(current);
 }
 
-void BridgeImpl::activate(const BridgePrx& proxy)
+void BridgeImpl::activate(const BridgePrx& proxy, const std::string& id)
 {
     mPrx = proxy;
-    string listenerId = mObjAdapter->getCommunicator()->identityToString(mPrx->ice_getIdentity());
-    mLogger(Debug) << FUNLOG << " : activating with " << listenerId;
-    mState->key = listenerId;
-    mState->bridgeId = listenerId;
-    listenerId += ".sessionListener";
+    mState->publishedBridge = proxy;
+    mState->key = id;
+    mState->bridgeId = id;
+    string listenerId = id + ".sessionListener"; 
+    mLogger(Debug) << FUNLOG << " : activating session listener with " << listenerId;
     mActivated = true;
     mSessionListenerPrx =
         SessionListenerPrx::uncheckedCast(
@@ -1002,8 +910,14 @@ void BridgeImpl::activate()
     mLogger(Debug) << FUNLOG;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
     mActivated = true;
-    mPrx = BridgePrx::uncheckedCast(mObjAdapter->add(this, mObjAdapter->getCommunicator()->stringToIdentity(mState->key)));
-    string listenerId = mState->key + ".sessionListener";
+    //
+    // XXX this is not correct with extension points... this could be a decorator.
+    //
+
+    mPrx = mState->publishedBridge;
+    BridgePrx actualPrx = BridgePrx::uncheckedCast(mObjAdapter->add(this, mObjAdapter->getCommunicator()->stringToIdentity(mState->key)));
+
+    string listenerId = mState->key + ".sessionListener"; // XXX this is no longer a derived thing.
     mSessionListenerPrx = SessionListenerPrx::uncheckedCast(
         mObjAdapter->add(mSessionListener, mObjAdapter->getCommunicator()->stringToIdentity(listenerId)));
     //
@@ -1036,7 +950,7 @@ void BridgeImpl::getAddSessionsTasks(QueuedTasks& tasks,
 {
     SessionsTrackerPtr tracker(new SessionsTracker);
     tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
-    tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
+    tasks.push_back(new AddToListeners(mListeners, tracker));
     tasks.push_back(new UpdateTask(this));
 }
 
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index 2c9ab9f..048ca77 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -90,7 +90,8 @@ public:
      * ONCE per instance and is not thread safe.
      *
      **/
-    virtual void activate(const AsteriskSCF::SessionCommunications::V1::BridgePrx& proxy) = 0;
+    virtual void activate(const AsteriskSCF::SessionCommunications::V1::BridgePrx& proxy, 
+        const std::string& id) = 0;
 
     /**
      *
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index 7361dc5..f0df313 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -24,6 +24,7 @@
 #include "BridgeImpl.h"
 #include "BridgeManagerListenerMgr.h"
 #include "BridgeReplicatorIf.h"
+#include "BridgeCreationExtensionPointImpl.h"
 #include <AsteriskSCF/System/ExceptionsIf.h>
 #include <AsteriskSCF/System/Component/ComponentServiceIf.h>
 
@@ -67,6 +68,7 @@ public:
     {
         BridgeServantPtr servant;
         BridgePrx proxy;
+        BridgePrx decoratingPrx;
     };
 
     bool destroyed();
@@ -99,6 +101,10 @@ private:
     BridgeManagerListenerMgrPtr mListeners;
     Logger mLogger;
 
+    BridgeCreationExtensionPointImplPtr mCreationExtension;
+    BridgeCreationExtensionPointPrx mCreationExtensionPrx;
+    ServiceLocatorManagerServicePrx mCreationExtensionPointServicePrx;
+
     BridgeManagerStateItemPtr mState;
 
     void reap();
@@ -154,6 +160,7 @@ protected:
         {
             mListenerMgr->bridgeCreated(mBridgeProxy);
         }
+        
         mCallback->ice_response(mBridgeProxy);
         return true;
     }
@@ -182,30 +189,58 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
         string stringId = string("bridge.") + IceUtil::generateUUID();
         Ice::Identity id(mAdapter->getCommunicator()->stringToIdentity(stringId));
         BridgePrx prx(BridgePrx::uncheckedCast(mAdapter->createProxy(id)));
-        BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), stringId, prx));
         vector<BridgeListenerPrx> listeners(mState->defaultBridgeListeners);
         if (listener)
         {
             listeners.push_back(listener);
         }
 
+        SessionSeq initialSessions;
+        BridgeCreationHookDataPtr originalData;
+        BridgeInfo info;
+        info.proxy = prx;
+        if (mCreationExtension)
+        {
+            originalData = new BridgeCreationHookData;
+            originalData->bridge = prx;
+            originalData->listeners = listeners;
+            originalData->initialSessions = sessions;
+            originalData = mCreationExtension->runHooks(originalData);
+            listeners = originalData->listeners;
+            initialSessions = originalData->sessions;
+            cookies = originalData->cookies;
+            info.externalPrx = originalData->bridge;
+        }
+        BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), stringId, info.externalPrx));
+
         BridgeServantPtr bridge = BridgeServant::create(stringId, mAdapter, listeners, mgr, mReplicationContext->getReplicator(), mLogger);
         Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
         mLogger(Info) << objectIdFromCurrent(current) << ": creating new bridge " << obj->ice_toString() << "." ;
-        BridgeInfo info;
+
+        //
+        // Finish updating BridgeInfo struct.
+        //
         info.servant = bridge;
-        info.proxy = BridgePrx::uncheckedCast(obj);
-        bridge->activate(info.proxy);
+       
+        //
+        // It's very important to note that the bridge servant will not have it's own proxy!
+        // 
+        bridge->activate(info.externalPrx, stringId);
         mBridges.push_back(info);
 
+        if (originalData)
+        {
+            bridge->setCookiesImpl(originalData->cookies);
+        }
+
         QueuedTasks tasks;
         if (!sessions.empty())
         {
-            bridge->getAddSessionsTasks(tasks, sessions);
+            bridge->getAddSessionsTasks(tasks, initialSessions);
         }
-        
-        tasks.push_back(new FinishUp(callback, mListeners, info.proxy));
+
+        tasks.push_back(new FinishUp(callback, mListeners, info.externalPrx));
         ExecutorPtr runner(new Executor(tasks, mLogger));
         runner->start();
     }
@@ -326,6 +361,17 @@ void BridgeManagerImpl::shutdown(const Ice::Current& current)
     {
         mListeners->stopped();
     }
+    try
+    {
+        if (mCreationExtensionPointServicePrx)
+        {
+            mCreationExtensionPointServicePrx->unregister();
+        }
+    }
+    catch (const std::exception& ex)
+    {
+        mLogger(Debug) << ex.what() << " caught while shutting down and unregistering supporting services.";
+    }
     mAdapter->getCommunicator()->shutdown();
     mState->runningState = AsteriskSCF::Replication::BridgeService::V1::Destroyed;
 }
@@ -371,13 +417,39 @@ vector<BridgeServantPtr> BridgeManagerImpl::getBridges()
     return result;
 }
 
-void BridgeManagerImpl::activate()
+void BridgeManagerImpl::activate(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator)
 {
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    for (BridgeManagerListenerSeq::iterator i = mState->listeners.begin(); i != mState->listeners.end(); ++i)
     {
-        mListeners->addListener(*i);
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        if (mCreationExtension)
+        {
+            return;
+        }
+
+        for (BridgeManagerListenerSeq::iterator i = mState->listeners.begin(); i != mState->listeners.end(); ++i)
+        {
+            mListeners->addListener(*i);
+        }
+        mCreationExtension = BridgeCreationExtensionPointImpl::create(mLogger);
     }
+    Ice::Identity myId = mAdapter->getCommunicator()->stringToIdentity(mName);
+
+    //
+    // Incarnated as a facet as a convenience. Also added to the service locator though, so all is fine with our
+    // requirements vis-a-vis "good objects".
+    //
+    mCreationExtensionPrx = 
+        BridgeCreationExtensionPointPrx::uncheckedCast(mAdapter->addFacet(mCreationExtension, myId, BridgeCreationExtensionPointFacet));
+
+    string extPtId = IceUtil::generateUUID();
+
+    // Configure how other components look this component up.
+    ServiceLocatorParamsPtr params = new ServiceLocatorParams;
+    params->category = BridgeCreationExtensionPointCategory;
+    params->service = extPtId;
+   
+    mCreationExtensionPointServicePrx = locator->addService(mCreationExtensionPrx, extPtId);
+    mCreationExtensionPointServicePrx->addLocatorParams(params, "");
 }
 
 void BridgeManagerImpl::createBridgeReplica(const BridgeStateItemPtr& state)
diff --git a/src/BridgeManagerImpl.h b/src/BridgeManagerImpl.h
index 62090a2..da4578a 100644
--- a/src/BridgeManagerImpl.h
+++ b/src/BridgeManagerImpl.h
@@ -17,6 +17,7 @@
 
 #include <Ice/Ice.h>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
 #include <AsteriskSCF/logger.h>
 #include <string>
 #include <vector>
@@ -49,7 +50,7 @@ public:
 
     virtual std::vector<BridgeServantPtr> getBridges() = 0;
 
-    virtual void activate() = 0;
+    virtual void activate(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx&) = 0;
 
     virtual std::string getID() = 0;
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c7fbc72..839fd48 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,6 +22,8 @@ astscf_component_add_files(bridgeservice SessionCollection.cpp)
 astscf_component_add_files(bridgeservice SessionCollection.h)
 astscf_component_add_files(bridgeservice SessionOperations.cpp)
 astscf_component_add_files(bridgeservice SessionOperations.h)
+astscf_component_add_files(bridgeservice BridgeCreationExtensionPointImpl.cpp) 
+astscf_component_add_files(bridgeservice BridgeCreationExtensionPointImpl.h) 
 astscf_component_add_files(bridgeservice ServiceUtil.h)
 astscf_component_add_files(bridgeservice DebugUtil.h)
 astscf_component_add_files(bridgeservice MediaSplicer.h)
diff --git a/src/Component.cpp b/src/Component.cpp
index dbe7194..6af9d0c 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -116,13 +116,17 @@ void Component::onPostInitialize()
 {
     if (getReplicationContext()->isActive())
     {
-       mBridgeManager->activate(); 
+       mBridgeManager->activate(getServiceLocator()); 
     }
 }
 
 void Component::onActivated()
 {
-    mBridgeManager->activate(); // TBD...Is this really needed? Is there really no standby() correlary?
+    mBridgeManager->activate(getServiceLocator()); // TBD...Is this really needed? Is there really no standby() correlary?
+    // 
+    // Response to TBD. None of the AsteriskSCF components support moving from active to standby.. the presumption
+    // being that if you are active, the only way you are going to be moved to standby is if you are restarted.
+    //
 }
 
 void Component::onPreInitialize()

commit 2efb1327f9209a1ef68f1b6d59e359f120a1c853
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Aug 8 11:13:47 2011 -0500

    Correct build problem for recent integration of base component.
    static_pointer_cast wasn't found in boost namespace without boost:: qualifier.

diff --git a/src/Component.cpp b/src/Component.cpp
index cbde65c..dbe7194 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -181,7 +181,7 @@ void Component::listenToStateReplicators()
 {
     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
     BridgeReplicationContextPtr bridgeReplicationContext = 
-        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+        boost::static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
 
     if (mListeningToReplicator == true)
     {
@@ -214,7 +214,7 @@ void Component::stopListeningToStateReplicators()
 {
     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
     BridgeReplicationContextPtr bridgeReplicationContext = 
-        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+        boost::static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
 
     if ((!bridgeReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
     {

commit 6c2a0e39849907661e31c5a28fc29bf6bce67d98
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Aug 8 02:13:49 2011 -0500

    Integration

diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index 13f2445..7361dc5 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -465,6 +465,7 @@ void BridgeManagerImpl::update()
         {
             mLogger(Warning) << "Caught exception while trying to replicate bridge manager state: " << ex.what();
         }
+    }
 }
 
 } // End of anonymous namespace
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8c0dbeb..c7fbc72 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,15 +1,15 @@
 include_directories(${logger_dir}/include)
 include_directories(${astscf-ice-util-cpp_dir}/include)
 
-<<<<<<< HEAD
 astscf_component_init(bridgeservice)
-astscf_component_add_files(bridgeservice Service.cpp)
+astscf_component_add_files(bridgeservice Component.cpp)
 astscf_component_add_files(bridgeservice BridgeImpl.h)
 astscf_component_add_files(bridgeservice BridgeImpl.cpp)
 astscf_component_add_files(bridgeservice BridgeListenerMgr.h)
 astscf_component_add_files(bridgeservice BridgeListenerMgr.cpp)
 astscf_component_add_files(bridgeservice BridgeManagerListenerMgr.h)
 astscf_component_add_files(bridgeservice BridgeManagerListenerMgr.cpp)
+astscf_component_add_files(bridgeservice BridgeReplicationContext.h)
 astscf_component_add_files(bridgeservice BridgeReplicatorStateListenerI.h)
 astscf_component_add_files(bridgeservice BridgeReplicatorStateListenerI.cpp)
 astscf_component_add_files(bridgeservice BridgeManagerImpl.h)
@@ -35,7 +35,7 @@ astscf_component_add_ice_libraries(bridgeservice IceStorm)
 astscf_component_add_boost_libraries(bridgeservice thread date_time)
 astscf_component_add_slice_collection_libraries(bridgeservice ASTSCF)
 astscf_component_build_icebox(bridgeservice)
-target_link_libraries(bridgeservice ice-util-cpp logging-client)
+target_link_libraries(bridgeservice astscf-ice-util-cpp logging-client)
 astscf_component_install(bridgeservice)
 
 astscf_component_init(BridgeReplicator)
diff --git a/src/Component.cpp b/src/Component.cpp
index 5957099..cbde65c 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -35,7 +35,7 @@ using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::BridgeService;
-using namespace AsteriskSCF::Bridge::V1;
+using namespace AsteriskSCF::Replication::BridgeService::V1;
 using namespace AsteriskSCF::Replication;
 using namespace AsteriskSCF::Discovery;
 using namespace std;
@@ -247,7 +247,7 @@ void Component::onStop()
 }
 
 extern "C" {
-ASTERISK_SCF_ICEBOX_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
+ASTSCF_DLL_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
 {
     return new Component;
 }
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index d42de16..f23c73c 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -237,6 +237,8 @@ private:
         //
         ServiceLocatorParamsPtr searchParams(new ServiceLocatorParams);
         searchParams->category = BridgeManagerDiscoveryCategory;
+        searchParams->service = "default";
+        searchParams->id = "TestBridge";
         try
         {
             mPrimary = BridgeManagerPrx::uncheckedCast(locator->locate(searchParams));
@@ -1086,9 +1088,9 @@ public:
                 msg << "Unexpected Ice exception " << ex.what();
                 BOOST_FAIL(msg.str());
             }
-            catch (...)
+            catch (const std::exception& e)
             {
-                BOOST_FAIL("Unexpected exception");
+                BOOST_FAIL("Unexpected exception:" << e.what());
             }
         }
         catch (...)

commit 9d266f59cab440e5ab70d975c22895ef85c39274
Merge: ce91883 4e1df70
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Aug 2 17:57:49 2011 -0500

    Merging use of base Component class and use of expanded ServiceLocatorParams.

diff --cc src/BridgeManagerImpl.cpp
index e75e7db,2be8238..13f2445
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@@ -460,15 -457,8 +457,14 @@@ void BridgeManagerImpl::update(
          ++mState->serial;
          ReplicatedStateItemSeq seq;
          seq.push_back(getState());
 -        mReplicationContext->getReplicator()->setState(seq);
 -    }
 +        try
 +        {
-             mReplicator->setState(seq);
++            mReplicationContext->getReplicator()->setState(seq);
 +        }
 +        catch (const Ice::Exception& ex)
 +        {
 +            mLogger(Warning) << "Caught exception while trying to replicate bridge manager state: " << ex.what();
 +        }
-     }
  }
  
  } // End of anonymous namespace
diff --cc src/CMakeLists.txt
index c7f87b5,ccc9502..8c0dbeb
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@@ -1,48 -1,53 +1,49 @@@
 -include_directories(${API_INCLUDE_DIR})
  include_directories(${logger_dir}/include)
 -include_directories(${ice-util-cpp_dir}/include)
 +include_directories(${astscf-ice-util-cpp_dir}/include)
  
 -asterisk_scf_slice_include_directories(${API_SLICE_DIR})
++<<<<<<< HEAD
 +astscf_component_init(bridgeservice)
 +astscf_component_add_files(bridgeservice Service.cpp)
 +astscf_component_add_files(bridgeservice BridgeImpl.h)
 +astscf_component_add_files(bridgeservice BridgeImpl.cpp)
 +astscf_component_add_files(bridgeservice BridgeListenerMgr.h)
 +astscf_component_add_files(bridgeservice BridgeListenerMgr.cpp)
 +astscf_component_add_files(bridgeservice BridgeManagerListenerMgr.h)
 +astscf_component_add_files(bridgeservice BridgeManagerListenerMgr.cpp)
 +astscf_component_add_files(bridgeservice BridgeReplicatorStateListenerI.h)
 +astscf_component_add_files(bridgeservice BridgeReplicatorStateListenerI.cpp)
 +astscf_component_add_files(bridgeservice BridgeManagerImpl.h)
 +astscf_component_add_files(bridgeservice BridgeManagerImpl.cpp)
 +astscf_component_add_files(bridgeservice SessionListener.cpp)
 +astscf_component_add_files(bridgeservice SessionListener.h)
 +astscf_component_add_files(bridgeservice SessionWrapper.cpp)
 +astscf_component_add_files(bridgeservice SessionWrapper.h)
 +astscf_component_add_files(bridgeservice SessionCollection.cpp)
 +astscf_component_add_files(bridgeservice SessionCollection.h)
 +astscf_component_add_files(bridgeservice SessionOperations.cpp)
 +astscf_component_add_files(bridgeservice SessionOperations.h)
 +astscf_component_add_files(bridgeservice ServiceUtil.h)
 +astscf_component_add_files(bridgeservice DebugUtil.h)
 +astscf_component_add_files(bridgeservice MediaSplicer.h)
 +astscf_component_add_files(bridgeservice MediaSplicer.cpp)
 +astscf_component_add_files(bridgeservice Tasks.h)
 +astscf_component_add_files(bridgeservice InternalExceptions.h)
 +astscf_component_add_files(bridgeservice BridgeServiceConfig.h)
 +astscf_component_add_files(bridgeservice ListenerManager.h)
 +astscf_component_add_slices(bridgeservice PROJECT AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice)
 +astscf_component_add_ice_libraries(bridgeservice IceStorm)
 +astscf_component_add_boost_libraries(bridgeservice thread date_time)
 +astscf_component_add_slice_collection_libraries(bridgeservice ASTSCF)
 +astscf_component_build_icebox(bridgeservice)
- target_link_libraries(bridgeservice logging-client)
++target_link_libraries(bridgeservice ice-util-cpp logging-client)
 +astscf_component_install(bridgeservice)
  
 -asterisk_scf_component_init(bridgeservice)
 -asterisk_scf_component_add_file(bridgeservice Component.cpp)
 -asterisk_scf_component_add_file(bridgeservice BridgeImpl.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeImpl.cpp)
 -asterisk_scf_component_add_file(bridgeservice BridgeListenerMgr.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeListenerMgr.cpp)
 -asterisk_scf_component_add_file(bridgeservice BridgeManagerListenerMgr.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeManagerListenerMgr.cpp)
 -asterisk_scf_component_add_file(bridgeservice BridgeReplicatorStateListenerI.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeReplicationContext.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeReplicatorStateListenerI.cpp)
 -asterisk_scf_component_add_file(bridgeservice BridgeManagerImpl.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeManagerImpl.cpp)
 -asterisk_scf_component_add_file(bridgeservice SessionListener.cpp)
 -asterisk_scf_component_add_file(bridgeservice SessionListener.h)
 -asterisk_scf_component_add_file(bridgeservice SessionWrapper.cpp)
 -asterisk_scf_component_add_file(bridgeservice SessionWrapper.h)
 -asterisk_scf_component_add_file(bridgeservice SessionCollection.cpp)
 -asterisk_scf_component_add_file(bridgeservice SessionCollection.h)
 -asterisk_scf_component_add_file(bridgeservice SessionOperations.cpp)
 -asterisk_scf_component_add_file(bridgeservice SessionOperations.h)
 -asterisk_scf_component_add_file(bridgeservice ServiceUtil.h)
 -asterisk_scf_component_add_file(bridgeservice DebugUtil.h)
 -asterisk_scf_component_add_file(bridgeservice MediaSplicer.h)
 -asterisk_scf_component_add_file(bridgeservice MediaSplicer.cpp)
 -asterisk_scf_component_add_file(bridgeservice Tasks.h)
 -asterisk_scf_component_add_file(bridgeservice InternalExceptions.h)
 -asterisk_scf_component_add_file(bridgeservice BridgeServiceConfig.h)
 -asterisk_scf_component_add_file(bridgeservice ListenerManager.h)
 -asterisk_scf_component_add_slice(bridgeservice ./BridgeReplicatorIf.ice)
 -asterisk_scf_component_add_ice_libraries(bridgeservice IceStorm)
 -asterisk_scf_component_add_ice_libraries(bridgeservice IceBox)
 -asterisk_scf_component_add_boost_libraries(bridgeservice thread date_time)
 -asterisk_scf_component_build_icebox(bridgeservice)
 -target_link_libraries(bridgeservice logging-client)
 -target_link_libraries(bridgeservice ice-util-cpp)
 -asterisk_scf_component_install(bridgeservice)
 -
 -asterisk_scf_component_init(BridgeReplicator)
 -asterisk_scf_component_add_file(BridgeReplicator BridgeReplicatorService.cpp)
 -asterisk_scf_component_add_slice(BridgeReplicator ./BridgeReplicatorIf.ice)
 -asterisk_scf_component_add_ice_libraries(BridgeReplicator IceStorm)
 -asterisk_scf_component_add_boost_libraries(BridgeReplicator thread date_time)
 -asterisk_scf_component_build_icebox(BridgeReplicator)
 +astscf_component_init(BridgeReplicator)
 +astscf_component_add_files(BridgeReplicator BridgeReplicatorService.cpp)
 +astscf_component_add_slices(BridgeReplicator PROJECT AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice)
 +astscf_component_add_ice_libraries(BridgeReplicator IceStorm)
 +astscf_component_add_boost_libraries(BridgeReplicator thread date_time)
 +astscf_component_add_slice_collection_libraries(BridgeReplicator ASTSCF)
 +astscf_component_build_icebox(BridgeReplicator)
  target_link_libraries(BridgeReplicator logging-client)
 -target_link_libraries(BridgeReplicator asterisk-scf-api)
 -asterisk_scf_component_install(BridgeReplicator)
 +astscf_component_install(BridgeReplicator)
diff --cc src/Component.cpp
index 0000000,aa7d5d7..5957099
mode 000000,100644..100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@@ -1,0 -1,254 +1,255 @@@
+ /*
+  * Asterisk SCF -- An open-source communications framework.
+  *
+  * Copyright (C) 2010-2011, Digium, Inc.
+  *
+  * See http://www.asterisk.org for more information about
+  * the Asterisk SCF project. Please do not directly contact
+  * any of the maintainers of this project for assistance;
+  * the project provides a web site, mailing lists and IRC
+  * channels for your use.
+  *
+  * This program is free software, distributed under the terms of
+  * the GNU General Public License Version 2. See the LICENSE.txt file
+  * at the top of the source tree.
+  */
+ 
+ #include <Ice/Ice.h>
+ #include <IceBox/IceBox.h>
+ #include <IceStorm/IceStorm.h>
+ 
+ #include <AsteriskSCF/Logger/IceLogger.h>
+ #include <AsteriskSCF/logger.h>
+ #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+ #include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+ #include <AsteriskSCF/System/Component/ReplicaIf.h>
+ #include <AsteriskSCF/Component/Component.h>
+ #include <AsteriskSCF/Discovery/LocatorRegistrationWrapper.h>
+ 
+ #include "BridgeManagerImpl.h"
+ #include "BridgeReplicatorStateListenerI.h"
+ #include "BridgeReplicationContext.h"
+ 
+ using namespace AsteriskSCF::System::Logging;
+ using namespace AsteriskSCF::SessionCommunications::V1;
+ using namespace AsteriskSCF::Core::Discovery::V1;
+ using namespace AsteriskSCF::System::Component::V1;
+ using namespace AsteriskSCF::BridgeService;
+ using namespace AsteriskSCF::Bridge::V1;
+ using namespace AsteriskSCF::Replication;
+ using namespace AsteriskSCF::Discovery;
+ using namespace std;
+ 
+ 
+ namespace
+ {
+ Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
+ }
+ 
+ namespace
+ {
+ 
+ class Component : public AsteriskSCF::Component::Component
+ {
+ public:
+     Component() : 
+         AsteriskSCF::Component::Component(lg, 
+                                           "BridgeService"),
+         mListeningToReplicator(false)   {}
+ 
+ private:
+     // Optional base Component notification overrides. 
+     virtual void onActivated();
+     virtual void onPreInitialize();
+     virtual void onPostInitialize();
+     virtual void onStop();
+ 
+     // Required base Component overrides
+     virtual void createPrimaryServices();
+     virtual void preparePrimaryServicesForDiscovery();
+     virtual void createReplicationStateListeners();
+     virtual void stopListeningToStateReplicators();
+     virtual void listenToStateReplicators();
+     virtual void findRemoteServices() {};  // N/A
+ 
+     // Other base Component overrides
+     virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
+ 
+     ReplicatorSmartPrx mReplicator;
+     BridgeManagerServantPtr mBridgeManager;
+     BridgeManagerPrx mBridgeManagerPrx;
+     LocatorRegistrationWrapperPtr mBridgeManagerRegistration;
+     RegisterThreadPtr mRegisterThread;
+     ReplicatorListenerPrx mReplicatorListenerPrx;
+     bool mListeningToReplicator;
+     boost::shared_mutex mReplicatorLock;
+ };
+ 
+ /**
+  * Override of factory method of the base Component class. Out custom 
+  * version allows us to attach our replicator proxy to the context.
+  */
+ ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
+ {
+     // Find our state replicator. 
+     ServiceLocatorParamsPtr searchParams = new ServiceLocatorParams;
+     searchParams->category = StateReplicatorDiscoveryCategory;
+     searchParams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
+                "Bridge.StateReplicatorService", "default");
+     searchParams->id = getCommunicator()->getProperties()->getProperty("Bridge.StateReplicatorId");
+ 
+     ReplicatorSmartPrx replicator;
+     try
+     {
+         replicator = ReplicatorSmartPrx(getServiceLocator(), searchParams, lg);
+     }
+     catch (const std::exception& ex)
+     {
+         lg(Error) << "Bridge state replicator lookup failed. Continuing without replication. " << ex.what();
+     }
+ 
+     BridgeReplicationContextPtr context(new BridgeReplicationContext(state, replicator));
+     return context;
+ }
+ 
+ void Component::onPostInitialize()
+ {
+     if (getReplicationContext()->isActive())
+     {
+        mBridgeManager->activate(); 
+     }
+ }
+ 
+ void Component::onActivated()
+ {
+     mBridgeManager->activate(); // TBD...Is this really needed? Is there really no standby() correlary?
+ }
+ 
+ void Component::onPreInitialize()
+ {
+     lg(Debug) << "Launching AsteriskSCF Session-Oriented Bridging Service " << getName();
+ }
+ 
+ /** 
+  * Create our servant implementations.
+  */
+ void Component::createPrimaryServices()
+ {
+      std::string managerName = 
+         getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".ManagerId", "BridgeManager");
+ 
+     //
+     // It's very important that uncheckedCast's be used here as there are no guarantees
+     // that the object adapter is activated yet. If it is not, then this can hang.
+     //
+     BridgeReplicationContextPtr replicationContext = boost::static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+     mBridgeManager = createBridgeManager(getServiceAdapter(), managerName, replicationContext, lg);
+     mBridgeManagerPrx = BridgeManagerPrx::uncheckedCast(getServiceAdapter()->add(mBridgeManager, 
+           getCommunicator()->stringToIdentity(managerName)));
+     assert(mBridgeManagerPrx != 0);
+     if (mBridgeManagerPrx == 0)
+     {
+         throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge manager object");
+     }
+ }
+ 
+ /**
+  * Wrap our servants for the locator service.
+  */
+ void Component::preparePrimaryServicesForDiscovery()
+ {
+     try
+     {
+         mBridgeManagerRegistration = this->wrapServiceForRegistration(mBridgeManagerPrx,
+                                                                       BridgeManagerDiscoveryCategory);
+         managePrimaryService(mBridgeManagerRegistration);
+     }
+     catch (const Ice::Exception& e)
+     {
+         lg(Error) << "Exception in " << BOOST_CURRENT_FUNCTION << e.what(); 
+         throw;
+     }
+ }
+ 
+ void Component::createReplicationStateListeners()
+ {
+     ReplicatorListenerPtr replicaListener = createStateListener(lg, mBridgeManager);
+     mReplicatorListenerPrx = ReplicatorListenerPrx::uncheckedCast(getBackplaneAdapter()->addWithUUID(replicaListener));
+ }
+ 
+ void Component::listenToStateReplicators()
+ {
+     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+     BridgeReplicationContextPtr bridgeReplicationContext = 
+         static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+ 
+     if (mListeningToReplicator == true)
+     {
+         return;
+     }
+ 
+     if (!bridgeReplicationContext->getReplicator().isInitialized())
+     {
+         lg(Error) << getName() << ": " << BOOST_CURRENT_FUNCTION << ": State replicator could not be found. Unable to listen for state updates!";
+         return;
+     }
+ 
+     try
+     {
+         // Are we in standby mode?
+         if (bridgeReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+         {
+             bridgeReplicationContext->getReplicator().tryOneWay()->addListener(mReplicatorListenerPrx);
+             mListeningToReplicator = true;
+         }
+     }
+     catch (const Ice::Exception& e)
+     {
+         lg(Error) << e.what();
+         throw;
+     }
+ }
+ 
+ void Component::stopListeningToStateReplicators()
+ {
+     boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+     BridgeReplicationContextPtr bridgeReplicationContext = 
+         static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+ 
+     if ((!bridgeReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+     {
+         return;
+     }
+ 
+     try
+     {
+         bridgeReplicationContext->getReplicator().tryOneWay()->removeListener(mReplicatorListenerPrx);
+         mListeningToReplicator = false;
+     }
+     catch (const Ice::Exception& e)
+     {
+         lg(Error) << e.what();
+         throw;
+     }
+ }
+ 
+ /**
+  * Override of stop notification. 
+  */
+ void Component::onStop()
+ {
+     if (mRegisterThread)
+     {
+         mRegisterThread->stop();
+     }
+ }
+ 
+ }
+ 
+ extern "C" {
+ ASTERISK_SCF_ICEBOX_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
+ {
+     return new Component;
+ }
+ }
++
diff --cc test/TestBridging.cpp
index a8052ac,bf88553..d42de16
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@@ -41,7 -40,7 +42,8 @@@ using namespace AsteriskSCF::BridgingTe
  using namespace AsteriskSCF::SessionCommunications::V1;
  using namespace AsteriskSCF::Core::Discovery::V1;
  using namespace AsteriskSCF::Core::Routing::V1;
 +using namespace AsteriskSCFTest;
+ using namespace AsteriskSCF::System::Component::V1;
  using namespace std;
  
  /* Cache the command line arguments so that Ice can be initialized within the global fixture. */

commit 4e1df70a193f2ff3f3713d22c2c5ab1428038f4e
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jun 28 20:51:24 2011 -0500

    Mods for changes to ServiceLocatorParams and use of base Component class.

diff --git a/config/bridging.conf b/config/bridging.conf
index 9fa634f..95e9796 100644
--- a/config/bridging.conf
+++ b/config/bridging.conf
@@ -5,7 +5,7 @@ BridgeManager.BridgeService.Endpoints=default
 Ice.ThreadPool.Client.Size=4
 
 # A proxy to the service locator management service
-ServiceLocatorManagementProxy=LocatorServiceManagement:tcp -p 4422
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 LocatorService.Proxy=LocatorService:tcp -p 4411
 
 # A proxy to the IceStorm topic manager
diff --git a/config/test_bridging.conf b/config/test_bridging.conf
index e88f751..c8cb3c8 100644
--- a/config/test_bridging.conf
+++ b/config/test_bridging.conf
@@ -9,6 +9,10 @@
 #
 Ice.Default.CollocationOptimized=0
 
+Ice.Override.Timeout=5000
+
+Ice.Warn.UnknownProperties=0
+
 #
 # We use a single file for configuration.
 #
@@ -104,7 +108,7 @@ ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
 # The proxies that clients use to access the Service Locator facilities.
 #
 LocatorService.Proxy=LocatorService:default -p 4411
-ServiceLocatorManagementProxy=LocatorServiceManagement:tcp -p 4422
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 
 #
 # The IceBox entries for loading the services.
@@ -128,15 +132,20 @@ TestChannel.InstanceName=BridgeTest
 #
 # Configuration for the test bridge instances. There are are two: one master
 # (TestBridge) and one standby (TestBridge2).
-# NOTE: These will be changed to be accessible through
-# service discovery in a later branch.
+# For testing purposes we're providing explicit endpoints for the standby 
+# component. Endpoints will be assigned random unused ports if not 
+# explicitly set. 
 #
 TestBridge.InstanceName=TestBridge
 TestBridge.ManagerId=TestBridgeManager
+# TestBridge.Endpoints=default -p 57000
+# TestBridge.Backplane.Endpoints=default -p 57001
 
 TestBridge2.InstanceName=TestBridge2
 TestBridge2.ManagerId=TestBridgeManager2
-TestBridge2.StateReplicatorListener=yes
+TestBridge2.Standby=yes
+TestBridge2.Endpoints=default -p 57010
+TestBridge2.Backplane.Endpoints=default -p 57011
 
 #
 # Configuration for the bridge state replicator.
diff --git a/src/BridgeListenerMgr.h b/src/BridgeListenerMgr.h
index 5c31156..d5a39d9 100644
--- a/src/BridgeListenerMgr.h
+++ b/src/BridgeListenerMgr.h
@@ -40,5 +40,6 @@ private:
 };
 
 typedef IceUtil::Handle<BridgeListenerMgr> BridgeListenerMgrPtr;
+
 } // End of namespace BridgeService
 } // End of namespace AsteriskSCF
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index be58b67..2be8238 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -45,7 +45,7 @@ class BridgeManagerImpl : public BridgeManagerServant
 public:
 
     BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name,
-            const ReplicatorSmartPrx& replicator, const Logging::Logger& logger);
+            const BridgeReplicationContextPtr& replicationContext, const Logging::Logger& logger);
     ~BridgeManagerImpl();
 
     //
@@ -93,9 +93,8 @@ private:
     boost::shared_mutex mLock;
     string mName;
     vector<BridgeInfo> mBridges;
-    bool mActivated;
     Ice::ObjectAdapterPtr mAdapter;
-    ReplicatorSmartPrx mReplicator;
+    BridgeReplicationContextPtr mReplicationContext;
     BridgeManagerPrx mSourceProxy;
     BridgeManagerListenerMgrPtr mListeners;
     Logger mLogger;
@@ -110,12 +109,11 @@ private:
 
 typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
 
-BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name, const ReplicatorSmartPrx& replicator,
+BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name, const BridgeReplicationContextPtr& replicationContext,
         const Logger& logger) :
     mName(name),
-    mActivated(false),
     mAdapter(adapter),
-    mReplicator(replicator), 
+    mReplicationContext(replicationContext), 
     mLogger(logger),
     mState(new BridgeManagerStateItem)
 {
@@ -191,7 +189,7 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
             listeners.push_back(listener);
         }
 
-        BridgeServantPtr bridge = BridgeServant::create(stringId, mAdapter, listeners, mgr, mReplicator, mLogger);
+        BridgeServantPtr bridge = BridgeServant::create(stringId, mAdapter, listeners, mgr, mReplicationContext->getReplicator(), mLogger);
         Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
         mLogger(Info) << objectIdFromCurrent(current) << ": creating new bridge " << obj->ice_toString() << "." ;
@@ -376,7 +374,6 @@ vector<BridgeServantPtr> BridgeManagerImpl::getBridges()
 void BridgeManagerImpl::activate()
 {
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    mActivated = true;
     for (BridgeManagerListenerSeq::iterator i = mState->listeners.begin(); i != mState->listeners.end(); ++i)
     {
         mListeners->addListener(*i);
@@ -391,7 +388,7 @@ void BridgeManagerImpl::createBridgeReplica(const BridgeStateItemPtr& state)
     BridgePrx prx(BridgePrx::uncheckedCast(mAdapter->createProxy(id)));
     BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), state->bridgeId, prx));
 
-    BridgeServantPtr bridge = BridgeServant::create(mAdapter, mgr, mReplicator, mLogger, state);
+    BridgeServantPtr bridge = BridgeServant::create(mAdapter, mgr, mReplicationContext->getReplicator(), mLogger, state);
     Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
     mLogger(Info) << ": creating bridge replica " << obj->ice_toString() << "." ;
@@ -437,7 +434,7 @@ void BridgeManagerImpl::reap()
 
 void BridgeManagerImpl::statePreCheck(const string& caller)
 {
-    if (!mActivated)
+    if (!mReplicationContext->isActive())
     {
         mLogger(Info) << caller << ": remote call invoked when not active!";
     }
@@ -455,12 +452,12 @@ void BridgeManagerImpl::statePreCheck(const string& caller)
 
 void BridgeManagerImpl::update()
 {
-    if (mActivated)
+    if (mReplicationContext->isReplicating())
     {
         ++mState->serial;
         ReplicatedStateItemSeq seq;
         seq.push_back(getState());
-        mReplicator->setState(seq);
+        mReplicationContext->getReplicator()->setState(seq);
     }
 }
 
@@ -468,8 +465,8 @@ void BridgeManagerImpl::update()
 
 BridgeManagerServantPtr 
 AsteriskSCF::BridgeService::createBridgeManager(const Ice::ObjectAdapterPtr& adapter, const string& name,
-        const ReplicatorSmartPrx& replicator,
+        const BridgeReplicationContextPtr& replicationContext,
         const Logger& logger)
 {
-    return new BridgeManagerImpl(adapter, name, replicator, logger);
+    return new BridgeManagerImpl(adapter, name, replicationContext, logger);
 }
diff --git a/src/BridgeManagerImpl.h b/src/BridgeManagerImpl.h
index dd7fad3..b5e4ec9 100644
--- a/src/BridgeManagerImpl.h
+++ b/src/BridgeManagerImpl.h
@@ -21,6 +21,7 @@
 #include <string>
 #include <vector>
 
+#include "BridgeReplicationContext.h"
 #include "BridgeServiceConfig.h"
 #include "BridgeImpl.h"
 
@@ -72,7 +73,7 @@ typedef IceUtil::Handle<BridgeManagerServant> BridgeManagerServantPtr;
  *
  **/
 BridgeManagerServantPtr createBridgeManager(const Ice::ObjectAdapterPtr& adapter,
-        const std::string& name, const ReplicatorSmartPrx& replicator,
+        const std::string& name, const BridgeReplicationContextPtr& replicationContext,
         const AsteriskSCF::System::Logging::Logger& logger);
 
 };
diff --git a/src/BridgeReplicationContext.h b/src/BridgeReplicationContext.h
new file mode 100644
index 0000000..8959336
--- /dev/null
+++ b/src/BridgeReplicationContext.h
@@ -0,0 +1,69 @@
+/*
+ * 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 <boost/thread/shared_mutex.hpp>
+
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+#include "BridgeServiceConfig.h"
+
+namespace AsteriskSCF
+{
+namespace BridgeService
+{
+
+/** 
+ * This class provides the component with context
+ * related to state replication. 
+ */
+class BridgeReplicationContext : public AsteriskSCF::Replication::ReplicationContext
+{
+public:
+    BridgeReplicationContext(AsteriskSCF::Replication::ReplicationStateType state, 
+                             const ReplicatorSmartPrx& bridgeReplicator) : 
+        ReplicationContext(state),
+        mBridgeReplicator(bridgeReplicator)
+    {
+    }
+        
+    // Override
+     virtual bool isReplicating() 
+     {
+         // If the base context says we aren't replicating, we aren't. 
+         if (!ReplicationContext::isReplicating())
+         {
+             return false;
+         }
+
+         // Do we have a replicator proxy?
+         if (mBridgeReplicator.isInitialized())
+         {
+             return true;
+         }
+
+         return false;
+     }
+
+    ReplicatorSmartPrx getReplicator() {return mBridgeReplicator;}
+
+private:
+   ReplicatorSmartPrx mBridgeReplicator;
+};
+typedef boost::shared_ptr<BridgeReplicationContext> BridgeReplicationContextPtr;
+
+} // namespace BridgeService
+} // namespace AsteriskSCF
diff --git a/src/BridgeReplicatorIf.ice b/src/BridgeReplicatorIf.ice
index 1d3e1b8..7d4b4ee 100644
--- a/src/BridgeReplicatorIf.ice
+++ b/src/BridgeReplicatorIf.ice
@@ -60,16 +60,6 @@ sequence<ReplicatedStateItem> ReplicatedStateItemSeq;
 
 /**
  *
- * TODO: Use!
- *
- */
-unsliceable class BridgeStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
-{
-    string name;
-};
-
-/**
- *
  * MediaOperationReplicationPolicy indicates whether proxies to media
  * operations should be replicated along with the media sessions or media
  * sessions only are replicated. If only the media sessions are replicated,
diff --git a/src/BridgeReplicatorService.cpp b/src/BridgeReplicatorService.cpp
index 6bda816..ca4b709 100644
--- a/src/BridgeReplicatorService.cpp
+++ b/src/BridgeReplicatorService.cpp
@@ -41,6 +41,11 @@ typedef IceUtil::Handle<ReplicatorI> ReplicatorIPtr;
 
 namespace
 {
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
+}
+
+namespace
+{
 
 class BridgeReplicatorApp : public IceBox::Service
 {
@@ -117,11 +122,11 @@ void BridgeReplicatorApp::start(const string& name, const Ice::CommunicatorPtr&
     getLoggerFactory().setLogOutput(iceLogger->getLogger());
 
 
-    string property = communicator->getProperties()->getProperty("ServiceLocatorManagementProxy");
+    string property = communicator->getProperties()->getProperty("LocatorServiceManagement.Proxy");
     if(property.size() == 0)
     {
         throw IceBox::FailureException(__FILE__, __LINE__,
-                "Configuration error: Unable to locate property `ServiceLocatorManagementProxy'");
+                "Configuration error: Unable to locate property `LocatorServiceManagement.Proxy'");
     }
     
     //
@@ -141,16 +146,23 @@ void BridgeReplicatorApp::start(const string& name, const Ice::CommunicatorPtr&
     bool registered = false;
     try
     {
-        BridgeStateReplicatorParamsPtr locatorParameters = new BridgeStateReplicatorParams;
+        std::string serviceName = communicator->getProperties()->getPropertyWithDefault(
+          name + ".ServiceName", "default");
+
+        ServiceLocatorParamsPtr locatorParameters = new ServiceLocatorParams;
         locatorParameters->category = StateReplicatorDiscoveryCategory;
-        locatorParameters->name = communicator->getProperties()->getPropertyWithDefault(name + ".ReplicatorName", "default");
+        locatorParameters->service = serviceName;
+        locatorParameters->id = communicator->getProperties()->getPropertyWithDefault(name + ".ReplicatorName", "default");
         mLocator = new LocatorRegistrationWrapper<ReplicatorPrx>(communicator, property, replicatorPrx, adapterName, 
           locatorParameters);
         registered = mLocator->registerService();
     }
-    catch(const Ice::Exception&)
+    catch(const Ice::Exception& e)
     {
+        lg(Error) << "Exception starting bridge replicator: " << e.what();
+        throw;
     }
+
     if(!registered)
     {
         mRegisterThread = new RegisterThread<ReplicatorPrx>(mLocator);
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f2c83c3..ccc9502 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,7 +5,7 @@ include_directories(${ice-util-cpp_dir}/include)
 asterisk_scf_slice_include_directories(${API_SLICE_DIR})
 
 asterisk_scf_component_init(bridgeservice)
-asterisk_scf_component_add_file(bridgeservice Service.cpp)
+asterisk_scf_component_add_file(bridgeservice Component.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeImpl.h)
 asterisk_scf_component_add_file(bridgeservice BridgeImpl.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeListenerMgr.h)
@@ -13,6 +13,7 @@ asterisk_scf_component_add_file(bridgeservice BridgeListenerMgr.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeManagerListenerMgr.h)
 asterisk_scf_component_add_file(bridgeservice BridgeManagerListenerMgr.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeReplicatorStateListenerI.h)
+asterisk_scf_component_add_file(bridgeservice BridgeReplicationContext.h)
 asterisk_scf_component_add_file(bridgeservice BridgeReplicatorStateListenerI.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeManagerImpl.h)
 asterisk_scf_component_add_file(bridgeservice BridgeManagerImpl.cpp)
@@ -38,6 +39,7 @@ asterisk_scf_component_add_ice_libraries(bridgeservice IceBox)
 asterisk_scf_component_add_boost_libraries(bridgeservice thread date_time)
 asterisk_scf_component_build_icebox(bridgeservice)
 target_link_libraries(bridgeservice logging-client)
+target_link_libraries(bridgeservice ice-util-cpp)
 asterisk_scf_component_install(bridgeservice)
 
 asterisk_scf_component_init(BridgeReplicator)
diff --git a/src/Component.cpp b/src/Component.cpp
new file mode 100644
index 0000000..aa7d5d7
--- /dev/null
+++ b/src/Component.cpp
@@ -0,0 +1,254 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+#include <IceStorm/IceStorm.h>
+
+#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
+#include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/Discovery/LocatorRegistrationWrapper.h>
+
+#include "BridgeManagerImpl.h"
+#include "BridgeReplicatorStateListenerI.h"
+#include "BridgeReplicationContext.h"
+
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::BridgeService;
+using namespace AsteriskSCF::Bridge::V1;
+using namespace AsteriskSCF::Replication;
+using namespace AsteriskSCF::Discovery;
+using namespace std;
+
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
+}
+
+namespace
+{
+
+class Component : public AsteriskSCF::Component::Component
+{
+public:
+    Component() : 
+        AsteriskSCF::Component::Component(lg, 
+                                          "BridgeService"),
+        mListeningToReplicator(false)   {}
+
+private:
+    // Optional base Component notification overrides. 
+    virtual void onActivated();
+    virtual void onPreInitialize();
+    virtual void onPostInitialize();
+    virtual void onStop();
+
+    // Required base Component overrides
+    virtual void createPrimaryServices();
+    virtual void preparePrimaryServicesForDiscovery();
+    virtual void createReplicationStateListeners();
+    virtual void stopListeningToStateReplicators();
+    virtual void listenToStateReplicators();
+    virtual void findRemoteServices() {};  // N/A
+
+    // Other base Component overrides
+    virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
+
+    ReplicatorSmartPrx mReplicator;
+    BridgeManagerServantPtr mBridgeManager;
+    BridgeManagerPrx mBridgeManagerPrx;
+    LocatorRegistrationWrapperPtr mBridgeManagerRegistration;
+    RegisterThreadPtr mRegisterThread;
+    ReplicatorListenerPrx mReplicatorListenerPrx;
+    bool mListeningToReplicator;
+    boost::shared_mutex mReplicatorLock;
+};
+
+/**
+ * Override of factory method of the base Component class. Out custom 
+ * version allows us to attach our replicator proxy to the context.
+ */
+ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
+{
+    // Find our state replicator. 
+    ServiceLocatorParamsPtr searchParams = new ServiceLocatorParams;
+    searchParams->category = StateReplicatorDiscoveryCategory;
+    searchParams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
+               "Bridge.StateReplicatorService", "default");
+    searchParams->id = getCommunicator()->getProperties()->getProperty("Bridge.StateReplicatorId");
+
+    ReplicatorSmartPrx replicator;
+    try
+    {
+        replicator = ReplicatorSmartPrx(getServiceLocator(), searchParams, lg);
+    }
+    catch (const std::exception& ex)
+    {
+        lg(Error) << "Bridge state replicator lookup failed. Continuing without replication. " << ex.what();
+    }
+
+    BridgeReplicationContextPtr context(new BridgeReplicationContext(state, replicator));
+    return context;
+}
+
+void Component::onPostInitialize()
+{
+    if (getReplicationContext()->isActive())
+    {
+       mBridgeManager->activate(); 
+    }
+}
+
+void Component::onActivated()
+{
+    mBridgeManager->activate(); // TBD...Is this really needed? Is there really no standby() correlary?
+}
+
+void Component::onPreInitialize()
+{
+    lg(Debug) << "Launching AsteriskSCF Session-Oriented Bridging Service " << getName();
+}
+
+/** 
+ * Create our servant implementations.
+ */
+void Component::createPrimaryServices()
+{
+     std::string managerName = 
+        getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".ManagerId", "BridgeManager");
+
+    //
+    // It's very important that uncheckedCast's be used here as there are no guarantees
+    // that the object adapter is activated yet. If it is not, then this can hang.
+    //
+    BridgeReplicationContextPtr replicationContext = boost::static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+    mBridgeManager = createBridgeManager(getServiceAdapter(), managerName, replicationContext, lg);
+    mBridgeManagerPrx = BridgeManagerPrx::uncheckedCast(getServiceAdapter()->add(mBridgeManager, 
+          getCommunicator()->stringToIdentity(managerName)));
+    assert(mBridgeManagerPrx != 0);
+    if (mBridgeManagerPrx == 0)
+    {
+        throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge manager object");
+    }
+}
+
+/**
+ * Wrap our servants for the locator service.
+ */
+void Component::preparePrimaryServicesForDiscovery()
+{
+    try
+    {
+        mBridgeManagerRegistration = this->wrapServiceForRegistration(mBridgeManagerPrx,
+                                                                      BridgeManagerDiscoveryCategory);
+        managePrimaryService(mBridgeManagerRegistration);
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << "Exception in " << BOOST_CURRENT_FUNCTION << e.what(); 
+        throw;
+    }
+}
+
+void Component::createReplicationStateListeners()
+{
+    ReplicatorListenerPtr replicaListener = createStateListener(lg, mBridgeManager);
+    mReplicatorListenerPrx = ReplicatorListenerPrx::uncheckedCast(getBackplaneAdapter()->addWithUUID(replicaListener));
+}
+
+void Component::listenToStateReplicators()
+{
+    boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+    BridgeReplicationContextPtr bridgeReplicationContext = 
+        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+
+    if (mListeningToReplicator == true)
+    {
+        return;
+    }
+
+    if (!bridgeReplicationContext->getReplicator().isInitialized())
+    {
+        lg(Error) << getName() << ": " << BOOST_CURRENT_FUNCTION << ": State replicator could not be found. Unable to listen for state updates!";
+        return;
+    }
+
+    try
+    {
+        // Are we in standby mode?
+        if (bridgeReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+        {
+            bridgeReplicationContext->getReplicator().tryOneWay()->addListener(mReplicatorListenerPrx);
+            mListeningToReplicator = true;
+        }
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
+}
+
+void Component::stopListeningToStateReplicators()
+{
+    boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+    BridgeReplicationContextPtr bridgeReplicationContext = 
+        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+
+    if ((!bridgeReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+    {
+        return;
+    }
+
+    try
+    {
+        bridgeReplicationContext->getReplicator().tryOneWay()->removeListener(mReplicatorListenerPrx);
+        mListeningToReplicator = false;
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
+}
+
+/**
+ * Override of stop notification. 
+ */
+void Component::onStop()
+{
+    if (mRegisterThread)
+    {
+        mRegisterThread->stop();
+    }
+}
+
+}
+
+extern "C" {
+ASTERISK_SCF_ICEBOX_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new Component;
+}
+}
diff --git a/src/Service.cpp b/src/Service.cpp
deleted file mode 100644
index fd3fcd6..0000000
--- a/src/Service.cpp
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010-2011, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-
-#include <Ice/Ice.h>
-#include <IceBox/IceBox.h>
-#include <IceStorm/IceStorm.h>
-
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include <AsteriskSCF/logger.h>
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
-#include "ServiceUtil.h"
-#include "BridgeManagerImpl.h"
-#include "BridgeReplicatorStateListenerI.h"
-
-using namespace AsteriskSCF::System::Logging;
-using namespace AsteriskSCF::SessionCommunications::V1;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::System::Component::V1;
-using namespace AsteriskSCF::BridgeService;
-using namespace AsteriskSCF::Bridge::V1;
-using namespace AsteriskSCF;
-using namespace std;
-
-namespace
-{
-
-class ReplicaControl : virtual public Replica
-{
-public:
-    ReplicaControl(const Ice::ObjectAdapterPtr& adapter, const BridgeManagerServantPtr& manager, const string& id) :
-        mActive(true),
-        mAdapter(adapter),
-        mManager(manager),
-        mReplicaId(id)
-    {
-    }
-
-    bool isActive(const Ice::Current&)
-    {
-        return mActive;
-    }
-
-    bool activate(const Ice::Current&)
-    {
-        mActive = true;
-        mManager->activate();
-        for (vector<ReplicaListenerPrx>::const_iterator i = mListeners.begin(); i != mListeners.end(); ++i)
-        {
-            (*i)->activated(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(mReplicaId))));
-        }
-        return true;
-    }
-
-    void standby(const Ice::Current&)
-    {
-        mActive = false;
-        for (vector<ReplicaListenerPrx>::const_iterator i = mListeners.begin(); i != mListeners.end(); ++i)
-        {
-            (*i)->onStandby(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(mReplicaId))));
-        }
-    }
-
-    void addListener(const ReplicaListenerPrx& listener, const Ice::Current&)
-    {
-        mListeners.push_back(listener);
-    }
-
-    void removeListener(const ReplicaListenerPrx& listener, const Ice::Current&)
-    {
-        mListeners.erase(remove(mListeners.begin(), mListeners.end(), listener), mListeners.end());
-    }
-    
-private:
-    bool mActive;
-    Ice::ObjectAdapterPtr mAdapter;
-    vector<ReplicaListenerPrx> mListeners;
-    BridgeManagerServantPtr mManager;
-    string mReplicaId;
-};
-typedef IceUtil::Handle<ReplicaControl> ReplicaControlPtr;
-
-class BridgingApp : public IceBox::Service
-{
-public:
-    BridgingApp();
-
-protected:
-    void start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args);
-    void stop();
-
-private:
-    /**
-     * A proxy to the service locator manager for the bridge manager service.
-     */
-    IceUtil::Handle<LocatorRegistrationWrapper<BridgeManagerPrx> > mLocator;
-    Ice::ObjectAdapterPtr mAdapter;
-    Ice::ObjectAdapterPtr mInfrastructureAdapter;
-    IceUtil::Handle<RegisterThread<BridgeManagerPrx> > mRegisterThread;
-    ReplicaControlPtr mReplicaControl;
-};
-
-BridgingApp::BridgingApp()
-{
-}
-
-void BridgingApp::start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq&)
-{
-    Logger logger = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
-    logger(Debug) << "Launching AsteriskSCF Session-Oriented Bridging Service." ;
-
-    //
-    // It is standard practice to base the adapter name on the configured
-    // service instance name.
-    //
-    std::string adapterName;
-    if (name.size() == 0)
-    {
-        adapterName = "BridgeService";
-    }
-    else
-    {
-        adapterName = name + ".BridgeService";
-    }
-
-    //
-    // Check on the threadpool properties, make sure that they are compatible with the requirements of this 
-    // service. This could be moved into a helper method, but it is somehow more clear for seeing what
-    // is going on during initialization to leave it here.
-    //
-    // TODO: Are there any other properties that need to be double-checked before proceeding?
-    //
-    Ice::Int defaultPoolSize = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 0);
-    if (communicator->getProperties()->getPropertyAsIntWithDefault(adapterName + ".ThreadPool.Size", 0) < 4)
-    {
-        if (defaultPoolSize < 4)
-        {
-            logger(Info) << "Configured thread pool size for " << adapterName + " is too small, defaulting to 4";
-            communicator->getProperties()->setProperty(adapterName + ".ThreadPool.Size", "4");
-        }
-    }
-    if (communicator->getProperties()->getPropertyAsIntWithDefault(adapterName + "Internal.ThreadPool.Size", 0) < 4)
-    {
-        if (defaultPoolSize < 4)
-        {
-            logger(Info) << "Configured thread pool size for " << adapterName + "Internal is too small, defaulting to 4";
-            communicator->getProperties()->setProperty(adapterName + "Internal.ThreadPool.Size", "4");
-        }
-    }
-    defaultPoolSize = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 0);
-    if (defaultPoolSize < 4)
-    {
-        logger(Warning) << "Client thread pool size is too small. It should be set to 4 or greater";
-    }
-
-    
-    //
-    // TODO: All adapter ids should be globally unique. This would allow replicas to be identified.
-    // How this might be useful is that it might be used as a replicated state item to identify
-    // which adapter is currently the primary in a group of replicas.
-    //
-    mAdapter = communicator->createObjectAdapterWithEndpoints(adapterName, 
-        communicator->getProperties()->getPropertyWithDefault(adapterName + ".Endpoints", "default"));
-
-    //
-    // We do not activate the main object adapter until most everything is initialized. The infrastructure
-    // adapter is for internally accessed objects or for supporting things that will be externally
-    // accessible until later so activating it now is fine.
-    //
-    mInfrastructureAdapter = communicator->createObjectAdapterWithEndpoints(adapterName + "Internal",
-        communicator->getProperties()->getPropertyWithDefault(adapterName + "Internal.Endpoints", "default"));
-    mInfrastructureAdapter->activate();
-
-    //
-    // Configure the AsteriskSCF logger.
-    // TODO: check whether this works right if we've already created the logger object.
-    //
-    ConfiguredIceLoggerPtr iceLogger = createIceLogger(mAdapter);
-    if (iceLogger)
-    {
-        getLoggerFactory().setLogOutput(iceLogger->getLogger());
-    }
-
-    //
-    // While this property is checked early in this method, it is not used until later on.
-    // This is to avoid several initialization steps if the final steps of initialization
-    // cannot be performed.
-    //
-    std::string serviceLocatorManagementProperty = communicator->getProperties()->getProperty("ServiceLocatorManagementProxy");
-    if (serviceLocatorManagementProperty.empty())
-    {
-        throw IceBox::FailureException(__FILE__, __LINE__, 
-            "Configuration error: Unable to locate property `ServiceLocatorManagementProxy'");
-    }
-
-    string locatorPropertyString = communicator->getProperties()->getProperty("LocatorService.Proxy");
-    if (locatorPropertyString.empty())
-    {
-        throw IceBox::FailureException(__FILE__, __LINE__,
-            "Configuration error: Unable to locate property `LocatorService.Proxy`");
-    }
-    
-    ServiceLocatorPrx locator = ServiceLocatorPrx::checkedCast(communicator->stringToProxy(locatorPropertyString));
-       
-    BridgeStateReplicatorParamsPtr searchParams = new BridgeStateReplicatorParams;
-    searchParams->category = StateReplicatorDiscoveryCategory;
-    searchParams->name = communicator->getProperties()->getPropertyWithDefault("Bridge.StateReplicatorName", "default");
-  
-    ReplicatorSmartPrx replicator;
-    try
-    {
-        replicator = ReplicatorSmartPrx(locator, searchParams, logger);
-    }
-    catch (const std::exception& ex)
-    {
-        logger(Error) << "Bridge state replicator lookup failed. Continuing without replication. " << ex.what();
-    }
-   
-    std::string managerName = 
-        communicator->getProperties()->getPropertyWithDefault(name + ".ManagerId", "BridgeManager");
-
-    //
-    // It's very important that uncheckedCast's be used here as there are no guarantees
-    // that the object adapter is activated yet. If it is not, then this can hang.
-    //
-    BridgeManagerServantPtr manager = createBridgeManager(mAdapter, managerName, replicator, logger);
-    BridgeManagerPrx bridgeManagerPrx = BridgeManagerPrx::uncheckedCast(mAdapter->add(manager, 
-          mAdapter->getCommunicator()->stringToIdentity(managerName)));
-    assert(bridgeManagerPrx != 0);
-    if (bridgeManagerPrx == 0)
-    {
-        throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge manager object");
-    }
-
-    //
-    // Configure replication connections.
-    //
-    ReplicatorListenerPtr replicaListener = createStateListener(logger, manager);
-    ReplicatorListenerPrx listenerPrx = ReplicatorListenerPrx::uncheckedCast(mInfrastructureAdapter->addWithUUID(replicaListener));
-
-    string replicaId = 
-        mAdapter->getCommunicator()->getProperties()->getPropertyWithDefault(
-            adapterName + ".ReplicaId", "BridgeReplica");
-    mReplicaControl = new ReplicaControl(mInfrastructureAdapter, manager, replicaId);
-    ReplicaPrx replicaControlPrx =
-        ReplicaPrx::uncheckedCast(mInfrastructureAdapter->add(mReplicaControl, communicator->stringToIdentity(replicaId)));
-
... 235 lines suppressed ...


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list