[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "pjlib-thread-hook" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Sep 22 16:11:27 CDT 2011
branch "pjlib-thread-hook" has been created
at b09018e286d33f717e2c3656f5fd4e9dd1884a21 (commit)
- Log -----------------------------------------------------------------
commit b09018e286d33f717e2c3656f5fd4e9dd1884a21
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Sep 22 16:09:36 2011 -0500
Add a common implementation of a thread hook used for tracking Ice runtime
threads in a component that also use PJLIB.
* Adds a new library, astscf-ice-util-cpp-pjlib.
diff --git a/include/AsteriskSCF/PJLib/ThreadHook.h b/include/AsteriskSCF/PJLib/ThreadHook.h
new file mode 100644
index 0000000..b3e79b6
--- /dev/null
+++ b/include/AsteriskSCF/PJLib/ThreadHook.h
@@ -0,0 +1,104 @@
+/*
+ * 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 <exception>
+#include <map>
+
+#include <Ice/Ice.h>
+
+#include <pjlib.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
+
+namespace AsteriskSCF
+{
+
+namespace PJLib
+{
+
+class ASTSCF_DLL_EXPORT ThreadRegistrationFailed : public std::exception
+{
+public:
+ ThreadRegistrationFailed(pj_status_t res) : result(res)
+ {
+ }
+
+ virtual const char* what() throw()
+ {
+ return "pj_thread_register() returned failure.";
+ }
+
+ pj_status_t result;
+};
+
+class ASTSCF_DLL_EXPORT ThreadHook : public virtual Ice::ThreadNotification
+{
+public:
+ ThreadHook()
+ {
+ pj_init();
+ }
+
+ /**
+ * Implementation of the start function which is called when a thread is starting.
+ */
+ void start();
+
+ /**
+ * Implementation of the stop function which is called when a thread is being stopped.
+ */
+ void stop();
+
+ /**
+ * Wrapper class around pj_thread_desc.
+ */
+ class ThreadDescWrapper
+ {
+ public:
+ ThreadDescWrapper()
+ {
+ memset(mDesc, 0, sizeof(mDesc));
+ }
+
+ /**
+ * pjthread thread description information, must persist for the life of the thread
+ */
+ pj_thread_desc mDesc;
+ };
+
+ /**
+ * Type definition used to create a smart pointer for the above.
+ */
+ typedef boost::shared_ptr<ThreadDescWrapper> ThreadDescWrapperPtr;
+
+private:
+ /**
+ * A map containing thread lifetime persistent data.
+ */
+ std::map<pj_thread_t*, ThreadDescWrapperPtr> mpjThreads;
+
+ /**
+ * Mutex to protect the map
+ */
+ boost::mutex mLock;
+};
+
+} // end namespace PJLib
+} // end namespace AsteriskSCF
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ae964db..b2712ce 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,3 +14,11 @@ astscf_component_add_slice_collection_libraries(astscf-ice-util-cpp ASTSCF)
astscf_component_build_library(astscf-ice-util-cpp)
target_link_libraries(astscf-ice-util-cpp logging-client)
astscf_component_install(astscf-ice-util-cpp)
+
+astscf_component_init(astscf-ice-util-cpp-pjlib)
+add_subdirectory(PJLib)
+astscf_component_add_boost_libraries(astscf-ice-util-cpp core)
+astscf_component_build_library(astscf-ice-util-cpp-pjlib)
+target_link_libraries(astscf-ice-util-cpp logging-client)
+astscf_component_install(astscf-ice-util-cpp-pjlib)
+pjproject_link(astscf-ice-util-cpp-pjlib pjlib)
diff --git a/src/PJLib/CMakeLists.txt b/src/PJLib/CMakeLists.txt
new file mode 100644
index 0000000..be5232e
--- /dev/null
+++ b/src/PJLib/CMakeLists.txt
@@ -0,0 +1 @@
+astscf_component_add_files(astscf-ice-util-cpp-pjlib ThreadHook.cpp)
diff --git a/src/PJLib/ThreadHook.cpp b/src/PJLib/ThreadHook.cpp
new file mode 100644
index 0000000..b09fb46
--- /dev/null
+++ b/src/PJLib/ThreadHook.cpp
@@ -0,0 +1,57 @@
+/*
+ * 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 <AsteriskSCF/PJLib/ThreadHook.h>
+
+namespace AsteriskSCF
+{
+
+namespace PJLib
+{
+
+/**
+ * Implementation of the start function which is called when a thread is started.
+ */
+void ThreadHook::start()
+{
+ ThreadDescWrapperPtr wrapper(new ThreadDescWrapper());
+ pj_thread_t *thread;
+ pj_status_t win = pj_thread_register("ICE Thread", wrapper->mDesc, &thread);
+ if (win != PJ_SUCCESS)
+ {
+ throw ThreadRegistrationFailed(win);
+ }
+ else
+ {
+ boost::lock_guard<boost::mutex> lock(mLock);
+ mpjThreads.insert(std::make_pair(thread, wrapper));
+ }
+}
+
+/**
+ * Implementation of the stop function which is called when a thread is being stopped.
+ */
+void ThreadHook::stop()
+{
+ if (pj_thread_is_registered())
+ {
+ boost::lock_guard<boost::mutex> lock(mLock);
+ mpjThreads.erase(pj_thread_this());
+ }
+}
+
+} // end namespace PJLib
+} // end namespace AsteriskSCF
commit d8d94a2704d08f1a2d8be9237be3ad64cb16e1c6
Author: Ken Hunt <ken.hunt at digium.com>
Date: Tue Sep 20 13:44:12 2011 -0500
Changed default port of Service Locator Management to match new config files.
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index 3c0c055..f654031 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -754,7 +754,7 @@ void Component::initServiceLocatorProxies()
mServiceLocatorManagement =
ServiceLocatorManagementPrx::checkedCast(mCommunicator->stringToProxy(
mCommunicator->getProperties()->getPropertyWithDefault(
- ServiceLocatorManagementPropertyName, "LocatorServiceManagement:tcp -p 4422")));
+ ServiceLocatorManagementPropertyName, "LocatorServiceManagement:tcp -p 4412")));
// Get a proxy to the interface for the Service Locator.
mServiceLocator =
commit 61b99317e07703ecd0001889f4fad41e5dfdfc44
Author: Ken Hunt <ken.hunt at digium.com>
Date: Mon Sep 19 18:09:23 2011 -0500
Updated Component test config file for changes to component configration properties.
diff --git a/test/Component/component-base-test.conf b/test/Component/component-base-test.conf
index 40a2199..17e30f3 100644
--- a/test/Component/component-base-test.conf
+++ b/test/Component/component-base-test.conf
@@ -14,73 +14,39 @@ IceBox.Service.ComponentTest=component-base-test:create
IceBox.LoadOrder=ServiceDiscovery,MockComponent,ComponentTest
-MockComponent.Endpoints=tcp -p 10090
-MockComponent.Backplane.Endpoints=tcp -p 10091
+MockComponent.ServiceAdapter.Endpoints=tcp -p 10090
+MockComponent.BackplaneAdapter.Endpoints=tcp -p 10091
MockComponent.ThreadPool.Size=4
MockComponent.ThreadPool.SizeMax=10
MockComponent.ThreadPool.SizeWarn=9
# Expose the ComponentTest interface facet.
MockComponent.ComponentTest=yes
-
-MockComponent.Standby=no
-
MockComponent.Standalone=yes
-
-ComponentTest.Endpoints=tcp -p 10300
-
-#Replicator.InstanceName=Replicator
-#Replicator.Endpoints=default -p 10704
-#Replicator.ComponentService.Endpoints=default -p 10705
-#Replicator.ThreadPool.Size=4
-#Replicator.ThreadPool.SizeMax=10
-#Replicator.ThreadPool.SizeWarn=9
+MockComponent.Standby=no
# For testing
+ComponentTest.Endpoints=tcp -p 10300
ComponentService.Proxy=ComponentService:tcp -p 10091
-
-# Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
-LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
-
-# Where to find the Service Locator.
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4412
LocatorService.Proxy=LocatorService:tcp -p 4411
# Endpoints for Icestorm events
-TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
+TopicManager.Proxy=ServiceDiscovery/TopicManager:default -p 4421
##########################################
# Service Locator properties
-AsteriskSCFIceStorm.InstanceName=AsteriskSCFIceStorm
-#
-# This property defines the endpoints on which the IceStorm
-# TopicManager listens.
-AsteriskSCFIceStorm.TopicManager.Endpoints=default -p 10000
-
-# This property defines the endpoints on which the topic
-# publisher objects listen. If you want to federate
-# IceStorm instances this must run on a fixed port (or use
-# IceGrid).
-#
-AsteriskSCFIceStorm.Publish.Endpoints=tcp -p 10001:udp -p 10001
-#
-# TopicManager Tracing
-#
-# 0 = no tracing
-# 1 = trace topic creation, subscription, unsubscription
-# 2 = like 1, but with more detailed subscription information
-AsteriskSCFIceStorm.Trace.TopicManager=2
-AsteriskSCFIceStorm.Transient=1
-AsteriskSCFIceStorm.Flush.Timeout=2000
-
-# Test endpoints for the service locator management adapter
-ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+ServiceDiscovery.IceStorm.InstanceName=ServiceDiscovery
+ServiceDiscovery.IceStorm.TopicManager.Endpoints=default -p 4421
+ServiceDiscovery.IceStorm.Publish.Endpoints=tcp -p 4422:udp -p 4422
+ServiceDiscovery.IceStorm.Trace.TopicManager=2
+ServiceDiscovery.IceStorm.Transient=1
+ServiceDiscovery.IceStorm.Flush.Timeout=2000
-# Test endpoints for the service locator adapter
-ServiceLocatorAdapter.Endpoints=tcp -p 4411
-ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
+ServiceDiscovery.Management.ServiceAdapter.Endpoints=tcp -p 4412
+ServiceDiscovery.Locator.ServiceAdapter.Endpoints=tcp -p 4411
+ServiceDiscovery.BackplaneAdapter.Endpoints=tcp -p 4410
+ServiceDiscovery.Standalone=true
-# Logger configuration
-LoggerAdapter.Endpoints=default
-AsteriskSCF.Logging.logger.AsteriskSCF=Error
commit 55c5019c185270ba5798a041c02201736e28c32e
Author: Brent Eagles <beagles at digium.com>
Date: Mon Sep 19 16:27:12 2011 -0230
Add ".IceStorm" to the properties handed into the IceStorm library for
consistency with property names.
diff --git a/src/CollocatedIceStorm/CollocatedIceStorm.cpp b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
index 0f24f46..d5e9cea 100644
--- a/src/CollocatedIceStorm/CollocatedIceStorm.cpp
+++ b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
@@ -52,10 +52,11 @@ CollocatedIceStorm::CollocatedIceStorm(const std::string& namePrefix, const Ice:
mService = factory(mCommunicator);
assert(mService != 0);
Ice::StringSeq options;
- mService->start(namePrefix, mCommunicator, options);
+ std::string prefix = namePrefix + ".IceStorm";
+ mService->start(prefix, mCommunicator, options);
std::stringstream os;
- os << properties->getPropertyWithDefault(namePrefix + ".IceStorm.InstanceName", "IceStorm") << "/TopicManager:";
- os << properties->getProperty(namePrefix + ".IceStorm.TopicManager.Endpoints");
+ os << properties->getPropertyWithDefault(prefix + ".InstanceName", "IceStorm") << "/TopicManager:";
+ os << properties->getProperty(prefix + ".TopicManager.Endpoints");
mTopicManagerString = os.str();
}
commit afaf84290379d63d85c66a197c0c8ebac81d194a
Author: Brent Eagles <beagles at digium.com>
Date: Mon Sep 19 12:25:52 2011 -0230
Adding a facility to the collocated Ice storm class to allow the topic manager
proxy to be created using information provided when the IceStorm instance was
created. This makes it unnecessary for the service creating the collocated
IceStorm instance to have a property for obtaining the proxy for the collocated
topic manager.
diff --git a/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h b/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
index 4cac3e1..37b51bc 100644
--- a/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
+++ b/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
@@ -43,11 +43,20 @@ public:
*/
void stop();
+ /**
+ *
+ * We need to hand in the communicator that the proxy should be created on to avoid
+ * unexpected behavior.
+ *
+ */
+ IceStorm::TopicManagerPrx createTopicManagerProxy(const Ice::CommunicatorPtr& communicator);
+
private:
IceUtilInternal::DynamicLibraryPtr mLibrary;
IceBox::ServicePtr mService;
Ice::CommunicatorPtr mCommunicator;
bool mStopped;
+ std::string mTopicManagerString;
};
typedef IceUtil::Handle<CollocatedIceStorm> CollocatedIceStormPtr;
diff --git a/src/CollocatedIceStorm/CollocatedIceStorm.cpp b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
index cd37418..0f24f46 100644
--- a/src/CollocatedIceStorm/CollocatedIceStorm.cpp
+++ b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
@@ -17,6 +17,7 @@
#include <IceStorm/IceStorm.h>
#include <assert.h>
#include <algorithm>
+#include <sstream>
#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
@@ -52,6 +53,10 @@ CollocatedIceStorm::CollocatedIceStorm(const std::string& namePrefix, const Ice:
assert(mService != 0);
Ice::StringSeq options;
mService->start(namePrefix, mCommunicator, options);
+ std::stringstream os;
+ os << properties->getPropertyWithDefault(namePrefix + ".IceStorm.InstanceName", "IceStorm") << "/TopicManager:";
+ os << properties->getProperty(namePrefix + ".IceStorm.TopicManager.Endpoints");
+ mTopicManagerString = os.str();
}
CollocatedIceStorm::~CollocatedIceStorm()
@@ -86,3 +91,8 @@ ASTSCF_DLL_EXPORT void CollocatedIceStorm::stop()
mStopped = true;
}
}
+
+IceStorm::TopicManagerPrx CollocatedIceStorm::createTopicManagerProxy(const Ice::CommunicatorPtr& communicator)
+{
+ return IceStorm::TopicManagerPrx::checkedCast(communicator->stringToProxy(mTopicManagerString));
+}
commit 1f46a195dc0bf69cb6ea3e1d2a67874b1b2fb862
Author: Ken Hunt <ken.hunt at digium.com>
Date: Fri Sep 16 12:09:00 2011 -0500
Changes to the adapter names for config cleanup.
diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index 5377bc8..a83b0f5 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -297,6 +297,9 @@ private:
Ice::CommunicatorPtr mCommunicator;
Ice::StringSeq mArgs;
+ std::string mServiceAdapterName;
+ std::string mBackplaneAdapterName;
+
AsteriskSCF::System::Component::V1::ComponentServicePtr mComponentService;
AsteriskSCF::System::Component::V1::ComponentServicePrx mComponentServicePrx;
AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr mComponentRegistration;
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index c584c57..3c0c055 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -578,15 +578,16 @@ void Component::createAdapters()
{
try
{
+
// Create the adapter that our functional services are published on.
// 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"));
+ mServiceAdapter = mCommunicator->createObjectAdapterWithEndpoints(mServiceAdapterName,
+ mCommunicator->getProperties()->getPropertyWithDefault(mServiceAdapterName + ".Endpoints", "default"));
// Create an adapter for our backplane services.
- mBackplaneAdapter = mCommunicator->createObjectAdapterWithEndpoints(mName + ".Backplane",
- mCommunicator->getProperties()->getPropertyWithDefault(mName + ".Backplane.Endpoints", "default"));
+ mBackplaneAdapter = mCommunicator->createObjectAdapterWithEndpoints(mBackplaneAdapterName,
+ mCommunicator->getProperties()->getPropertyWithDefault(mBackplaneAdapterName + ".Endpoints", "default"));
}
catch(const std::exception& e)
{
@@ -862,6 +863,9 @@ void Component::start(const string& name,
mServiceName = mCommunicator->getProperties()->getPropertyWithDefault(mName + ".ServiceName", "default");
+ mServiceAdapterName = mName + ".ServiceAdapter";
+ mBackplaneAdapterName = mName + ".BackplaneAdapter";
+
if (!mInitialized)
{
initialize();
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list