[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Mar 14 09:25:22 CDT 2012


branch "retry_deux" has been updated
       via  62e32bc965e3140af78987d00dccbc54e08e8903 (commit)
       via  a888470a7bfb92f57c5cc6e26cb9d0bd138502ba (commit)
       via  6f780a026de7470a1b4e69d81b1b5aaa03a2a320 (commit)
       via  27ee5eaa46137735bde319b02a115bd2bc093c4e (commit)
       via  0260c56584f42d4cd0b6736693672a2c1fdf4659 (commit)
       via  047cb337070751cbbc6303d2c50f3ca6e693ce30 (commit)
       via  7f7102094df3e6156379bf254e8c9ab868f6c90b (commit)
       via  e94c750e182b375000357a2c7c92d878ea51ae32 (commit)
       via  9a5d98ce68759fbda3ead29f13fdb877fda846de (commit)
       via  40fb738d92e4c70d2ecea2f85694008a86a69211 (commit)
       via  eca922fd6e1c4f16b3a43fba0a89464dc6bdeaa9 (commit)
       via  b81af86a71d756acf7f83eb45dbc7025cc732ee2 (commit)
       via  a2efb4aca28b4060839e4553356118c6bb32b036 (commit)
      from  0485490749d2b3b9b1c9b13cf0be64ea98a40e75 (commit)

Summary of changes:
 include/AsteriskSCF/Component/Component.h          |   10 +-
 .../Component/ComponentStateReplicator.h           |  129 +++++++++++
 .../Discovery/LocatorRegistrationWrapper.h         |    5 +
 include/AsteriskSCF/Discovery/SmartProxy.h         |   10 +
 include/AsteriskSCF/Listener/ListenerManager.h     |    2 +-
 .../AsteriskSCF/Operations/OperationContextCache.h |    6 +-
 include/AsteriskSCF/PJLIB/ThreadHook.h             |    6 +-
 include/AsteriskSCF/WorkQueue/Dispatched.h         |    6 +-
 src/Component/CMakeLists.txt                       |    1 +
 src/Component/Component.cpp                        |    2 +
 src/Component/ComponentStateReplicator.cpp         |  223 ++++++++++++++++++++
 test/Component/component-base-test.conf            |    2 +-
 test/WorkQueue/TestSuspendableWorkQueue.cpp        |    2 +-
 test/WorkQueue/TestWorkQueue.cpp                   |    2 +-
 14 files changed, 393 insertions(+), 13 deletions(-)
 create mode 100644 include/AsteriskSCF/Component/ComponentStateReplicator.h
 create mode 100644 src/Component/ComponentStateReplicator.cpp


- Log -----------------------------------------------------------------
commit 62e32bc965e3140af78987d00dccbc54e08e8903
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Mar 14 11:54:58 2012 -0230

    A silly fix for a typo in a comment.

diff --git a/include/AsteriskSCF/Operations/OperationContextCache.h b/include/AsteriskSCF/Operations/OperationContextCache.h
index 90611e7..e1b5388 100644
--- a/include/AsteriskSCF/Operations/OperationContextCache.h
+++ b/include/AsteriskSCF/Operations/OperationContextCache.h
@@ -73,7 +73,7 @@ public:
     ~OperationContextCache();
 
     /**
-     * Caches the specified context if it isnt' already in the cache. 
+     * Caches the specified context if it isn't already in the cache. 
      *
      * @param operationContext The context to add to the cache. 
      * @return true The context was added, which means it wasn't already in the cache.
@@ -84,7 +84,7 @@ public:
     bool addOperationContext(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
 
     /**
-     * Caches the specified context if it isnt' already in the cache, and associate a cookie with it. 
+     * Caches the specified context if it isn't already in the cache, and associate a cookie with it. 
      *
      * @param operationContext The context to add to the cache. 
      * @param inCookie A cookie object to associate with this entry in the cache. 
@@ -106,7 +106,7 @@ public:
     bool contains(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
 
     /**
-     * This will remove an OperationContext from the cache, if one exists with the given id. 
+     * This will remove an OperationContext from the cache if one exists with the given id. 
      * Removal is typically done automatically within the cache based on an internal timer. 
      * This operation exists to support clients that wish to force an immediate removal of a 
      * context themselves. 

commit a888470a7bfb92f57c5cc6e26cb9d0bd138502ba
Merge: 6f780a0 0485490
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Mar 14 11:51:36 2012 -0230

    Merge branch 'retry_deux' of ssh://git.asterisk.org/asterisk-scf/integration/ice-util-cpp into retry_deux


commit 6f780a026de7470a1b4e69d81b1b5aaa03a2a320
Merge: 1907e2b 27ee5ea
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Mar 6 14:17:43 2012 -0330

    Merge remote-tracking branch 'origin/master' into retry_deux

diff --cc include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index 5cef1c1,0d3b233..3791f3e
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@@ -133,7 -127,13 +133,12 @@@ public
          return mServiceManagement;
      }
  
+     Ice::Identity getServiceIdentity()
+     {
+         return mService->ice_getIdentity();
+     }
+ 
  private:
 -
      //
      // This template doesn't use boost locking simply because it already has a physical dependency
      // to Ice runtime, so avoiding adding a second seemed reasonable.

commit 27ee5eaa46137735bde319b02a115bd2bc093c4e
Author: David M. Lee <dlee at digium.com>
Date:   Wed Feb 15 15:07:20 2012 -0600

    Fixed a few uninitialized variable errors

diff --git a/test/WorkQueue/TestSuspendableWorkQueue.cpp b/test/WorkQueue/TestSuspendableWorkQueue.cpp
index f469cfc..7e6d6a0 100644
--- a/test/WorkQueue/TestSuspendableWorkQueue.cpp
+++ b/test/WorkQueue/TestSuspendableWorkQueue.cpp
@@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(shutdownException)
 
     queue->shutdown();
 
-    bool excepted;
+    bool excepted = false;
     try
     {
         queue->getSize();
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index b7d77ef..99dd979 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(shutdownException)
 
     queue->shutdown();
 
-    bool excepted;
+    bool excepted = false;
     try
     {
         queue->getSize();

commit 0260c56584f42d4cd0b6736693672a2c1fdf4659
Author: David M. Lee <dlee at digium.com>
Date:   Wed Feb 15 15:06:26 2012 -0600

    Fixed uninitialized reference

diff --git a/include/AsteriskSCF/Listener/ListenerManager.h b/include/AsteriskSCF/Listener/ListenerManager.h
index 30eaa78..52d7976 100644
--- a/include/AsteriskSCF/Listener/ListenerManager.h
+++ b/include/AsteriskSCF/Listener/ListenerManager.h
@@ -163,7 +163,7 @@ public:
 
     bool removeListener(const T& listener)
     {
-        T& proxyToUnsubscribe;
+        T proxyToUnsubscribe;
         {
             boost::unique_lock<boost::shared_mutex> lock(mLock);
             typename std::vector<T>::iterator i = std::find(mListeners.begin(), mListeners.end(), listener);

commit 047cb337070751cbbc6303d2c50f3ca6e693ce30
Author: David M. Lee <dlee at digium.com>
Date:   Wed Feb 15 15:03:26 2012 -0600

    Fixed what() overrides for thread hook exceptions
    
    The cv spec must match for function overrides.

diff --git a/include/AsteriskSCF/PJLIB/ThreadHook.h b/include/AsteriskSCF/PJLIB/ThreadHook.h
index 1f35221..b46e0a9 100644
--- a/include/AsteriskSCF/PJLIB/ThreadHook.h
+++ b/include/AsteriskSCF/PJLIB/ThreadHook.h
@@ -40,7 +40,7 @@ public:
     {
     }
 
-    virtual const char* what() throw()
+    virtual const char* what() const throw()
     {
         return "pj_init() returned failure.";
     }
@@ -55,7 +55,7 @@ public:
     {
     }
 
-    virtual const char* what() throw()
+    virtual const char* what() const throw()
     {
         return "pjlib_util_init() returned failure.";
     }
@@ -70,7 +70,7 @@ public:
     {
     }
 
-    virtual const char* what() throw()
+    virtual const char* what() const throw()
     {
         return "pj_thread_register() returned failure.";
     }

commit 7f7102094df3e6156379bf254e8c9ab868f6c90b
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Feb 10 11:36:42 2012 -0600

    Fixes for configuration registration with ServiceLocator.

diff --git a/include/AsteriskSCF/Component/ComponentStateReplicator.h b/include/AsteriskSCF/Component/ComponentStateReplicator.h
index ffeac17..7ede98c 100644
--- a/include/AsteriskSCF/Component/ComponentStateReplicator.h
+++ b/include/AsteriskSCF/Component/ComponentStateReplicator.h
@@ -34,7 +34,8 @@ class ASTSCF_DLL_EXPORT ComponentStateReplicator : public AsteriskSCF::Component
 public:
     ComponentStateReplicator(const AsteriskSCF::System::Logging::Logger& logger,
               const std::string& componentDiscoveryCategory,
-              bool replicatesConfiguration);
+              bool replicatesConfiguration,
+              const std::string& configurationDiscoveryCategory);
 
 protected:
    
@@ -119,7 +120,9 @@ private:
     AsteriskSCF::System::Configuration::V1::ConfigurationReplicatorPtr mConfigurationReplicator;
     AsteriskSCF::CollocatedIceStorm::CollocatedIceStormPtr mIceStorm;
     Ice::ObjectPrx mConfigurationPublisher;
+    AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx mConfigurationManagement;
     bool mReplicatesConfiguration;
+    std::string mConfigurationDiscoveryCategory;
 };
 
 } // end namespace Component
diff --git a/src/Component/ComponentStateReplicator.cpp b/src/Component/ComponentStateReplicator.cpp
index c8e70f8..2b8686e 100644
--- a/src/Component/ComponentStateReplicator.cpp
+++ b/src/Component/ComponentStateReplicator.cpp
@@ -78,11 +78,14 @@ void ConfigurationReplicatorImpl::registerConfigurationService(const AsteriskSCF
         }
     }
 }
-ComponentStateReplicator::ComponentStateReplicator(const AsteriskSCF::System::Logging::Logger& logger,
-                     const string& componentDiscoveryCategory,
-                     bool replicatesConfiguration) :
-      Component(logger, componentDiscoveryCategory),
-      mReplicatesConfiguration(replicatesConfiguration)
+ComponentStateReplicator::ComponentStateReplicator(
+      const AsteriskSCF::System::Logging::Logger& logger,
+      const string& componentDiscoveryCategory,
+      bool replicatesConfiguration,
+      const string& configurationDiscoveryCategory) :
+          Component(logger, componentDiscoveryCategory),
+          mReplicatesConfiguration(replicatesConfiguration),
+          mConfigurationDiscoveryCategory(configurationDiscoveryCategory)
 {
 }
 
@@ -189,6 +192,17 @@ void ComponentStateReplicator::onPreServiceCreation()
     if (mReplicatesConfiguration)
     {
         createConfigurationReplicationService();
+
+        // Publish the configuration service IceStorm topic so everybody gets configuration
+        mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
+            getServiceLocatorManagement()->addService(mConfigurationPublisher, ""));
+
+        ServiceLocatorParamsPtr configurationParams = new ServiceLocatorParams();
+        configurationParams->category = mConfigurationDiscoveryCategory;
+        configurationParams->service = getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".ServiceName", 
+            "default");
+        configurationParams->id = getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".Name", "");
+        mConfigurationManagement->addLocatorParams(configurationParams, "");
     }
 }
 

commit e94c750e182b375000357a2c7c92d878ea51ae32
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Feb 8 11:39:57 2012 -0330

    Merged branch jira-astscf-397-sipuseragent.
    
    -   Adding some accessors to the smart proxy members, mostly that a new one
        might be created with only slightly modified values.

diff --git a/include/AsteriskSCF/Discovery/SmartProxy.h b/include/AsteriskSCF/Discovery/SmartProxy.h
index 6ab22a7..c332988 100644
--- a/include/AsteriskSCF/Discovery/SmartProxy.h
+++ b/include/AsteriskSCF/Discovery/SmartProxy.h
@@ -202,6 +202,16 @@ public:
         return mProxy;
     }
 
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx getLocator() const
+    {
+        return mServiceLocator;
+    }
+
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr getLocationParameters() const
+    {
+        return AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr::dynamicCast(mLocatorParams->ice_clone());
+    }
+
 private:
 
     /**

commit 9a5d98ce68759fbda3ead29f13fdb877fda846de
Merge: 40fb738 eca922f
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Feb 6 15:08:14 2012 -0600

    Merge branch 'master' of git.asterisk.org:asterisk-scf/release/ice-util-cpp


commit 40fb738d92e4c70d2ecea2f85694008a86a69211
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Feb 6 15:07:25 2012 -0600

    Corrected reference to ServiceDiscovery component in unit test config file.

diff --git a/test/Component/component-base-test.conf b/test/Component/component-base-test.conf
index f958bad..9ec515d 100644
--- a/test/Component/component-base-test.conf
+++ b/test/Component/component-base-test.conf
@@ -8,7 +8,7 @@ Ice.Override.Timeout=2000
 
 IceBox.InheritProperties=1 
 
-IceBox.Service.ServiceDiscovery=service_locator:create
+IceBox.Service.ServiceDiscovery=ServiceLocator:create
 IceBox.Service.MockComponent=component-base-test-mockcomponent:create
 IceBox.Service.ComponentTest=component-base-test:create
 

commit eca922fd6e1c4f16b3a43fba0a89464dc6bdeaa9
Author: David M. Lee <dlee at digium.com>
Date:   Mon Feb 6 10:48:00 2012 -0600

    Fixed for boost-1.48

diff --git a/include/AsteriskSCF/WorkQueue/Dispatched.h b/include/AsteriskSCF/WorkQueue/Dispatched.h
index b69bcf8..7cd2d40 100644
--- a/include/AsteriskSCF/WorkQueue/Dispatched.h
+++ b/include/AsteriskSCF/WorkQueue/Dispatched.h
@@ -17,6 +17,8 @@
 
 #include <boost/interprocess/detail/atomic.hpp>
 
+#include <AsteriskSCF/Boost/FixIpcDetail.h>
+
 namespace AsteriskSCF
 {
 namespace WorkQueue
@@ -27,11 +29,11 @@ class ASTSCF_DLL_EXPORT Dispatched
 public:
     Dispatched() : mDestroyed(0) { }
 
-    void setDestroyed() { boost::interprocess::detail::atomic_inc32(&mDestroyed); }
+    void setDestroyed() { boost::interprocess::ipcdetail::atomic_inc32(&mDestroyed); }
 
     bool isDestroyed()
     {
-        if (boost::interprocess::detail::atomic_read32(&mDestroyed) > 0)
+        if (boost::interprocess::ipcdetail::atomic_read32(&mDestroyed) > 0)
         {
             return true;
         }

commit b81af86a71d756acf7f83eb45dbc7025cc732ee2
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Feb 6 11:33:39 2012 -0600

    Correction for filename case change.

diff --git a/include/AsteriskSCF/Component/ComponentStateReplicator.h b/include/AsteriskSCF/Component/ComponentStateReplicator.h
index 6936a61..ffeac17 100644
--- a/include/AsteriskSCF/Component/ComponentStateReplicator.h
+++ b/include/AsteriskSCF/Component/ComponentStateReplicator.h
@@ -21,7 +21,7 @@
 #include <boost/shared_ptr.hpp>
 
 #include <AsteriskSCF/Component/Component.h>
-#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Logger.h>
 #include <AsteriskSCF/System/Component/ConfigurationIf.h>
 #include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
 

commit a2efb4aca28b4060839e4553356118c6bb32b036
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Feb 3 17:49:05 2012 -0600

    Adding a base ComponentStateReplicator for state replicators.

diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index e29ded6..ff0f3a1 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -63,6 +63,7 @@ protected:
     // Notification for some of 
     // the component events. 
     virtual void onPreInitialize() {}
+    virtual void onPreServiceCreation() {}
     virtual void onPostInitialize() {}
     virtual void onSuspend() {}
     virtual void onResume() {}
@@ -203,7 +204,7 @@ protected:
     /**
      * Helper that caches the service references for the primary adapter.
      */
-    void managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+    virtual void managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
 
     /**
      * Helper that caches the service references for the backplane adapter. 
@@ -253,6 +254,7 @@ protected:
     /////////////////////////////////////////////////////////////////////
     // Accessors to state. 
     const AsteriskSCF::Replication::ReplicationContextPtr& getReplicationContext() const {return mReplicationContext;}
+    void setReplicationContext(const AsteriskSCF::Replication::ReplicationContextPtr& context) {mReplicationContext = context;}
     const AsteriskSCF::Component::TestContextPtr& getTestContext() const {return mTestContext;}
     const std::string& getName() const {return mName;}
     const std::string& getServiceName() const {return mServiceName;}
@@ -274,7 +276,13 @@ protected:
     AsteriskSCF::System::Logging::Logger mLogger;
 
 private:
+
+    /** 
+     * We just aren't going to let anyone else do this. There
+     * are hooks and overrides aplenty. 
+     */
     void initialize();
+
     void suspendService(bool shuttingDown);
 
     /////////////////////////////////////////////////////////////////////
diff --git a/include/AsteriskSCF/Component/ComponentStateReplicator.h b/include/AsteriskSCF/Component/ComponentStateReplicator.h
new file mode 100644
index 0000000..6936a61
--- /dev/null
+++ b/include/AsteriskSCF/Component/ComponentStateReplicator.h
@@ -0,0 +1,126 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 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 <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
+
+namespace AsteriskSCF
+{
+namespace Component
+{
+class ASTSCF_DLL_EXPORT ComponentStateReplicator : public AsteriskSCF::Component::Component
+{
+public:
+    ComponentStateReplicator(const AsteriskSCF::System::Logging::Logger& logger,
+              const std::string& componentDiscoveryCategory,
+              bool replicatesConfiguration);
+
+protected:
+   
+    //////////////////////////////////////////////
+    // Overrides of Component class operations. 
+
+    /** 
+     * Unregister as a listener to our state replicator. 
+     * A component in active mode doesn't neeed to listen to
+     * state replication data. 
+     * Note: This currently defaults to no-op, since our replicators
+     * don't yet replicate themeselve. 
+     */
+    virtual void stopListeningToStateReplicators() {}
+
+    /** 
+     * Register as a listener to our state replicator. 
+     * A component in standby mode will do this to monitor state changes
+     * being sent from an active component. 
+     * Note: This currently defaults to no-op, since our replicators
+     * don't yet replicate themeselve. 
+     */
+    virtual void listenToStateReplicators() {}
+
+    /**
+     * Note: This currently defaults to no-op, since our replicators
+     * don't yet replicate themeselve. 
+     */
+    virtual void createReplicationStateListeners() {}
+
+    /**
+     * Creates a replication context using the factory method
+     * createReplicationContext(). Override the factory method if 
+     * you want to create a custom replication context. 
+     * Note: State replicators don't actually replicate themselves currently,
+     * but this is behavior from the base Component class. 
+     */
+    virtual void initReplicationContext();
+
+    /**
+     * By default we're assuming State Replicators don't need to locate
+     * remote services. But override this if you need to. 
+     */
+    virtual void findRemoteServices() {}
+
+    /**
+     * We've specialized this from the base Component class. 
+     */
+    virtual void managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+
+    ////////////////////////////////////////////////////////
+    // These are required overrides. 
+
+    /**
+     * Create all services to be associated with the primary service adapter. 
+     * This is where you create the servants for your replication interfaces. 
+     */
+    virtual void createPrimaryServices() = 0;
+
+    /**
+     * The derived component is expected to wrap each 
+     * primary adapter service that should be 
+     * registered with the Service Locator. 
+     */
+    virtual void preparePrimaryServicesForDiscovery() = 0;
+
+    /**
+     * Some notifications from the Component we rely on.
+     */
+    void onStop();
+
+    void onPreServiceCreation();
+
+    /////////////////////////////////////////////////////////
+    // Implementation
+    virtual void createConfigurationReplicationService();
+
+private:
+    /////////////////////////////////////////////////////////////////////
+    // State data
+
+    AsteriskSCF::System::Configuration::V1::ConfigurationReplicatorPtr mConfigurationReplicator;
+    AsteriskSCF::CollocatedIceStorm::CollocatedIceStormPtr mIceStorm;
+    Ice::ObjectPrx mConfigurationPublisher;
+    bool mReplicatesConfiguration;
+};
+
+} // end namespace Component
+} // end namespace AsteriskSCF
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index e6d410f..0d3b233 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -127,6 +127,11 @@ public:
         return mServiceManagement;
     }
 
