[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "baserep" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Dec 16 08:38:33 CST 2011


branch "baserep" has been created
        at  bec64096b7e5578527b6b5843e1d17e94c20181d (commit)

- Log -----------------------------------------------------------------
commit bec64096b7e5578527b6b5843e1d17e94c20181d
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Dec 15 17:38:23 2011 -0600

    Use base ComponentStateReplicator, and renamed the BridgeReplicatorService.cpp to ComponentStateReplicator.cpp.

diff --git a/src/BridgeReplicatorService.cpp b/src/BridgeReplicatorService.cpp
deleted file mode 100644
index 7ee758c..0000000
--- a/src/BridgeReplicatorService.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010-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 <Ice/Ice.h>
-#include <IceBox/IceBox.h>
-
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include <AsteriskSCF/logger.h>
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include "ServiceUtil.h"
-#include "BridgeReplicatorIf.h"
-#include <AsteriskSCF/Replication/StateReplicator.h>
-
-using namespace AsteriskSCF::System::Logging;
-using namespace AsteriskSCF::SessionCommunications::V1;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::Replication::BridgeService::V1;
-using namespace AsteriskSCF;
-using namespace std;
-
-typedef AsteriskSCF::Replication::StateReplicator<
-    AsteriskSCF::Replication::BridgeService::V1::Replicator,
-    AsteriskSCF::Replication::BridgeService::V1::ReplicatedStateItemPtr,
-    string,
-    AsteriskSCF::Replication::BridgeService::V1::ReplicatorListenerPrx> ReplicatorI;
-
-typedef IceUtil::Handle<ReplicatorI> ReplicatorIPtr;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
-}
-
-namespace
-{
-
-class BridgeReplicatorApp : public IceBox::Service
-{
-public:
-    BridgeReplicatorApp();
-
-protected:
-    void start(const string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args);
-    void stop();
-
-private:
-    /**
-     * A proxy to the service locator manager for the bridge replicator service.
-     */
-    IceUtil::Handle<LocatorRegistrationWrapper<ReplicatorPrx> > mLocator;
-    Ice::ObjectAdapterPtr mAdapter;
-    IceUtil::Handle<RegisterThread<ReplicatorPrx> > mRegisterThread; 
-    ReplicatorIPtr mReplicator;
-};
-
-BridgeReplicatorApp::BridgeReplicatorApp()
-{
-}
-
-void BridgeReplicatorApp::start(const string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq&)
-{
-    Logger logger = getLoggerFactory().getLogger("AsteriskSCF.BridgeReplicator");
-    logger(Debug) << "Launching AsteriskSCF Bridge Replicator Service." ;
-
-    //
-    // It is standard practice to base the adapter name on the configured
-    // service instance name.
-    //
-    string adapterName;
-    if(name.size() == 0)
-    {
-        adapterName = "Adapter";
-    }
-    else
-    {
-        adapterName = name + ".Adapter";
-    }
-
-    //
-    // Check on the threadpool properties, make sure that they are compatible with the requirements of this 
-    // service. This could be moved into a helper method, but it is somehow more clear for seeing what
-    // is going on during initialization to leave it here.
-    //
-    // TODO: Are there any other properties that need to be double-checked before proceeding?
-    //
-    Ice::Int defaultPoolSize = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 0);
-    if (communicator->getProperties()->getPropertyAsIntWithDefault(adapterName + ".ThreadPool.Size", 0) < 4)
-    {
-        if (defaultPoolSize < 4)
-        {
-            logger(Info) << "Configured thread pool size for " << adapterName + " is too small, defaulting to 4";
-            communicator->getProperties()->setProperty(adapterName + ".ThreadPool.Size", "4");
-        }
-    }
-
-    //
-    // TODO: All adapter ids should be globally unique. This would allow replicas to be identified.
-    // How this might be useful is that it might be used as a replicated state item to identify
-    // which adapter is currently the primary in a group of replicas.
-    //
-    mAdapter = communicator->createObjectAdapterWithEndpoints(adapterName,
-        communicator->getProperties()->getPropertyWithDefault(adapterName + ".Endpoints", "default"));
-
-    //
-    // Configure the AsteriskSCF logger.
-    // TODO: check whether this works right if we've already created the logger object.
-    //
-    ConfiguredIceLoggerPtr iceLogger = createIceLogger(mAdapter);
-    getLoggerFactory().setLogOutput(iceLogger->getLogger());
-
-
-    string property = communicator->getProperties()->getProperty("LocatorServiceManagement.Proxy");
-    if(property.size() == 0)
-    {
-        throw IceBox::FailureException(__FILE__, __LINE__,
-                "Configuration error: Unable to locate property `LocatorServiceManagement.Proxy'");
-    }
-    
-    //
-    // TODO: The bridge manager's identity should come from a central configuration and/or a replicator
-    // service.
-    //
-    string managerName = "BridgeReplicator";
-    mReplicator = new ReplicatorI;
-    ReplicatorPrx replicatorPrx = ReplicatorPrx::uncheckedCast(mAdapter->add(mReplicator, communicator->stringToIdentity(managerName)));
-
-    assert(replicatorPrx != 0);
-    if(replicatorPrx == 0)
-    {
-        throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge replicator object");
-    }
-
-    bool registered = false;
-    try
-    {
-        std::string serviceName = communicator->getProperties()->getPropertyWithDefault(
-          name + ".ServiceName", "default");
-
-        ServiceLocatorParamsPtr locatorParameters = new ServiceLocatorParams;
-        locatorParameters->category = StateReplicatorDiscoveryCategory;
-        locatorParameters->service = serviceName;
-        locatorParameters->id = communicator->getProperties()->getPropertyWithDefault(name + ".StateReplicatorId",
-                "default");
-        mLocator = new LocatorRegistrationWrapper<ReplicatorPrx>(communicator, property, replicatorPrx, adapterName, 
-          locatorParameters);
-        registered = mLocator->registerService();
-    }
-    catch(const Ice::Exception& e)
-    {
-        lg(Error) << "Exception starting bridge replicator: " << e.what();
-        throw;
-    }
-
-    if(!registered)
-    {
-        mRegisterThread = new RegisterThread<ReplicatorPrx>(mLocator);
-        mRegisterThread->start();
-    }
-    //
-    // TODO: We need to know whether or not to activate!
-    //
-    mAdapter->activate();
-}
-
-void BridgeReplicatorApp::stop()
-{
-    if(mRegisterThread)
-    {
-        mRegisterThread->stop();
-    }
-    try
-    {
-        mLocator->unregister();
-    }
-    catch(const Ice::Exception&)
-    {
-    }
-    try
-    {
-        Ice::CommunicatorPtr comm = mAdapter->getCommunicator();
-        comm->shutdown();
-        mAdapter->waitForDeactivate();
-        comm->destroy();
-    }
-    catch(...)
-    {
-        // TODO: log
-    }
-}
-}
-
-extern "C" {
-ASTSCF_DLL_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
-{
-    return new BridgeReplicatorApp;
-}
-}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4e20b5c..65d0f0b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -43,11 +43,11 @@ target_link_libraries(bridgeservice astscf-ice-util-cpp logging-client)
 astscf_component_install(bridgeservice)
 
 astscf_component_init(BridgeReplicator)
