[asterisk-scf-commits] asterisk-scf/release/routing.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Feb 6 11:13:51 CST 2012


branch "master" has been updated
       via  9001b8584ae8028c6be5d0245f962370ce60776c (commit)
      from  5642fdc45554ff4b46af29f1a06515e26608b0f5 (commit)

Summary of changes:
 src/BasicRoutingStateReplicatorApp.cpp |  326 --------------------------------
 src/CMakeLists.txt                     |    4 +-
 src/ComponentStateReplicator.cpp       |  125 ++++++++++++
 3 files changed, 127 insertions(+), 328 deletions(-)
 delete mode 100644 src/BasicRoutingStateReplicatorApp.cpp
 create mode 100644 src/ComponentStateReplicator.cpp


- Log -----------------------------------------------------------------
commit 9001b8584ae8028c6be5d0245f962370ce60776c
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Feb 3 18:24:18 2012 -0600

    Using base class ComponentStateReplicator for the replicator service.

diff --git a/src/BasicRoutingStateReplicatorApp.cpp b/src/BasicRoutingStateReplicatorApp.cpp
deleted file mode 100644
index 0e385dd..0000000
--- a/src/BasicRoutingStateReplicatorApp.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010, 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 <Ice/Ice.h>
-#include <IceUtil/UUID.h>
-#include <IceStorm/IceStorm.h>
-#include <IceBox/IceBox.h>
-
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
-#include <AsteriskSCF/Logger.h>
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include <AsteriskSCF/Replication/StateReplicator.h>
-#include "BasicRoutingStateReplicationIf.h"
-
-using namespace std;
-using namespace AsteriskSCF::Core;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::System::Component::V1;
-using namespace AsteriskSCF::System::Logging;
-using namespace AsteriskSCF::Replication::BasicRoutingService::V1;
-using namespace AsteriskSCF::Core::Routing::V1;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BasicRoutingServiceStateReplicator");
-}
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-
-typedef AsteriskSCF::Replication::StateReplicator< RoutingStateReplicator, 
-                                                   RoutingStateItemPtr, 
-                                                   std::string, 
-                                                   RoutingStateReplicatorListenerPrx> RoutingStateReplicatorI;
-typedef IceUtil::Handle<RoutingStateReplicatorI> RoutingStateReplicatorIPtr;
-
-};
-};
-
-using namespace AsteriskSCF::BasicRoutingService;
-
-/**
- * This class implements a very simplistic replication capability using the StateReplicator template.
- */
-class BasicRoutingStateReplicatorService : public IceBox::Service
-{
-public:
-    BasicRoutingStateReplicatorService() : mRunning(false), mInitialized(false) {};
-    ~BasicRoutingStateReplicatorService() {};
-
-    void suspend();
-    void resume();
-
-    ////// Overrides of IceBox::Service methods. 
-    virtual void start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
-    virtual void stop();
-
-private:
-    void suspendService(bool shuttingDown);
-    void initialize(const std::string& appName);
-    void registerWithServiceLocator();
-    void deregisterFromServiceLocator(bool includeComponentService);
-    std::string mAppName;
-
-    bool mRunning;
-    bool mInitialized;
-    ::Ice::ObjectAdapterPtr mServiceAdapter;
-    ::Ice::CommunicatorPtr mCommunicator;
-    ServiceLocatorManagementPrx mServiceLocatorManagement;
-    Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
-    Discovery::V1::ServiceManagementPrx mStateReplicationManagement;
-    ConfiguredIceLoggerPtr mIceLogger;
-    RoutingStateReplicatorIPtr mStateReplicator;
-
-    ComponentServicePrx mComponentServicePrx;
-    RoutingStateReplicatorPrx mStateReplicatorPrx;
-};
-typedef ::IceUtil::Handle<BasicRoutingStateReplicatorService> BasicRoutingStateReplicatorServicePtr;
-
-static const string ComponentServiceId("BasicRoutingStateReplicatorComponent");
-static const string ServiceDiscoveryId("BasicRoutingStateReplicatorService");
-
-/**
- * This class provides implementation for the ComponentService interface, which
- * every Asterisk SCF component is expected to publish.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
-    ComponentServiceImpl(BasicRoutingStateReplicatorService* service) : mService(service) {}
-
-public: // Overrides of the ComponentService interface.
-    virtual void suspend(const ::Ice::Current&)
-    {
-        mService->suspend();
-    }
-
-    virtual void resume(const ::Ice::Current&)
-    {
-        mService->resume();
-    }
-
-    virtual void shutdown(const ::Ice::Current&)
-    {
-        mService->stop();
-    }
-
-private:
-    BasicRoutingStateReplicatorServicePtr mService;
-};
-
-/**
- * Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
- * other components can look up our interfaces.
- */
-void setCategory(const Discovery::V1::ServiceManagementPrx& serviceManagement, 
-		 const string& category,
-		 const string& service,
-		 const string& id="")
-{
-    // Add category as a parameter to enable other components look this component up.
-    ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams;
-    genericparams->category = category;
-    genericparams->service = service;
-    genericparams->id = id;
-    serviceManagement->addLocatorParams(genericparams, "");
-}
-
-/**
- * Register this component's primary public interfaces with the Service Locator.
- * This enables other Asterisk SCF components to locate our interfaces.
- */
-void BasicRoutingStateReplicatorService::registerWithServiceLocator()
-{
-    try
-    {
-	string serviceName = mCommunicator->getProperties()->getPropertyWithDefault(
-		mAppName + ".ServiceName", "default");
-
-        // Add our ComponentService interface and add it to the Service Locator.
-        // Note that this interface has its own adapter.
-        string componentServiceGuid(StateReplicatorComponentCategory);
-        mComponentServiceManagement = mServiceLocatorManagement->addService(mComponentServicePrx, componentServiceGuid);
-        setCategory(mComponentServiceManagement,  StateReplicatorComponentCategory, serviceName);
-
-        // Add our Replicator interface and add it to the Service Locator.
-        mStateReplicationManagement = mServiceLocatorManagement->addService(mStateReplicatorPrx, StateReplicatorDiscoveryCategory);
-
-        string replicatorName = mAppName;
-	setCategory(mStateReplicationManagement, StateReplicatorDiscoveryCategory, serviceName, replicatorName);
-    }
-    catch(...)
-    {
-        lg(Error) << "Exception in " << mAppName << BOOST_CURRENT_FUNCTION;
-        throw;
-    }
-}
-
-/**
- * Deregister this component's primary public interfaces from the Service Locator.
- * This is done at shutdown, and whenever we want to keep other services from locating
- * our interfaces.
- *
- * @param includeBackplane If true, deregisters our backplane interfaces
- * in addition to all our other interfaces, making this component unreachable from the 
- * rest of Asterisk SCF. Should only be done during shutdown.
- */
-void BasicRoutingStateReplicatorService::deregisterFromServiceLocator(bool includeBackplane)
-{
-    try
-    {
-        mStateReplicationManagement->unregister();
-
-        if (includeBackplane)
-        {
-            mComponentServiceManagement->unregister();
-        }
-    }
-    catch(...)
-    {
-        lg(Error) << "Exception in " << mAppName << BOOST_CURRENT_FUNCTION;
-    }
-}
-
-void BasicRoutingStateReplicatorService::initialize(const std::string& appName)
-{
-    mAppName = appName;
-
-    // This is the primary adapter for this component.
-    mServiceAdapter = mCommunicator->createObjectAdapter(mAppName + ".Adapter");
-
-    // setup logging client
-    mIceLogger = createIceLogger(mServiceAdapter);
-    getLoggerFactory().setLogOutput(mIceLogger->getLogger());
-
-    // Create and publish our ComponentService interface.
-    mComponentServicePrx = ComponentServicePrx::uncheckedCast(
-        mServiceAdapter->add(new ComponentServiceImpl(this), mCommunicator->stringToIdentity(ComponentServiceId)));
-
-    // Create our instance of the StateReplicator template. 
-    mStateReplicator = new RoutingStateReplicatorI();
-    mStateReplicatorPrx = RoutingStateReplicatorPrx::uncheckedCast(
-        mServiceAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId)));
-
-    // Activate our adapters.
-    mServiceAdapter->activate();
-
-    // Get a proxy to the management interface for the Service Locator, so we can add 
-    // ourselves into the system discovery mechanisms.
-    mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
-
-    if (mServiceLocatorManagement == 0)
-    {
-        lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. " << BOOST_CURRENT_FUNCTION;
-    }
-
-    mInitialized = true;
-}
-
-void BasicRoutingStateReplicatorService::start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& )
-{
-    mCommunicator = ic;
-
-    if (!mInitialized)
-    {
-        initialize(name);
-    }
-    else
-    {
-        mServiceAdapter->activate();
-    }
-
-    // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-    // can be located.
-    registerWithServiceLocator();
-
-    mRunning = true;
-}
-
-void BasicRoutingStateReplicatorService::resume()
-{
-    if (!mRunning)
-    {
-        mServiceAdapter->add(mStateReplicator, mCommunicator->stringToIdentity(ServiceDiscoveryId));
-
-        // Plug back into the Asterisk SCF discovery system so that the interfaces we provide
-        // can be located.
-        registerWithServiceLocator();
-
-        // Reactivate the primary adapter. 
-        mServiceAdapter->activate();
-    }
-
-    mRunning = true;
-}
-
-/** 
- * Utility function to suspend the service for a suspend() or stop().
- */
-void BasicRoutingStateReplicatorService::suspendService(bool shuttingDown)
-{
-    if (mRunning)
-    {
-        // Deregister our servants.
-        deregisterFromServiceLocator(shuttingDown);
-
-        // Deactive the primary adapter. 
-        // The adapter that services the ComponentService stays active. 
-        mServiceAdapter->deactivate();
-    }
-
-    mRunning = false;
-}
-
-/** 
- * Handle a notice from the ComponentService. 
- */
-void BasicRoutingStateReplicatorService::suspend()
-{
-    lg(Info) << "Suspending...";
-
-    suspendService(false);
-
-    lg(Info) << "Suspended.";
-}
-
-/**
- * Implementation of the required IceBox::Service stop method.
- */
-void BasicRoutingStateReplicatorService::stop()
-{
-    lg(Info) << "Stopping...";
-
-    suspendService(true);
-
-    // Just in case we were in suspend() mode when told to stop.
-    mComponentServiceManagement->unregister();
-
-
-    lg(Info) << "Stopped.";
-}
-
-extern "C"
-{
-ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr )
-{
-    return new BasicRoutingStateReplicatorService;
-}
-}
-
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 64fbf5f..750fbb0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -45,10 +45,10 @@ endif()
 astscf_component_install(BasicRoutingService)
 
 astscf_component_init(BasicRoutingStateReplicator)
