[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
Fri Jul 8 17:48:13 CDT 2011


branch "basecomponent" has been updated
       via  5ed8071cafb4b82a0052b3b35adb9e33a9adf6eb (commit)
      from  e0d0d56b39c7a870d650b262f415a4a4d49dd514 (commit)

Summary of changes:
 include/AsteriskSCF/Component/Component.h          |   94 ++++++-
 .../Discovery/LocatorRegistrationWrapper.h         |    1 +
 include/AsteriskSCF/Helpers/PropertyHelper.h       |   39 +++
 .../AsteriskSCF/Replication/ReplicationContext.h   |   14 +-
 src/Component/Component.cpp                        |  277 +++++++++++++-------
 src/Replication/ReplicationContext.cpp             |    7 +
 .../LocatorRegistrationTest.cpp                    |    4 +-
 test/PropertyHelper/PropertyHelperTest.cpp         |   24 ++
 8 files changed, 347 insertions(+), 113 deletions(-)


- Log -----------------------------------------------------------------
commit 5ed8071cafb4b82a0052b3b35adb9e33a9adf6eb
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Jul 8 17:46:47 2011 -0500

    Incorporated more review feedback, and tested with actual components using the Component base.

diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index 00531ac..df3c44b 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -94,17 +94,81 @@ protected:
      */
     virtual void listenToStateReplicators() = 0;
 
+    /** 
+     * A factory method. 
+     * Allows subclasses to easily extend the ReplicationContext if needed. 
+     */
+    virtual AsteriskSCF::Replication::ReplicationContextPtr createReplicationContext(
+           AsteriskSCF::Replication::ReplicationStateType state);
+
     /////////////////////////////////////////////////////////////////////
-    // Operations called by the initialize method, which implements the
-    // Template Method pattern. 
+    // Operations called by the initialize() method. The initialize() method
+    // implements the Template Method pattern. These methods are called in 
+    // the order declared below. If you override any of the default implementations,
+    // you probably want to call the default implementation from your override. 
+
+    /**
+     * Verifies the configured parameters in the Ice config file meet
+     * minimum expectations, particularly thread pool sizes. If the do not, 
+     * this method alters the configuration and logs the changes.
+     */
+    virtual void verifyProperties();
+
+    /**
+     * Creates the primary service adapter and the backplane adapters. 
+     * If you need other adapter you can override this, but be sure to 
+     * call the default implementation from you override. 
+     */
     virtual void createAdapters();
+
+    /** 
+     * Activates the primary and backplane adapters. 
+     */
+    virtual void activateAdapters();
+
+    /**
+     * Acquires references to the Service Locator proxies that can be accessed
+     * with the getServiceLocatorManagement() and getServiceLocator() accessors. 
+     * The adapters must be activated prior to calling, which should always be
+     * the case due to the flow of the initialize() template method. 
+     */
+    virtual void initServiceLocatorProxies();
+
+    /**
+     * Creates a replication context using the factory method
+     * createReplicationContext(). Override the factory method if 
+     * you want to create a custom replication context. 
+     * Note: Custom context must derive from AsteriskSCF::Replication::ReplicationContext.
+     */
     virtual void initReplicationContext();
+
+    /**
+     * Creates a test context for component to use to detemine if it
+     * has test modes enabled. Support for test modes is optional. 
+     */
     virtual void initTestContext();
+
+    /**
+     * Create the logger. The generic implementation creates an IceLogger. 
+     */
     virtual void configureLogger();
+
+    /**
+     * Create all services to be associated with the primary service adapter. 
+     * Note: This is a required override. 
+     */
     virtual void createPrimaryServices() = 0;
+
+    /**
+     * Create any services to be associated with the primary service adapter. 
+     * If you override this operation, you should call the default implementation. 
+     */
     virtual void createBackplaneServices();
-    virtual void activateAdapters();
-    virtual void initServiceLocatorProxies();
+
+    /**
+     * A required override for the component to locate and cache any 
+     * proxies to remote services that it needs to operate. 
+     */
     virtual void findRemoteServices() = 0;
 
     /////////////////////////////////////////////////////////////////////
@@ -121,17 +185,17 @@ protected:
 
     /////////////////////////////////////////////////////////////////////
     // Accessors to state. 
-    AsteriskSCF::Replication::ReplicationContextPtr getReplicationContext() {return mReplicationContext;}
-    AsteriskSCF::Component::TestContextPtr getTestContext() {return mTestContext;}
-    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;}
-    AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx  getServiceLocator() {return mServiceLocator;}
-    Ice::ObjectAdapterPtr getServiceAdapter() {return mServiceAdapter;}
-    Ice::ObjectAdapterPtr getBackplaneAdapter() {return mBackplaneAdapter;}
-    std::string getServiceLocatorManagementProperty();
+    const AsteriskSCF::Replication::ReplicationContextPtr& getReplicationContext() const {return mReplicationContext;}
+    const AsteriskSCF::Component::TestContextPtr& getTestContext() const {return mTestContext;}
+    const std::string& getName() const {return mName;}
+    const std::string& getServiceName() const {return mServiceName;}
+    const Ice::CommunicatorPtr& getCommunicator() const {return mCommunicator;}
+    const Ice::StringSeq& getArgs() const {return mArgs;}
+    const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& getServiceLocatorManagement() const {return mServiceLocatorManagement;}
+    const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx&  getServiceLocator() const {return mServiceLocator;}
+    const Ice::ObjectAdapterPtr& getServiceAdapter() const {return mServiceAdapter;}
+    const Ice::ObjectAdapterPtr& getBackplaneAdapter() const {return mBackplaneAdapter;}
+    std::string getServiceLocatorManagementProperty() const;
 
     // State data
     AsteriskSCF::System::Logging::Logger mLogger;
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index 2812e62..95edc18 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -196,6 +196,7 @@ private:
     IceUtil::Time mRetryInterval;
     bool mStopped;
 };