-astscf_component_add_files(BridgeReplicator BridgeReplicatorService.cpp)
+astscf_component_add_files(BridgeReplicator ComponentStateReplicator.cpp)
 astscf_component_add_slices(BridgeReplicator PROJECT AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice)
 astscf_component_add_ice_libraries(BridgeReplicator IceStorm)
 astscf_component_add_boost_libraries(BridgeReplicator thread date_time)
 astscf_component_add_slice_collection_libraries(BridgeReplicator ASTSCF)
 astscf_component_build_icebox(BridgeReplicator)
-target_link_libraries(BridgeReplicator logging-client)
+target_link_libraries(BridgeReplicator logging-client astscf-ice-util-cpp)
 astscf_component_install(BridgeReplicator)
diff --git a/src/ComponentStateReplicator.cpp b/src/ComponentStateReplicator.cpp
new file mode 100644
index 0000000..c651315
--- /dev/null
+++ b/src/ComponentStateReplicator.cpp
@@ -0,0 +1,115 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-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 <Ice/Ice.h>
+
+#include <AsteriskSCF/Component/ComponentStateReplicator.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Replication/StateReplicator.h>
+#include <AsteriskSCF/logger.h>
+#include "ServiceUtil.h"
+#include "BridgeReplicatorIf.h"
+
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::Replication::BridgeService::V1;
+using namespace AsteriskSCF::Discovery;
+using namespace AsteriskSCF;
+using namespace std;
+
+typedef AsteriskSCF::Replication::StateReplicator<
+    AsteriskSCF::Replication::BridgeService::V1::Replicator,
+    AsteriskSCF::Replication::BridgeService::V1::ReplicatedStateItemPtr,
+    string,
+    AsteriskSCF::Replication::BridgeService::V1::ReplicatorListenerPrx> ReplicatorI;
+
+typedef IceUtil::Handle<ReplicatorI> ReplicatorIPtr;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
+}
+
+namespace
+{
+
+class ComponentStateReplicator : public AsteriskSCF::Component::ComponentStateReplicator
+{
+public:
+    ComponentStateReplicator() :
+      AsteriskSCF::Component::ComponentStateReplicator(lg, AsteriskSCF::Replication::BridgeService::V1::StateReplicatorComponentCategory, false)
+    {
+    }
+
+    ~ComponentStateReplicator() {}
+
+    ///////////////////////////////////////////////////
+    // Required overrides
+
+    void createPrimaryServices();
+    void preparePrimaryServicesForDiscovery();
+
+private:
+    ReplicatorIPtr mReplicator;
+    ReplicatorPrx mReplicatorPrx;
+    LocatorRegistrationWrapperPtr mStateReplicatorRegistration;
+};
+
+/**
+ * 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(mReplicatorPrx,
+                                                                  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()
+{
+    //
+    // TODO: The bridge manager's identity should come from a central configuration and/or a replicator
+    // service.
+    //
+    string managerName = "BridgeReplicator";
+    mReplicator = new ReplicatorI;
+    mReplicatorPrx = ReplicatorPrx::uncheckedCast(getServiceAdapter()->add(mReplicator, getCommunicator()->stringToIdentity(managerName)));
+
+    assert(mReplicatorPrx != 0);
+    if(mReplicatorPrx == 0)
+    {
+        throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge replicator object");
+    }
+}
+
+} // end unnamed namespace
+
+extern "C" {
+ASTSCF_DLL_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new ComponentStateReplicator;
+}
+}

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list