+    Ice::Identity getServiceIdentity()
+    {
+        return mService->ice_getIdentity();
+    }
+
 private:
 
     //
diff --git a/src/Component/CMakeLists.txt b/src/Component/CMakeLists.txt
index 7ef8530..f618fb1 100644
--- a/src/Component/CMakeLists.txt
+++ b/src/Component/CMakeLists.txt
@@ -1,2 +1,3 @@
 astscf_component_add_files(ASTSCFIceUtilCpp Component.cpp)
+astscf_component_add_files(ASTSCFIceUtilCpp ComponentStateReplicator.cpp)
 astscf_component_add_files(ASTSCFIceUtilCpp TestContext.cpp)
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index 70866e1..5511ca0 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -874,6 +874,8 @@ void Component::initialize()
 
         configureLogger();
 
+        onPreServiceCreation();
+
         createPrimaryServices();
 
         createBackplaneServices();
diff --git a/src/Component/ComponentStateReplicator.cpp b/src/Component/ComponentStateReplicator.cpp
new file mode 100644
index 0000000..c8e70f8
--- /dev/null
+++ b/src/Component/ComponentStateReplicator.cpp
@@ -0,0 +1,209 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <boost/lexical_cast.hpp>
+
+#include <Ice/Ice.h>
+#include <IceUtil/Thread.h>
+#include <IceBox/IceBox.h>
+
+#include <AsteriskSCF/Helpers/PropertyHelper.h>
+#include <AsteriskSCF/Component/ComponentStateReplicator.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
+#include <AsteriskSCF/Discovery/LocatorRegistrationWrapper.h>
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
+
+using namespace std;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::Discovery;
+using namespace AsteriskSCF::Replication;
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::CollocatedIceStorm;
+
+namespace AsteriskSCF
+{
+namespace Component
+{
+static const string ServiceLocatorManagementPropertyName("LocatorServiceManagement.Proxy");
+static const string ServiceLocatorPropertyName("LocatorService.Proxy");
+	
+static const string ComponentServiceProxyId("ComponentService");
+static const string ReplicaProxyId("Replica");
+
+/**
+* Servant that provides configuration data replication. 
+*/
+class ConfigurationReplicatorImpl : public ConfigurationReplicator
+{
+public:
+    ConfigurationReplicatorImpl(const IceStorm::TopicPrx& topic) : mConfigurationReplicationTopic(topic) { };
+    void registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx&, const Ice::Current&);
+private:
+    IceStorm::TopicPrx mConfigurationReplicationTopic;
+};
+
+void ConfigurationReplicatorImpl::registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx& service, const Ice::Current&)
+{
+    if (mConfigurationReplicationTopic)
+    {
+	IceStorm::QoS qos;
+        qos["reliability"] = "ordered";
+
+        try
+        {
+            mConfigurationReplicationTopic->subscribeAndGetPublisher(qos, service);
+        }
+        catch (const IceStorm::AlreadySubscribed&)
+        {
+            // This is perfectly okay actually, it just means what they wanted us to do
+            // is already done.
+        }
+    }
+}
+ComponentStateReplicator::ComponentStateReplicator(const AsteriskSCF::System::Logging::Logger& logger,
+                     const string& componentDiscoveryCategory,
+                     bool replicatesConfiguration) :
+      Component(logger, componentDiscoveryCategory),
+      mReplicatesConfiguration(replicatesConfiguration)
+{
+}
+
+/**
+ * In the required override of registerPrimaryServices(), this operation should
+ * be called for each primary interface registered with the service locator.
+ */
+void ComponentStateReplicator::managePrimaryService(const LocatorRegistrationWrapperPtr& service)
+{
+    Component::managePrimaryService(service);
+
+    if (mReplicatesConfiguration)
+    {
+        // Add the configuration repliator service as a facet to all primary services being registered
+        // with this state replicator. 
+        getServiceAdapter()->addFacet(mConfigurationReplicator, 
+                                      service->getServiceIdentity(),
+	                              ReplicatorFacet);
+    }
+}
+
+/**
+ * Create a ReplicationContext for this component. 
+ * This operation is a step in initialize()'s Template Method pattern.
+ */
+void ComponentStateReplicator::initReplicationContext()
+{
+    try
+    {
+        // Currently replicators are all assumed to be standalone instances.
+        // In the near future this will change. When it does, change the 
+        // default for this property to false.
+        bool standalone = AsteriskSCF::getBooleanPropertyValueWithDefault( 
+            getCommunicator()->getProperties(), getName() + ".Standalone", true);
+
+        ReplicationStateType state(STANDBY_IN_REPLICA_GROUP);
+
+        if (standalone)
+        {
+            state = ACTIVE_STANDALONE;
+        }
+
+        // Create the replication context.
+        setReplicationContext(createReplicationContext(state));
+    }
+    catch(const std::exception& e)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << e.what();
+        throw;
+    }
+}
+
+/**
+ * Create a service that supports replicating configuration data.  
+ * This operation is a step in initialize()'s Template Method pattern,
+ * but is only called if this object was constructed with the 'replicatesConfiguration'
+ * parameter set to true. 
+ */
+void ComponentStateReplicator::createConfigurationReplicationService()
+{
+    mIceStorm = new AsteriskSCF::CollocatedIceStorm::CollocatedIceStorm(getName(), getCommunicator()->getProperties());
+    IceStorm::TopicManagerPrx topicManager = mIceStorm->createTopicManagerProxy(getCommunicator());
+
+    IceStorm::TopicPrx topic;
+
+    if (topicManager)
+    {
+        try
+        {
+            topic = topicManager->retrieve("ConfigurationReplication");
+        }
+        catch (const IceStorm::NoSuchTopic&)
+        {
+            try
+            {
+                topic = topicManager->create("ConfigurationReplication");
+            }
+            catch (const IceStorm::TopicExists&)
+            {
+                mLogger(Error) << "Race condition creating topic, aborting";
+                return;
+            }
+        }
+        // There is no cast here on purpose as this is just going to get passed to
+        // the service locator which just takes a plain ol' proxy anyway.
+        mConfigurationPublisher = topic->getPublisher();
+    }
+    else
+    {
+        mLogger(Info) << "IceStorm topic manager proxy not present, unable to perform configuration replication.";
+    }
+
+    // Create our ConfigurationReplicator interface support.
+    mConfigurationReplicator = new ConfigurationReplicatorImpl(topic);
+}
+
+/**
+ * This notification is called by base Component during initialization, 
+ * just before required overrides are called to create the primary 
+ * services of the component. 
+ */
+void ComponentStateReplicator::onPreServiceCreation()
+{
+    if (mReplicatesConfiguration)
+    {
+        createConfigurationReplicationService();
+    }
+}
+
+/**
+ * This notification is called by base Component during initialization, 
+ * just before required overrides are called to create the primary 
+ * services of the component. 
+ */
+void ComponentStateReplicator::onStop()
+{
+    if (mReplicatesConfiguration)
+    {
+        mIceStorm->stop();
+    }
+}
+
+} // end Component
+} // end AsteriskSCF

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


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



More information about the asterisk-scf-commits mailing list