+typedef IceUtil::Handle<RegisterThread> RegisterThreadPtr;
 
 } /* End of namespace Discovery */
 
diff --git a/include/AsteriskSCF/Helpers/PropertyHelper.h b/include/AsteriskSCF/Helpers/PropertyHelper.h
index b6579b8..6beb4c2 100644
--- a/include/AsteriskSCF/Helpers/PropertyHelper.h
+++ b/include/AsteriskSCF/Helpers/PropertyHelper.h
@@ -19,6 +19,7 @@
 #include <string>
 #include <vector>
 #include <boost/shared_ptr.hpp>
+#include <boost/algorithm/string/predicate.hpp>
 
 namespace AsteriskSCF
 {
@@ -41,6 +42,44 @@ inline std::string propGetSet(const Ice::PropertiesPtr& p, const std::string& pr
 }
 
 /**
+ * A method to convert a string to a boolean value. 
+ *
+ * Values that result in 'true': 
+ *   - "true", "True", "TRUE" or other case variants of "true"
+ *   - "yes", "Yes", "Yes" or other case variants of "yes"
+ *   - "1" 
+ * 
+ * All other values for valueStr result in a return of 'false'. 
+ */
+inline bool stringToBool(const std::string& valueStr)
+{
+    return boost::iequals(valueStr, "yes") || 
+           boost::iequals(valueStr, "true") ||
+           (valueStr.compare("1") == 0);
+}
+
+/**
+ * A method to get the boolean value represented by a named property from
+ * a Property set. 
+ *  @param properties The property expected to contain the named property. 
+ *  @param propertyName The name of the property that represents some boolean value.
+ *  @param defaultValue The value to return if the named property doesn't exist. 
+ *
+ *  @return The boolean value of the property with name 'propertyName', or 
+ * 'defaultvalue' if it the named property isn't found in 'properties'. 
+ */
+inline bool getBooleanPropertyWithDefault(const Ice::PropertiesPtr& properties, const std::string& propertyName, bool defaultValue)
+{
+    std::string defaultStr("no");
+    if (defaultValue)
+    {
+        defaultStr = "yes";
+    }
+
+    return AsteriskSCF::stringToBool(properties->getPropertyWithDefault(propertyName, defaultStr));
+}
+
+/**
  *
  * A generic helper template that can be specialized to help convert different types to std::strings
  * for the StringVectorAsArgs template.
diff --git a/include/AsteriskSCF/Replication/ReplicationContext.h b/include/AsteriskSCF/Replication/ReplicationContext.h
index 1b1950f..c41485e 100644
--- a/include/AsteriskSCF/Replication/ReplicationContext.h
+++ b/include/AsteriskSCF/Replication/ReplicationContext.h
@@ -23,20 +23,18 @@ namespace AsteriskSCF
 namespace Replication
 {
 
-enum ReplicationStateType
+enum ASTERISK_SCF_ICEBOX_EXPORT ReplicationStateType
 {
     ACTIVE_STANDALONE,
     ACTIVE_IN_REPLICA_GROUP,
     STANDBY_IN_REPLICA_GROUP
 };
 
-class ReplicationContextPriv;
-
 /** 
  * This class provides the component with context
  * related to state replication. 
  */
-class ReplicationContext 
+class ASTERISK_SCF_ICEBOX_EXPORT ReplicationContext 
 {
 public:
     ReplicationContext(ReplicationStateType initialState);
@@ -52,6 +50,12 @@ public:
     virtual bool isReplicating();
 
     /**
+     * Returns true if the component is in 
+     * any of the active states. 
+     */
+    bool isActive();
+
+    /**
      * Gets the current state. 
      * @see isReplicating
      */
@@ -64,8 +68,8 @@ public:
     void setState(ReplicationStateType newState);
 
 private:
-    ReplicationStateType mState;
     boost::shared_mutex mLock;
+    ReplicationStateType mState;
 };
 typedef boost::shared_ptr<ReplicationContext> ReplicationContextPtr;
 
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index 9d6e679..92fdbef 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -14,11 +14,12 @@
  * at the top of the source tree.
  */
 
-#include <boost/algorithm/string/predicate.hpp>
+#include <boost/lexical_cast.hpp>
 
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
 
+#include <AsteriskSCF/Helpers/PropertyHelper.h>
 #include <AsteriskSCF/Listener/ListenerManager.h>
 #include <AsteriskSCF/Component/Component.h>
 #include <AsteriskSCF/Logger/IceLogger.h>
@@ -167,7 +168,7 @@ public:
         for (vector<ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); 
              listener != mListeners.end(); ++listener)
         {
-            (*listener)->activated(mReplicaPrx);
+            (*listener)->begin_activated(mReplicaPrx);
         }
 
         return true;
