[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "basecomponent" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jul 12 09:21:55 CDT 2011
branch "basecomponent" has been created
at c7526b263e28dbda80f8efb88efae882bcdfffe1 (commit)
- Log -----------------------------------------------------------------
commit c7526b263e28dbda80f8efb88efae882bcdfffe1
Author: Ken Hunt <ken.hunt at digium.com>
Date: Tue Jul 12 09:17:49 2011 -0500
Bridge service works using new Component base 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 a66e867..6f31fe4 100644
--- a/config/test_bridging.conf
+++ b/config/test_bridging.conf
@@ -11,6 +11,8 @@ Ice.Default.CollocationOptimized=0
Ice.Override.Timeout=5000
+Ice.Warn.UnknownProperties=0
+
#
# We use a single file for configuration.
#
@@ -106,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.
@@ -130,15 +132,19 @@ 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, you may wish to uncomment the explicit endpoint
+# specification.
#
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/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/BridgeReplicatorService.cpp b/src/BridgeReplicatorService.cpp
index 952189a..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'");
}
//
@@ -152,9 +157,12 @@ void BridgeReplicatorApp::start(const string& name, const Ice::CommunicatorPtr&
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..0f87b1e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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/Service.cpp b/src/Service.cpp
index 408fff1..da2c161 100644
--- a/src/Service.cpp
+++ b/src/Service.cpp
@@ -23,9 +23,12 @@
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
#include <AsteriskSCF/System/Component/ReplicaIf.h>
-#include "ServiceUtil.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;
@@ -34,305 +37,187 @@ using namespace AsteriskSCF::System::Component::V1;
using namespace AsteriskSCF::BridgeService;
using namespace AsteriskSCF::Bridge::V1;
using namespace AsteriskSCF;
+using namespace AsteriskSCF::Component;
+using namespace AsteriskSCF::Replication;
+using namespace AsteriskSCF::Discovery;
using namespace std;
+
namespace
{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
+}
-class ReplicaControl : virtual public Replica
+namespace
{
-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
+class BridgingApp : public Component
{
public:
BridgingApp();
protected:
- void start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args);
- void stop();
+ // Optional notification overrides.
+ virtual void onActivated();
+ virtual void onPreInitialize();
+ virtual void onPostInitialize();
+ virtual void onStop();
+
+ // Required Component overrides
+ virtual void createPrimaryServices();
+ virtual void registerPrimaryServices();
+ virtual void createReplicationStateListeners();
+ virtual void stopListeningToStateReplicators();
+ virtual void listenToStateReplicators();
+ virtual void findRemoteServices() {}
+
+ // Other overrides
+ virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
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;
+ ReplicatorSmartPrx mReplicator;
+ BridgeManagerServantPtr mBridgeManager;
+ BridgeManagerPrx mBridgeManagerPrx;
+ LocatorRegistrationWrapperPtr mBridgeManagerRegistration;
+ RegisterThreadPtr mRegisterThread;
+ ReplicatorListenerPrx mReplicatorListenerPrx;
};
-BridgingApp::BridgingApp()
+BridgingApp::BridgingApp() :
+ AsteriskSCF::Component::Component(lg,
+ "BridgeService")
{
}
-void BridgingApp::start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq&)
+ReplicationContextPtr BridgingApp::createReplicationContext(ReplicationStateType state)
{
- 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";
- }
+ // 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");
- //
- // 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)
+ ReplicatorSmartPrx replicator;
+ try
{
- 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");
- }
+ replicator = ReplicatorSmartPrx(getServiceLocator(), searchParams, lg);
}
- defaultPoolSize = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 0);
- if (defaultPoolSize < 4)
+ catch (const std::exception& ex)
{
- logger(Warning) << "Client thread pool size is too small. It should be set to 4 or greater";
+ lg(Error) << "Bridge state replicator lookup failed. Continuing without replication. " << ex.what();
}
-
- //
- // 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();
+ BridgeReplicationContextPtr context(new BridgeReplicationContext(state, replicator));
+ return context;
+}
- //
- // Configure the AsteriskSCF logger.
- // TODO: check whether this works right if we've already created the logger object.
- //
- ConfiguredIceLoggerPtr iceLogger = createIceLogger(mAdapter);
- if (iceLogger)
+void BridgingApp::onPostInitialize()
+{
+ if (getReplicationContext()->isActive())
{
- getLoggerFactory().setLogOutput(iceLogger->getLogger());
+ mBridgeManager->activate();
}
+}
- //
- // 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'");
- }
+void BridgingApp::onActivated()
+{
+ mBridgeManager->activate(); // TBD...Is this really needed? Is there really no standby() correlary?
+}
- 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));
-
- std::string replicatorServiceName = communicator->getProperties()->getPropertyWithDefault(
- "Bridge.StateReplicatorService", "default");
+void BridgingApp::onPreInitialize()
+{
+ lg(Debug) << "Launching AsteriskSCF Session-Oriented Bridging Service " << getName();
+}
- ServiceLocatorParamsPtr searchParams = new ServiceLocatorParams;
- searchParams->category = StateReplicatorDiscoveryCategory;
- searchParams->service = replicatorServiceName;
- searchParams->id = communicator->getProperties()->getPropertyWithDefault("Bridge.StateReplicatorId", "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");
+void BridgingApp::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.
//
- BridgeManagerServantPtr manager = createBridgeManager(mAdapter, managerName, replicator, logger);
- BridgeManagerPrx bridgeManagerPrx = BridgeManagerPrx::uncheckedCast(mAdapter->add(manager,
- mAdapter->getCommunicator()->stringToIdentity(managerName)));
- assert(bridgeManagerPrx != 0);
- if (bridgeManagerPrx == 0)
+ 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");
}
+}
- //
- // 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)));
-
- bool onStandby = false;
- if (replicator)
- {
- onStandby = communicator->getProperties()->getPropertyWithDefault(name + ".StateReplicatorListener", "no") == "yes";
- }
- if (onStandby)
- {
- replicator->addListener(listenerPrx);
- replicaControlPrx->standby();
- }
- else
- {
- manager->activate();
- }
-
+void BridgingApp::registerPrimaryServices()
+{
bool registered = false;
try
{
- std::string serviceName = communicator->getProperties()->getPropertyWithDefault(
- adapterName + ".Service", "default");
+ std::string serviceName = getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".Service", "default");
ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
- parameters->category = BridgeServiceDiscoveryCategory;
+ parameters->category = BridgeManagerDiscoveryCategory;
parameters->service = serviceName;
- parameters->id = adapterName;
- mLocator =
- new LocatorRegistrationWrapper<BridgeManagerPrx>(communicator, serviceLocatorManagementProperty, bridgeManagerPrx,
- adapterName, parameters);
- registered = mLocator->registerService();
+ parameters->id = getName();
+
+ mBridgeManagerRegistration =
+ new LocatorRegistrationWrapper(getCommunicator(), getServiceLocatorManagementProperty(), mBridgeManagerPrx,
+ getName(), parameters);
+ registered = registerPrimaryService(mBridgeManagerRegistration);
}
- catch (const Ice::Exception&)
+ catch (const Ice::Exception& e)
{
+ lg(Error) << "Exception registering services in " << BOOST_CURRENT_FUNCTION << e.what();
+ throw;
}
+
if (!registered)
{
- mRegisterThread = new RegisterThread<BridgeManagerPrx>(mLocator);
+ mRegisterThread = new RegisterThread(mBridgeManagerRegistration);
mRegisterThread->start();
}
- //
- // TODO: We need to know whether or not to activate!
- //
- mAdapter->activate();
}
-void BridgingApp::stop()
+void BridgingApp::createReplicationStateListeners()
+{
+ ReplicatorListenerPtr replicaListener = createStateListener(lg, mBridgeManager);
+ mReplicatorListenerPrx = ReplicatorListenerPrx::uncheckedCast(getBackplaneAdapter()->addWithUUID(replicaListener));
+}
+
+void BridgingApp::listenToStateReplicators()
+{
+ ReplicationContextPtr replication = getReplicationContext();
+ static_pointer_cast<BridgeReplicationContext>(replication)->getReplicator()->addListener(mReplicatorListenerPrx);
+}
+
+void BridgingApp::stopListeningToStateReplicators()
+{
+ ReplicationContextPtr replication = getReplicationContext();
+ static_pointer_cast<BridgeReplicationContext>(replication)->getReplicator()->removeListener(mReplicatorListenerPrx);
+}
+
+/**
+ * Override of stop notification.
+ */
+void BridgingApp::onStop()
{
if (mRegisterThread)
{
mRegisterThread->stop();
}
+
try
{
- mLocator->unregister();
+ mBridgeManagerRegistration->unregister();
}
catch (const Ice::Exception&)
{
}
- try
- {
- Ice::CommunicatorPtr comm = mAdapter->getCommunicator();
- comm->shutdown();
- mAdapter->waitForDeactivate();
- mInfrastructureAdapter->waitForDeactivate();
- comm->destroy();
- }
- catch (...)
- {
- // TODO: log
- }
}
+
}
extern "C" {
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index f5569e9..aa6f328 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -126,7 +126,7 @@ private:
// the correct one.
//
ServiceLocatorParamsPtr searchParams(new ServiceLocatorParams);
- searchParams->category = BridgeServiceDiscoveryCategory;
+ searchParams->category = BridgeManagerDiscoveryCategory;
Ice::ObjectProxySeq results = locator->locateAll(searchParams);
if (results.size() < 2)
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/bridging.git
More information about the asterisk-scf-commits
mailing list