-astscf_component_add_files(BasicRoutingStateReplicator BasicRoutingStateReplicatorApp.cpp)
+astscf_component_add_files(BasicRoutingStateReplicator ComponentStateReplicator.cpp)
 astscf_component_add_slices(BasicRoutingStateReplicator PROJECT AsteriskSCF/Replication/BasicRoutingService/BasicRoutingStateReplicationIf.ice)
 astscf_component_add_ice_libraries(BasicRoutingStateReplicator IceStorm)
 astscf_component_add_slice_collection_libraries(BasicRoutingStateReplicator ASTSCF)
 astscf_component_build_icebox(BasicRoutingStateReplicator)
-target_link_libraries(BasicRoutingStateReplicator LoggingClient)
+target_link_libraries(BasicRoutingStateReplicator LoggingClient ASTSCFIceUtilCpp)
 astscf_component_install(BasicRoutingStateReplicator)
diff --git a/src/ComponentStateReplicator.cpp b/src/ComponentStateReplicator.cpp
new file mode 100644
index 0000000..e96d90e
--- /dev/null
+++ b/src/ComponentStateReplicator.cpp
@@ -0,0 +1,125 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, 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 <Ice/Ice.h>
+#include <IceUtil/UUID.h>
+#include <IceStorm/IceStorm.h>
+#include <IceBox/IceBox.h>
+
+#include <AsteriskSCF/Component/ComponentStateReplicator.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Replication/StateReplicator.h>
+#include "BasicRoutingStateReplicationIf.h"
+
+using namespace std;
+using namespace AsteriskSCF::Core;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::Replication::BasicRoutingService::V1;
+using namespace AsteriskSCF::Discovery;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BasicRoutingServiceStateReplicator");
+}
+
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+
+typedef AsteriskSCF::Replication::StateReplicator< RoutingStateReplicator, 
+                                                   RoutingStateItemPtr, 
+                                                   std::string, 
+                                                   RoutingStateReplicatorListenerPrx> RoutingStateReplicatorI;
+typedef IceUtil::Handle<RoutingStateReplicatorI> RoutingStateReplicatorIPtr;
+
+};
+};
+
+/**
+ * This class implements a very simplistic replication capability using the StateReplicator template.
+ */
+class ComponentStateReplicator : public AsteriskSCF::Component::ComponentStateReplicator
+{
+public:
+    ComponentStateReplicator() :
+      AsteriskSCF::Component::ComponentStateReplicator(lg, 
+          AsteriskSCF::Replication::BasicRoutingService::V1::StateReplicatorComponentCategory, 
+          false) 
+    {
+    }
+
+    ~ComponentStateReplicator() {};
+
+    ///////////////////////////////////////////////////
+    // Required overrides
+
+    void createPrimaryServices();
+    void preparePrimaryServicesForDiscovery();
+
+private:
+    AsteriskSCF::BasicRoutingService::RoutingStateReplicatorIPtr mStateReplicator;
+    RoutingStateReplicatorPrx mStateReplicatorPrx;
+    LocatorRegistrationWrapperPtr mStateReplicatorRegistration;
+};
+
+static const string ServiceDiscoveryId("BasicRoutingStateReplicatorService");
+
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void ComponentStateReplicator::preparePrimaryServicesForDiscovery()
+{
+    try
+    {
+        // Wrap our replicator interface for the Service Locator.
+        mStateReplicatorRegistration = wrapServiceForRegistration(mStateReplicatorPrx,
+                                                                  StateReplicatorDiscoveryCategory);
+        managePrimaryService(mStateReplicatorRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION <<
+            ". Exception: " << e.what();
+        throw; // rethrow
+    }
+}
+
+void ComponentStateReplicator::createPrimaryServices()
+{
+    // Create our instance of the StateReplicator template. 
+    mStateReplicator = new AsteriskSCF::BasicRoutingService::RoutingStateReplicatorI;
+    mStateReplicatorPrx = RoutingStateReplicatorPrx::uncheckedCast(
+        getServiceAdapter()->add(mStateReplicator, getCommunicator()->stringToIdentity(ServiceDiscoveryId)));
+
+    assert(mStateReplicatorPrx != 0);
+    if(mStateReplicatorPrx == 0)
+    {
+        throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate routing replicator object");
+    }
+}
+
+extern "C"
+{
+ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr )
+{
+    return new ComponentStateReplicator;
+}
+}
+

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


-- 
asterisk-scf/release/routing.git



More information about the asterisk-scf-commits mailing list