@@ -185,7 +186,7 @@ public:
         for (vector<ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); 
                 listener != mListeners.end(); ++listener)
         {
-            (*listener)->onStandby(mReplicaPrx);
+            (*listener)->begin_onStandby(mReplicaPrx);
         }
     }
 
@@ -230,7 +231,7 @@ Component::Component(const AsteriskSCF::System::Logging::Logger& logger,
 {
 }
 
-std::string Component::getServiceLocatorManagementProperty()
+std::string Component::getServiceLocatorManagementProperty() const
 {
     return mCommunicator->getProperties()->getProperty(ServiceLocatorManagementPropertyName);
 }
@@ -264,20 +265,34 @@ bool Component::isActive()
 
 void Component::activated()
 {
-    mReplicationContext->setState(ACTIVE_IN_REPLICA_GROUP);
-    stopListeningToStateReplicators();
+    try
+    {
+        mReplicationContext->setState(ACTIVE_IN_REPLICA_GROUP);
+        stopListeningToStateReplicators();
 
-    // Notify subclasses
-    onActivated();
+        // Notify subclasses
+        onActivated();
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+    }
 }
 
 void Component::standby()
 {
-    mReplicationContext->setState(STANDBY_IN_REPLICA_GROUP);
-    listenToStateReplicators();
+    try
+    {
+        mReplicationContext->setState(STANDBY_IN_REPLICA_GROUP);
+        listenToStateReplicators();
 
-    // Notify subclasses
-    onStandby();
+        // Notify subclasses
+        onStandby();
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+    }
 }
 
 /**
@@ -286,8 +301,16 @@ void Component::standby()
  */
 void Component::registerPrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
 {
-    mPrimaryServices.push_back(service);
-    service->registerService();
+    try
+    {
+        mPrimaryServices.push_back(service);
+        service->registerService();
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        throw;
+    }
 }
 
 /**
@@ -295,8 +318,16 @@ void Component::registerPrimaryService(const AsteriskSCF::Discovery::LocatorRegi
  */
 void Component::registerBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
 {
-    mBackplaneServices.push_back(service);
-    service->registerService();
+    try
+    {
+        mBackplaneServices.push_back(service);
+        service->registerService();
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        throw;
+    }
 }
 
 /**
@@ -359,17 +390,17 @@ void Component::registerBackplaneServices()
  */
 void Component::unregisterPrimaryServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mPrimaryServices.begin(); 
+        i != mPrimaryServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mPrimaryServices.begin(); i != mPrimaryServices.end(); ++i)
+        try
         {
             (*i)->unregister();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -378,17 +409,17 @@ void Component::unregisterPrimaryServices()
  */
 void Component::unregisterBackplaneServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mBackplaneServices.begin(); 
+        i != mBackplaneServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mBackplaneServices.begin(); i != mBackplaneServices.end(); ++i)
+        try
         {
             (*i)->unregister();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -400,17 +431,17 @@ void Component::unregisterBackplaneServices()
  */
 void Component::suspendPrimaryServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mPrimaryServices.begin(); 
+        i != mPrimaryServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mPrimaryServices.begin(); i != mPrimaryServices.end(); ++i)
+        try
         {
             (*i)->suspend();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -421,17 +452,17 @@ void Component::suspendPrimaryServices()
  */
 void Component::unsuspendPrimaryServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mPrimaryServices.begin(); 
+        i != mPrimaryServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mPrimaryServices.begin(); i != mPrimaryServices.end(); ++i)
+        try
         {
             (*i)->unsuspend();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -442,17 +473,17 @@ void Component::unsuspendPrimaryServices()
  */
 void Component::suspendBackplaneServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mBackplaneServices.begin(); 
+        i != mBackplaneServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mBackplaneServices.begin(); i != mBackplaneServices.end(); ++i)
+        try
         {
             (*i)->suspend();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -463,17 +494,17 @@ void Component::suspendBackplaneServices()
  */
 void Component::unsuspendBackplaneServices()
 {
-    try
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mBackplaneServices.begin(); 
+        i != mBackplaneServices.end(); ++i)
     {
-        vector<LocatorRegistrationWrapperPtr>::iterator i;
-        for(i=mBackplaneServices.begin(); i != mBackplaneServices.end(); ++i)
+        try
         {
             (*i)->unsuspend();
         }
-    }
-    catch(const std::exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -486,10 +517,14 @@ void Component::createAdapters()
     try
     {
         // Create the adapter that our functional services are published on.
-        mServiceAdapter = mCommunicator->createObjectAdapter(mName);
+        // If not specified in the config file at all, using "default" will choose a port 
+        // number for us, avoiding the unconfigured adapter exception. 
+        mServiceAdapter = mCommunicator->createObjectAdapterWithEndpoints(mName,
+            mCommunicator->getProperties()->getPropertyWithDefault(mName + ".Endpoints", "default"));
 
         // Create an adapter for our backplane services. 
-        mBackplaneAdapter = mCommunicator->createObjectAdapter(mName + ".Backplane");
+        mBackplaneAdapter = mCommunicator->createObjectAdapterWithEndpoints(mName + ".Backplane",
+           mCommunicator->getProperties()->getPropertyWithDefault(mName + ".Backplane.Endpoints", "default"));
     }
     catch(const std::exception& e)
     {
@@ -516,6 +551,15 @@ void Component::activateAdapters()
     }
 }
 
+/** 
+ * A factory method. 
+ * Allows subclasses to easily extend the ReplicationContext if needed. 
+ */
+ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
+{
+     return ReplicationContextPtr(new ReplicationContext(state));
+}
+
 /**
  * Create a ReplicationContext for this component. 
  * This operation is a step in initialize()'s Template Method pattern.
@@ -524,10 +568,8 @@ void Component::initReplicationContext()
 {
     try
     {
-        string standaloneProp = mCommunicator->getProperties()->getPropertyWithDefault(
-              mName + ".Standalone", "no");
-        bool standalone = boost::iequals(standaloneProp,"yes") || 
-                          boost::iequals(standaloneProp,"true");
+        bool standalone = AsteriskSCF::getBooleanPropertyWithDefault( 
+            mCommunicator->getProperties(), mName + ".Standalone", false);
 
         ReplicationStateType state(STANDBY_IN_REPLICA_GROUP);
 
@@ -551,8 +593,7 @@ void Component::initReplicationContext()
         }
 
         // Create the replication context.
-        mReplicationContext = ReplicationContextPtr(
-            new ReplicationContext(state));
+        mReplicationContext = createReplicationContext(state);
     }
     catch(const std::exception& e)
     {
@@ -644,13 +685,53 @@ void Component::createBackplaneServices()
  */
 void Component::initServiceLocatorProxies()
 {
-    // Get a proxy to the management interface for the Service Locator manager.
-    mServiceLocatorManagement = 
-        ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorManagementPropertyName));
+    try
+    {
+        // Get a proxy to the management interface for the Service Locator manager.
+        mServiceLocatorManagement = 
+            ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorManagementPropertyName));
+
+        // Get a proxy to the interface for the Service Locator.
+        mServiceLocator = 
+            ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorPropertyName));
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << "Unable to obtain proxies to ServiceLocator. Check configuration. " << e.what();
+        throw;
+    }
+}
+
+void Component::verifyProperties()
+{
+    const int defaultSize(4);
+    string strDefaultSize = boost::lexical_cast<std::string>(defaultSize);
+
+    Ice::Int defaultPoolSize = mCommunicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 0);
+    if (mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + ".ThreadPool.Size", 0) < defaultSize)
+    {
+        if (defaultPoolSize < defaultSize)
+        {
+            mLogger(Info) << "Configured thread pool size for " << mName + " is too small, defaulting to " << strDefaultSize;
+            mCommunicator->getProperties()->setProperty(mName + ".ThreadPool.Size", strDefaultSize);
+        }
+    }
+
+    if (mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + "Internal.ThreadPool.Size", 0) < defaultSize)
+    {
+        if (defaultPoolSize < defaultSize)
+        {
+            mLogger(Info) << "Configured Internal thread pool size for " << mName + " is too small, defaulting to " << strDefaultSize;
+            mCommunicator->getProperties()->setProperty(mName + "Internal.ThreadPool.Size", strDefaultSize);
+        }
+    }
+
+    defaultPoolSize = mCommunicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 0);
+    if (defaultPoolSize < defaultSize)
+    {
+        mLogger(Warning) << "Client thread pool size is too small. It should be set to " << strDefaultSize << " or greater.";
+    }
 
