[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
Tue Jul 19 09:58:17 CDT 2011


branch "basecomponent" has been updated
       via  d424295ebb347315faab4253bd2498039963840d (commit)
      from  ef03e42a73fdb41fa8d383a8e73c1a453b0f676d (commit)

Summary of changes:
 include/AsteriskSCF/Component/Component.h  |   45 ++++------
 include/AsteriskSCF/Discovery/SmartProxy.h |    8 ++-
 src/Component/Component.cpp                |  123 ++++++++++++++++------------
 test/Component/MockComponent.cpp           |    6 +-
 4 files changed, 99 insertions(+), 83 deletions(-)


- Log -----------------------------------------------------------------
commit d424295ebb347315faab4253bd2498039963840d
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jul 19 09:57:43 2011 -0500

    More fixes from testing.

diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index 33f11ee..9da9c57 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -184,29 +184,23 @@ protected:
     virtual void registerWithRemoteServices() {}
 
     /**
-     * Deregister this component's proxies from service
+     * Unregister this component's proxies from service
      * (other than the ServiceLocator).
      */
-    virtual void deregisterFromRemoteServices() {}
+    virtual void unregisterFromRemoteServices() {}
 
     /////////////////////////////////////////////////////////////////////
     // Service locator operations
 
     /**
-     * Helper that caches the service references for the primary adapter, and invokes 
-     * the register method of the registration wrapper if the component is active. 
-     * @return true if the service is registered. Always returns false if the component
-     * is in standby mode. 
+     * Helper that caches the service references for the primary adapter.
      */
-    bool managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+    void managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
 
     /**
-     * Helper that caches the service references for the backplane adapter, and invokes 
-     * the register method of the registration wrapper if the component is active. 
-     * @return true if the service is registered. Always returns false if the component
-     * is in standby mode. 
+     * Helper that caches the service references for the backplane adapter. 
      */
-    bool manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+    void manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
     
     /** 
      * Helper that wraps a service for registration by making some assumptions that
@@ -219,27 +213,24 @@ protected:
                                    const std::string& id = "");
 
     /**
-     *  The derived component must override this operation, and is expected
-     *  to register all services associated with the primary adapter. 
-     *  This operation is called after the initialize() operation, so the adapters
-     *  exist. 
-     *  If the derived component calls registerPrimaryService(LocatorRegistrationWrapperPtr& service)
-     *  for each component, there should be no need to override unregisterPrimaryServices(), 
-     *  suspendPrimaryServices(), or unsuspendPrimaryServices(). 
+     * The derived component is expected to wrap each 
+     * primary adapter service that should be 
+     * registered with the Service Locator. Refer to
+     * documentation. 
      */
-    virtual void registerPrimaryServices() = 0;
+    virtual void preparePrimaryServicesForDiscovery() = 0;
+    void registerPrimaryServices();
     void unregisterPrimaryServices();
     void suspendPrimaryServices();
     void unsuspendPrimaryServices();
 
     /**
-     *  The derived component should override this operation only if it wishes to create
-     *  additional backplane services. 
-     *  If the derived component calls registerBackplaneService(LocatorRegistrationWrapperPtr& service)
-     *  for each component, there should be no need to override unregisterBackplaneServices(), 
-     *  suspendBackplaneServices(), or unsuspendBackplaneServices(). 
+     * The derived component should override this operation only if it wishes
+     * register its own backplane services. If this method is overridden, 
+     * this class's implmentation should be called from the override. 
      */
-    virtual void registerBackplaneServices();
+    virtual void prepareBackplaneServicesForDiscovery();
+    void registerBackplaneServices();
     void unregisterBackplaneServices();
     void suspendBackplaneServices();
     void unsuspendBackplaneServices();
diff --git a/include/AsteriskSCF/Discovery/SmartProxy.h b/include/AsteriskSCF/Discovery/SmartProxy.h
index eda54fb..b6dc87b 100644
--- a/include/AsteriskSCF/Discovery/SmartProxy.h
+++ b/include/AsteriskSCF/Discovery/SmartProxy.h
@@ -82,11 +82,13 @@ public:
     }
 
     /** 
-     * Attempts to offer a oneway proxy. If oneway isn't supported, will return the
+     * Attempts to offer a oneway proxy. If oneway isn't supported due to the proxy not 
+     * supporting a stream-oriented protocol (based on configuration), this operation will return the
      * two-way proxy without throwing the typical NoEndpointException that ice_oneway
      * might have thrown. If the caller needs to know, the supportsOneWay() is available. 
      * Note that TwoWayOnly exception can still be generated if
-     * calling an operation that needs to send info back to client. 
+     * calling an operation that needs to send info back to client (via return values, out
+     * parameters or exceptions). 
      * @see supportsOneWay
      */
     P tryOneWay()
@@ -242,9 +244,11 @@ private:
         IceUtil::Mutex::Lock rhsLock(rhs.mMutex);
 
         mProxy = rhs.mProxy;
+        mOneWayProxy = rhs.mOneWayProxy;
         mServiceLocator = rhs.mServiceLocator;
         mLocatorParams = rhs.mLocatorParams;
         mLogger = rhs.mLogger;
