[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "basecomponent" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Jun 30 15:40:51 CDT 2011
branch "basecomponent" has been updated
via e0d0d56b39c7a870d650b262f415a4a4d49dd514 (commit)
from 48ec22a79bae9c6613c8983be7c079b74fb45106 (commit)
Summary of changes:
include/AsteriskSCF/Component/Component.h | 18 +++--
.../Discovery/LocatorRegistrationWrapper.h | 9 +--
.../AsteriskSCF/Replication/ReplicationContext.h | 39 ++++++-----
src/Component/Component.cpp | 72 +++++++++++---------
src/Replication/ReplicationContext.cpp | 29 ++------
test/Component/.component-base-test.conf.swp | Bin 12288 -> 0 bytes
test/Component/CMakeLists.txt | 3 +-
test/Component/ComponentTest.cpp | 10 ++--
test/Component/MockComponent.cpp | 5 +-
.../LocatorRegistrationTest.cpp | 6 +-
10 files changed, 96 insertions(+), 95 deletions(-)
delete mode 100644 test/Component/.component-base-test.conf.swp
- Log -----------------------------------------------------------------
commit e0d0d56b39c7a870d650b262f415a4a4d49dd514
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Jun 30 15:40:53 2011 -0500
Incorporated review feedback.
diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index 2a6009f..00531ac 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -1,7 +1,7 @@
/*
* Asterisk SCF -- An open-source communications framework.
*
- * Copyright (C) 2010, Digium, Inc.
+ * Copyright (C) 2011, Digium, Inc.
*
* See http://www.asterisk.org for more information about
* the Asterisk SCF project. Please do not directly contact
@@ -65,7 +65,8 @@ protected:
/////////////////////////////////////////////////////////////////////
// Notification for some of
// the component events.
- virtual void onInitialize() {}
+ virtual void onPreInitialize() {}
+ virtual void onPostInitialize() {}
virtual void onSuspend() {}
virtual void onResume() {}
virtual void onStop() {}
@@ -74,8 +75,9 @@ protected:
virtual void onStandby() {}
/////////////////////////////////////////////////////////////////////
- // Every component must provded
- // custom implementations.
+ // Every component must provide custom
+ // implementations of these replication
+ // operations.
virtual void createReplicationStateListeners() = 0;
/**
@@ -118,10 +120,11 @@ protected:
void unsuspendBackplaneServices();
/////////////////////////////////////////////////////////////////////
- // Accessors to state variables
+ // Accessors to state.
AsteriskSCF::Replication::ReplicationContextPtr getReplicationContext() {return mReplicationContext;}
AsteriskSCF::Component::TestContextPtr getTestContext() {return mTestContext;}
- std::string getComponentName() {return mComponentName;}
+ std::string getName() {return mName;}
+ std::string getServiceName() {return mServiceName;}
Ice::CommunicatorPtr getCommunicator() {return mCommunicator;}
Ice::StringSeq getArgs() {return mArgs;}
AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx getServiceLocatorManagement() {return mServiceLocatorManagement;}
@@ -153,7 +156,8 @@ private:
std::string mComponentDiscoveryCategory;
- std::string mComponentName;
+ std::string mName;
+ std::string mServiceName;
Ice::CommunicatorPtr mCommunicator;
Ice::StringSeq mArgs;
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index ff4a061..2812e62 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -143,19 +143,18 @@ typedef IceUtil::Handle<LocatorRegistrationWrapper> LocatorRegistrationWrapperPt
* This thread takes care of registering the registration wrapper instance if the service discovery components are
* unavailable during startup.
**/
-template <class T>
class RegisterThread : public IceUtil::Thread
{
public:
- RegisterThread(const IceUtil::Handle<LocatorRegistrationWrapper>& registration,
- const IceUtil::Time& retryInterval) :
+ RegisterThread(const LocatorRegistrationWrapperPtr& registration,
+ const IceUtil::Time& retryInterval) :
mRegistration(registration),
mRetryInterval(retryInterval),
mStopped(false)
{
}
- RegisterThread(const IceUtil::Handle<LocatorRegistrationWrapper>& registration) :
+ RegisterThread(const LocatorRegistrationWrapperPtr& registration) :
mRegistration(registration),
mRetryInterval(IceUtil::Time::seconds(15)),
mStopped(false)
@@ -193,7 +192,7 @@ public:
private:
IceUtil::Monitor<IceUtil::Mutex> mMonitor;
- IceUtil::Handle<LocatorRegistrationWrapper> mRegistration;
+ LocatorRegistrationWrapperPtr mRegistration;
IceUtil::Time mRetryInterval;
bool mStopped;
};
diff --git a/include/AsteriskSCF/Replication/ReplicationContext.h b/include/AsteriskSCF/Replication/ReplicationContext.h
index eebe1ba..1b1950f 100644
--- a/include/AsteriskSCF/Replication/ReplicationContext.h
+++ b/include/AsteriskSCF/Replication/ReplicationContext.h
@@ -22,6 +22,14 @@ namespace AsteriskSCF
{
namespace Replication
{
+
+enum ReplicationStateType
+{
+ ACTIVE_STANDALONE,
+ ACTIVE_IN_REPLICA_GROUP,
+ STANDBY_IN_REPLICA_GROUP
+};
+
class ReplicationContextPriv;
/**
@@ -31,37 +39,32 @@ class ReplicationContextPriv;
class ReplicationContext
{
public:
- ReplicationContext(bool componentIsActive, bool standalone);
+ ReplicationContext(ReplicationStateType initialState);
/**
- * Returns true if this component is active, non-standalone.
+ * The default implementation returns true if this component is
+ * in ACTIVE_IN_REPLICA_GROUP state.
+ *
+ * This operation is virtual so that subclasses can
+ * add other criteria, such as whether the component
+ * has valid proxies to state replicators.
*/
virtual bool isReplicating();
/**
- * Indicates whether this component is in active (as opposed to standby) mode.
- */
- bool isComponentActive();
-
- /**
- * If true, the component is in standalone mode.
+ * Gets the current state.
* @see isReplicating
*/
- bool isStandalone();
-
- /**
- * Changes this context to reflect active mode.
- */
- void setComponentActive();
+ ReplicationStateType getState();
/**
- * Changes this context to reflect standby mode.
+ * Changes this context to reflect a specific state.
+ * @param newState New context state.
*/
- void setComponentStandby();
+ void setState(ReplicationStateType newState);
private:
- bool mActive;
- bool mStandalone;
+ ReplicationStateType mState;
boost::shared_mutex mLock;
};
typedef boost::shared_ptr<ReplicationContext> ReplicationContextPtr;
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index 7585eba..9d6e679 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -46,7 +46,7 @@ static const string ComponentServiceProxyId("ComponentService");
static const string ReplicaProxyId("Replica");
/**
- * This class provides implementation for the ComponentService interface.
+ * This class provides an implementation of the ComponentService interface.
* Every Asterisk SCF component is expected to expose the ComponentService interface.
*/
class ComponentServiceImpl : public ComponentService
@@ -81,8 +81,10 @@ private:
}; // class ComponentServiceImpl
/**
- * This interface is published as a facet of the Component Service interface.
- * It exists to allow additional control of a component during testing.
+ * This interface exists to allow optional, additional control of a
+ * component during testing. This interface is usually published
+ * as an additional facet of the same object identity used to publish
+ * the Component Service interface.
*/
class ComponentTestImpl : public ComponentTest
{
@@ -120,7 +122,9 @@ private:
}; // class ComponentTestImpl
/**
- * This class provides implementation for this component's Replica management interface.
+ * This class provides an implementation of this component's Replica interface,
+ * used to manage the component's replication state.
+ *
* TBD... Use ListenerManager template to notify listeners.
*/
class ReplicaImpl : public Replica
@@ -216,9 +220,6 @@ private:
}; // class ReplicaImpl
-/**
- * Constructor.
- */
Component::Component(const AsteriskSCF::System::Logging::Logger& logger,
const std::string& componentDiscoveryCategory) :
mInitialized(false),
@@ -258,12 +259,12 @@ void Component::clearTestModes()
bool Component::isActive()
{
// The Replication Context is tracking our current status.
- return mReplicationContext->isComponentActive();
+ return (mReplicationContext->getState() != STANDBY_IN_REPLICA_GROUP);
}
void Component::activated()
{
- mReplicationContext->setComponentActive();
+ mReplicationContext->setState(ACTIVE_IN_REPLICA_GROUP);
stopListeningToStateReplicators();
// Notify subclasses
@@ -272,7 +273,7 @@ void Component::activated()
void Component::standby()
{
- mReplicationContext->setComponentStandby();
+ mReplicationContext->setState(STANDBY_IN_REPLICA_GROUP);
listenToStateReplicators();
// Notify subclasses
@@ -309,19 +310,20 @@ void Component::registerBackplaneServices()
{
ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
parameters->category = mComponentDiscoveryCategory;
- parameters->id = mComponentName + ".ComponentService";
+ parameters->service = mServiceName;
+ parameters->id = mName;
mComponentRegistration =
new LocatorRegistrationWrapper(mCommunicator,
getServiceLocatorManagementProperty(),
mComponentServicePrx,
- mComponentName + ".ComponentService",
+ mName + ".ComponentService",
parameters);
registerBackplaneService(mComponentRegistration);
}
if (mPublishTestInterface)
{
- // Register our test servant as a facet of the ComponentService interface.
+ // Register our test servant as a facet of the ComponentService's object identity.
mComponentTestPrx = ComponentTestPrx::uncheckedCast(
mBackplaneAdapter->addFacet(mComponentTest,
mComponentServicePrx->ice_getIdentity(),
@@ -333,7 +335,8 @@ void Component::registerBackplaneServices()
{
ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
parameters->category = mComponentDiscoveryCategory + ".Replica";
- parameters->id = mComponentName + ".Replica";
+ parameters->service = mServiceName;
+ parameters->id = mName;
mReplicaRegistration =
new LocatorRegistrationWrapper(mCommunicator,
getServiceLocatorManagementProperty(),
@@ -345,7 +348,7 @@ void Component::registerBackplaneServices()
}
catch(const std::exception& e)
{
- mLogger(Error) << "Exception in component " << mComponentName <<
+ mLogger(Error) << "Exception in component " << mName <<
" in " << BOOST_CURRENT_FUNCTION << ". Details: " << e.what();
throw;
}
@@ -483,10 +486,10 @@ void Component::createAdapters()
try
{
// Create the adapter that our functional services are published on.
- mServiceAdapter = mCommunicator->createObjectAdapter(mComponentName);
+ mServiceAdapter = mCommunicator->createObjectAdapter(mName);
// Create an adapter for our backplane services.
- mBackplaneAdapter = mCommunicator->createObjectAdapter(mComponentName + ".Backplane");
+ mBackplaneAdapter = mCommunicator->createObjectAdapter(mName + ".Backplane");
}
catch(const std::exception& e)
{
@@ -522,15 +525,15 @@ void Component::initReplicationContext()
try
{
string standaloneProp = mCommunicator->getProperties()->getPropertyWithDefault(
- mComponentName + ".Standalone", "no");
+ mName + ".Standalone", "no");
bool standalone = boost::iequals(standaloneProp,"yes") ||
boost::iequals(standaloneProp,"true");
- bool active(false);
+ ReplicationStateType state(STANDBY_IN_REPLICA_GROUP);
if (standalone)
{
- active = true;
+ state = ACTIVE_STANDALONE;
}
else
{
@@ -538,15 +541,18 @@ void Component::initReplicationContext()
// instances that will default to being active. When that is in
// place, non-standalone instances will need to be made active via
// the Replica interface. But for now, we default to active unless
- // the Standby property is set.
+ // the soon-to-be obsolete Standby property is set.
string standbyProp =
- mCommunicator->getProperties()->getPropertyWithDefault(mComponentName + ".Standby", "no");
- active = boost::iequals(standbyProp,"no") || boost::iequals(standbyProp,"false");
+ mCommunicator->getProperties()->getPropertyWithDefault(mName + ".Standby", "no");
+ if (boost::iequals(standbyProp,"no") || boost::iequals(standbyProp,"false"))
+ {
+ state = ACTIVE_IN_REPLICA_GROUP;
+ }
}
// Create the replication context.
mReplicationContext = ReplicationContextPtr(
- new ReplicationContext(active, standalone));
+ new ReplicationContext(state));
}
catch(const std::exception& e)
{
@@ -601,7 +607,7 @@ void Component::createBackplaneServices()
{
// Check to see if we're configured to publish a test interface.
string testProp = mCommunicator->getProperties()->getPropertyWithDefault(
- mComponentName + ".ComponentTest", "no");
+ mName + ".ComponentTest", "no");
mPublishTestInterface = boost::iequals(testProp,"yes") || boost::iequals(testProp,"true");
if (mPublishTestInterface)
@@ -656,6 +662,8 @@ void Component::initialize()
{
try
{
+ onPreInitialize();
+
createAdapters();
initReplicationContext();
@@ -676,14 +684,14 @@ void Component::initialize()
}
catch(const ::Ice::Exception &e)
{
- mLogger(Error) << "Problems in " << mComponentName << BOOST_CURRENT_FUNCTION << e.what();
+ mLogger(Error) << "Problems in " << mName << BOOST_CURRENT_FUNCTION << e.what();
throw e;
}
findRemoteServices();
// Notify subclasses.
- onInitialize();
+ onPostInitialize();
}
/**
@@ -696,9 +704,11 @@ void Component::start(const string& name,
mLogger(Info) << "Starting...";
mCommunicator = communicator;
- mComponentName = name;
+ mName = name;
mArgs = args; // Arguments that weren't stripped off by IceBox.
+ mServiceName = mCommunicator->getProperties()->getPropertyWithDefault(mName + ".ServiceName", "default");
+
if (!mInitialized)
{
initialize();
@@ -715,7 +725,7 @@ void Component::start(const string& name,
registerPrimaryServices();
// Standby mode?
- if (!mReplicationContext->isComponentActive())
+ if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
{
listenToStateReplicators();
}
@@ -735,7 +745,7 @@ void Component::resumed()
if (!mRunning)
{
// Standby mode?
- if (!mReplicationContext->isComponentActive())
+ if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
{
listenToStateReplicators();
}
@@ -769,7 +779,7 @@ void Component::suspendService(bool shuttingDown)
}
// Standby mode?
- if (!mReplicationContext->isComponentActive())
+ if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
{
stopListeningToStateReplicators();
}
diff --git a/src/Replication/ReplicationContext.cpp b/src/Replication/ReplicationContext.cpp
index 0fa71dd..278fdf4 100644
--- a/src/Replication/ReplicationContext.cpp
+++ b/src/Replication/ReplicationContext.cpp
@@ -22,8 +22,8 @@ namespace AsteriskSCF
namespace Replication
{
-ReplicationContext::ReplicationContext(bool componentIsActive, bool standalone)
- : mActive(componentIsActive), mStandalone(standalone)
+ReplicationContext::ReplicationContext(ReplicationStateType initialState)
+ : mState(initialState)
{
}
@@ -31,36 +31,21 @@ bool ReplicationContext::isReplicating()
{
boost::shared_lock<boost::shared_mutex> lock(mLock);
- return mActive && !mStandalone;
+ return (mState == ACTIVE_IN_REPLICA_GROUP);
}
-bool ReplicationContext::isComponentActive()
+ReplicationStateType ReplicationContext::getState()
{
boost::shared_lock<boost::shared_mutex> lock(mLock);
- return mActive;
+ return mState;
}
-bool ReplicationContext::isStandalone()
-{
- boost::shared_lock<boost::shared_mutex> lock(mLock);
-
- return mStandalone;
-}
-
-void ReplicationContext::setComponentActive()
-{
- boost::unique_lock<boost::shared_mutex> lock(mLock);
-
- mActive = true;
-
-}
-
-void ReplicationContext::setComponentStandby()
+void ReplicationContext::setState(ReplicationStateType state)
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
- mActive = false;
+ mState = state;
}
} // end BasicRoutingService
diff --git a/test/Component/.component-base-test.conf.swp b/test/Component/.component-base-test.conf.swp
deleted file mode 100644
index 58afc30..0000000
Binary files a/test/Component/.component-base-test.conf.swp and /dev/null differ
diff --git a/test/Component/CMakeLists.txt b/test/Component/CMakeLists.txt
index e6f3127..3a6dc51 100644
--- a/test/Component/CMakeLists.txt
+++ b/test/Component/CMakeLists.txt
@@ -6,7 +6,6 @@ include_directories(${ice-util-cpp_dir}/include)
asterisk_scf_component_init(component-base-test-mockcomponent)
asterisk_scf_component_add_slice(component-base-test-mockcomponent ComponentTestIf.ice)
asterisk_scf_component_add_file(component-base-test-mockcomponent MockComponent.cpp)
-asterisk_scf_component_add_ice_libraries(component-base-test-mockcomponent IceBox)
asterisk_scf_component_add_boost_libraries(component-base-test-mockcomponent date_time thread)
asterisk_scf_component_build_icebox(component-base-test-mockcomponent)
target_link_libraries(component-base-test-mockcomponent asterisk-scf-api ice-util-cpp logging-client)
@@ -18,7 +17,7 @@ asterisk_scf_component_add_file(component-base-test ComponentTest.cpp)
asterisk_scf_component_add_boost_libraries(component-base-test unit_test_framework thread)
asterisk_scf_component_build_icebox(component-base-test)
target_link_libraries(component-base-test asterisk-scf-api ice-util-cpp logging-client)
-asterisk_scf_test_icebox(component-base-test component-base-test.conf)
+asterisk_scf_test_icebox(component-base-test test/Component/component-base-test.conf)
diff --git a/test/Component/ComponentTest.cpp b/test/Component/ComponentTest.cpp
index ce9d7fe..6ecc91f 100644
--- a/test/Component/ComponentTest.cpp
+++ b/test/Component/ComponentTest.cpp
@@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(LocateComponentService)
{
try
{
- ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory", "MockComponent.ComponentService");
+ ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory", "default", "MockComponent");
Ice::ObjectPrx prx = sharedTestData.mServiceLocator->locate(params);
BOOST_CHECK(prx != 0);
}
@@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(LocateReplica)
{
try
{
- ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory.Replica", "MockComponent.Replica");
+ ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory.Replica", "default", "MockComponent");
Ice::ObjectPrx prx = sharedTestData.mServiceLocator->locate(params);
BOOST_CHECK(prx != 0);
}
@@ -196,11 +196,11 @@ BOOST_AUTO_TEST_CASE(ManipulateComponentService)
try
{
- ServiceLocatorParamsPtr serviceparams = new ServiceLocatorParams("MockCategory", "MockComponent.ComponentService");
+ ServiceLocatorParamsPtr serviceparams = new ServiceLocatorParams("MockCategory", "default", "MockComponent");
componentService = ComponentServicePrx::uncheckedCast(sharedTestData.mServiceLocator->locate(serviceparams));
BOOST_CHECK(componentService != 0);
- ServiceLocatorParamsPtr mockservparams = new ServiceLocatorParams("MockService", "");
+ ServiceLocatorParamsPtr mockservparams = new ServiceLocatorParams("MockService", "default", "");
mockService = MockServicePrx::uncheckedCast(sharedTestData.mServiceLocator->locate(mockservparams));
BOOST_CHECK(mockService != 0);
@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(CheckReplica)
// The Replica is registered under the same category as the ComponentService + ".Replica".
// The unique id is the component's name + ".Replica"
- ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory.Replica", "MockComponent.Replica");
+ ServiceLocatorParamsPtr params = new ServiceLocatorParams("MockCategory.Replica", "default", "MockComponent");
ReplicaPrx prx = ReplicaPrx::uncheckedCast(sharedTestData.mServiceLocator->locate(params));
BOOST_CHECK(prx != 0);
diff --git a/test/Component/MockComponent.cpp b/test/Component/MockComponent.cpp
index c7d845b..cf5ec2c 100644
--- a/test/Component/MockComponent.cpp
+++ b/test/Component/MockComponent.cpp
@@ -137,7 +137,8 @@ void MockComponent::registerPrimaryServices()
{
ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
parameters->category = "MockService";
- parameters->id = "";
+ parameters->service = "default";
+ parameters->id = getName();
LocatorRegistrationWrapperPtr registration =
new LocatorRegistrationWrapper(getCommunicator(),
getServiceLocatorManagementProperty(),
@@ -148,7 +149,7 @@ void MockComponent::registerPrimaryServices()
}
catch(const std::exception& e)
{
- mLogger(Error) << "Exception in component " << getComponentName() <<
+ mLogger(Error) << "Exception in component " << getName() <<
" in " << BOOST_CURRENT_FUNCTION << ". Details: " << e.what();
throw;
}
diff --git a/test/LocatorRegistration/LocatorRegistrationTest.cpp b/test/LocatorRegistration/LocatorRegistrationTest.cpp
index 8f2cd09..c6a84ce 100644
--- a/test/LocatorRegistration/LocatorRegistrationTest.cpp
+++ b/test/LocatorRegistration/LocatorRegistrationTest.cpp
@@ -665,15 +665,15 @@ public:
params->category = "TestListener";
std::string id = IceUtil::generateUUID();
- IceUtil::Handle<LocatorRegistrationWrapper> registrationWrapper =
+ LocatorRegistrationWrapperPtr registrationWrapper =
new LocatorRegistrationWrapper(
mCommunicator,
mCommunicator->getProperties()->getProperty("LocatorServiceManager.Proxy"),
mClientEnvironment.proxy(),
id,
params);
- IceUtil::Handle<RegisterThread<AsteriskSCF::System::Discovery::EventsPrx> >
- t = new RegisterThread<AsteriskSCF::System::Discovery::EventsPrx>(registrationWrapper,
+ IceUtil::Handle<RegisterThread>
+ t = new RegisterThread(registrationWrapper,
IceUtil::Time::seconds(1));
t->start();
t->getThreadControl().join();
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list