-    // Get a proxy to the interface for the Service Locator.
-    mServiceLocator = 
-        ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorPropertyName));
 }
 
 /**
@@ -662,10 +743,20 @@ void Component::initialize()
 {
     try
     {
+        // Notify subclasses.
         onPreInitialize();
 
+        verifyProperties();
+
         createAdapters();
 
+        // We activate the adapters fairly early in the process 
+        // so that components can get access to the Service Locator
+        // for their specialized behavior. 
+        activateAdapters();
+
+        initServiceLocatorProxies();
+
         initReplicationContext();
 
         initTestContext();
@@ -676,22 +767,18 @@ void Component::initialize()
 
         createBackplaneServices();
 
-        activateAdapters();
+        mInitialized = true;
 
-        initServiceLocatorProxies();
+        findRemoteServices();
 
-        mInitialized = true;
+        // Notify subclasses.
+        onPostInitialize();
     }
     catch(const ::Ice::Exception &e)
     {
         mLogger(Error) << "Problems in " << mName << BOOST_CURRENT_FUNCTION << e.what();
         throw e;
     }
-
-    findRemoteServices();
-
-    // Notify subclasses.
-    onPostInitialize();
 }
 
 /**
@@ -719,19 +806,27 @@ void Component::start(const string& name,
         mBackplaneAdapter->activate();
     }
 
-    // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-    // can be located.
-    registerBackplaneServices();
-    registerPrimaryServices();
-    
-    // Standby mode?
-    if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+    try
     {
-        listenToStateReplicators();
-    } 
+        // Plug into the Asterisk SCF discovery system so that the interfaces we provide
+        // can be located.
+        registerBackplaneServices();
+        registerPrimaryServices();
+    
+        // Standby mode?
+        if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+        {
+            listenToStateReplicators();
+        } 
 
-    // Notify subclasses
-    onStart();
+        // Notify subclasses
+        onStart();
+    }
+    catch(const Ice::Exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        throw;
+    }
 
     mRunning = true;
     mLogger(Info) << "Started";
diff --git a/src/Replication/ReplicationContext.cpp b/src/Replication/ReplicationContext.cpp
index 278fdf4..574e730 100644
--- a/src/Replication/ReplicationContext.cpp
+++ b/src/Replication/ReplicationContext.cpp
@@ -27,6 +27,13 @@ ReplicationContext::ReplicationContext(ReplicationStateType initialState)
 {
 }
 
+bool ReplicationContext::isActive()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mLock);
+
+    return (mState != STANDBY_IN_REPLICA_GROUP);
+}
+
 bool ReplicationContext::isReplicating()
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
diff --git a/test/LocatorRegistration/LocatorRegistrationTest.cpp b/test/LocatorRegistration/LocatorRegistrationTest.cpp
index c6a84ce..5ce3370 100644
--- a/test/LocatorRegistration/LocatorRegistrationTest.cpp
+++ b/test/LocatorRegistration/LocatorRegistrationTest.cpp
@@ -464,7 +464,7 @@ public:
                 AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx::uncheckedCast(mAdapter->addWithUUID(new MockLocatorManager(mDB)));
 
             mCommunicator->getProperties()->setProperty("LocatorService.Proxy", mLocator->ice_toString());
-            mCommunicator->getProperties()->setProperty("LocatorServiceManager.Proxy", mManager->ice_toString());
+            mCommunicator->getProperties()->setProperty("LocatorServiceManagement.Proxy", mManager->ice_toString());
             mAdapter->activate();
             //
             // Looks a little weird maybe, but WHY can't the manager be added to the locator. It makes a whole whackload of sense really.
@@ -668,7 +668,7 @@ public:
         LocatorRegistrationWrapperPtr registrationWrapper = 
             new LocatorRegistrationWrapper(
                mCommunicator,
-               mCommunicator->getProperties()->getProperty("LocatorServiceManager.Proxy"),
+               mCommunicator->getProperties()->getProperty("LocatorServiceManagement.Proxy"),
                mClientEnvironment.proxy(),
                id,
                params);
diff --git a/test/PropertyHelper/PropertyHelperTest.cpp b/test/PropertyHelper/PropertyHelperTest.cpp
index fa1e735..dd96286 100644
--- a/test/PropertyHelper/PropertyHelperTest.cpp
+++ b/test/PropertyHelper/PropertyHelperTest.cpp
@@ -86,6 +86,30 @@ static void runPropertyHelperTest()
     BOOST_CHECK(result == "1");
     result = p->getProperty("test.property");
     BOOST_CHECK(result == "1");
+
+    BOOST_CHECK(stringToBool("True"));
+    BOOST_CHECK(!stringToBool("False"));
+
+    BOOST_CHECK(stringToBool("TRUE"));
+    BOOST_CHECK(!stringToBool("FALSE"));
+
+    BOOST_CHECK(stringToBool("Yes"));
+    BOOST_CHECK(!stringToBool("No"));
+
+    BOOST_CHECK(stringToBool("yes"));
+    BOOST_CHECK(!stringToBool("no"));
+
+    BOOST_CHECK(stringToBool("1"));
+    BOOST_CHECK(!stringToBool("0"));
+
+    bool bval = getBooleanPropertyWithDefault(p, "test.boolprop", false);
+    BOOST_CHECK(!bval); 
+
+    result = propGetSet(p, "test.boolprop", "True");
+    BOOST_CHECK(result == "True");
+
+    bval = getBooleanPropertyWithDefault(p, "test.boolprop", false);
+    BOOST_CHECK(bval); 
 }
 using namespace boost::unit_test;
 

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list