+        mSupportsOneWay = rhs.mOneWayProxy;
     }
 
     // we want to lock even const instances, so mMutex must be mutable
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index 17397e5..d26e389 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -268,6 +268,7 @@ void Component::activated()
     {
         mReplicationContext->setState(ACTIVE_IN_REPLICA_GROUP);
         stopListeningToStateReplicators();
+        registerPrimaryServices();
         registerWithRemoteServices();
 
         // Notify subclasses
@@ -283,9 +284,10 @@ void Component::standby()
 {
     try
     {
+        unregisterPrimaryServices();
+        unregisterFromRemoteServices();
         mReplicationContext->setState(STANDBY_IN_REPLICA_GROUP);
         listenToStateReplicators();
-        deregisterFromRemoteServices();
 
         // Notify subclasses
         onStandby();
@@ -320,57 +322,28 @@ LocatorRegistrationWrapperPtr Component::wrapServiceForRegistration(const Ice::O
 }
 
 /**
- * In the override of registerPrimaryServices(), this operation should
+ * In the required override of registerPrimaryServices(), this operation should
  * be called for each primary interface registered with the service locator.
  */
-bool Component::managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
+void Component::managePrimaryService(const LocatorRegistrationWrapperPtr& service)
 {
-    bool result(false);
-    try
-    {
-        mPrimaryServices.push_back(service);
-
-        if (mReplicationContext->isActive())
-        {
-            result = service->registerService();
-        }
-    }
-    catch(const Ice::Exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
-        throw;
-    }
-
-    return result;
+    mPrimaryServices.push_back(service);
 }
 
 /**
- * This operation should be called for each backplane interface registered with the service locator.
+ * This operation should be called for each backplane interface that's to be 
+ * registered with the service locator.
  */
-bool Component::manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
+void Component::manageBackplaneService(const LocatorRegistrationWrapperPtr& service)
 {
-    bool result(false);
-    try
-    {
-        mBackplaneServices.push_back(service);
-
-        if (mReplicationContext->isActive())
-        {
-            result = service->registerService();
-        }
-    }
-    catch(const Ice::Exception& e)
-    {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
-        throw;
-    }
-    return result;
+    mBackplaneServices.push_back(service);
 }
 
 /**
- * Register this component's backplane interfaces with the Service Locator.
+ * Prepare this component's backplane services for registration 
+ * with the Service Locator.
  */
-void Component::registerBackplaneServices()
+void Component::prepareBackplaneServicesForDiscovery()
 {
     try
     {
@@ -407,6 +380,25 @@ void Component::registerBackplaneServices()
 }
 
 /**
+ * Register this component's primary service interfaces with the Service Locator.
+ */
+void Component::registerPrimaryServices()
+{
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mPrimaryServices.begin(); 
+        i != mPrimaryServices.end(); ++i)
+    {
+        try
+        {
+            (*i)->registerService();
+        }
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
+    }
+}
+
+/**
  * Unregister this component's primary service interfaces from the Service Locator.
  */
 void Component::unregisterPrimaryServices()
@@ -422,6 +414,29 @@ void Component::unregisterPrimaryServices()
         {
             mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
         }
+        catch(...)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << "Some unknown exception.";
+        }
+    }
+}
+
+/**
+ * Register this component's backplane interfaces from the Service Locator.
+ */
+void Component::registerBackplaneServices()
+{
+    for(vector<LocatorRegistrationWrapperPtr>::iterator i=mBackplaneServices.begin(); 
+        i != mBackplaneServices.end(); ++i)
+    {
+        try
+        {
+            (*i)->registerService();
+        }
+        catch(const std::exception& e)
+        {
+            mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        }
     }
 }
 
@@ -741,12 +756,12 @@ void Component::verifyProperties()
         }
     }
 
-    if (mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + "Internal.ThreadPool.Size", 0) < defaultSize)
+    if (mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + ".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);
+            mCommunicator->getProperties()->setProperty(mName + ".ThreadPool.Size", strDefaultSize);
         }
     }
 
@@ -781,10 +796,10 @@ void Component::initialize()
 
         initServiceLocatorProxies();
 
-        initReplicationContext();
-
         initTestContext();
 
+        initReplicationContext();
+
         configureLogger();
 
         createPrimaryServices();
@@ -838,16 +853,22 @@ void Component::start(const string& name,
             registerWithRemoteServices();
         }
 
-        // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-        // can be located.
-        registerBackplaneServices();
-        registerPrimaryServices();
+        // Prepare our services for discovery via the Service Locator.
+        prepareBackplaneServicesForDiscovery();
+        preparePrimaryServicesForDiscovery();
     
+        // We always register backplane services with Service Locator.
+        registerBackplaneServices();
+
         // Standby mode?
-        if (mReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+        if (mReplicationContext->isActive() == true)
+        {
+            registerPrimaryServices();
+        }
+        else
         {
             listenToStateReplicators();
-        } 
+        }
 
         // Notify subclasses
         onStart();
@@ -939,7 +960,7 @@ void Component::suspendService(bool shuttingDown)
         {
              try
              {
-                 deregisterFromRemoteServices();
+                 unregisterFromRemoteServices();
              }
              catch(const std::exception& e)
              {
diff --git a/test/Component/MockComponent.cpp b/test/Component/MockComponent.cpp
index f60b2a8..8d0915c 100644
--- a/test/Component/MockComponent.cpp
+++ b/test/Component/MockComponent.cpp
@@ -57,7 +57,7 @@ protected:
     virtual void listenToStateReplicators();
     virtual void createPrimaryServices();
     virtual void findRemoteServices();
-    virtual void registerPrimaryServices();
+    virtual void preparePrimaryServicesForDiscovery();
 
     ///////////////////////////
     // Optional notifications
@@ -128,10 +128,10 @@ void MockComponent::createPrimaryServices()
 }
 
 /**
- * Register this component's services with the 
+ * Prepare this component's services for the 
  * service locator. 
  */
-void MockComponent::registerPrimaryServices()
+void MockComponent::preparePrimaryServicesForDiscovery()
 {
     try
     {

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


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



More information about the asterisk-scf-commits mailing list