[asterisk-scf-commits] asterisk-scf/integration/servicediscovery.git branch "replication" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Dec 15 20:12:43 UTC 2010


branch "replication" has been updated
       via  aed907cf26570f667cc4fab752d47e85650287f8 (commit)
       via  4aadc688e48d3c3f4ac2b3dafb7f9983ff489662 (commit)
       via  5bfc3333e8192b5ebba8b7fd83328d955661bcb4 (commit)
       via  97a07d6bc5d0b0b822328138ce30bfcbc714673b (commit)
       via  0b7b92b6e857949b41554c1871e50cbf1401391f (commit)
      from  c9172ee2039ce9994e3ea7f5a6872c29e6e429a4 (commit)

Summary of changes:
 src/CMakeLists.txt                       |   22 ++++
 src/ServiceLocatorManagement.cpp         |   91 +++++++++++++-
 src/ServiceLocatorManagement.h           |   17 +++
 src/ServiceLocatorStateListener.cpp      |  199 ++++++++++++++++++++++++++++++
 src/ServiceLocatorStateReplicator.h      |   42 +++++++
 src/ServiceLocatorStateReplicatorApp.cpp |  129 +++++++++++++++++++
 src/ServiceManagement.cpp                |   32 ++++--
 src/ServiceManagement.h                  |    4 +-
 8 files changed, 521 insertions(+), 15 deletions(-)
 create mode 100644 src/ServiceLocatorStateListener.cpp
 create mode 100644 src/ServiceLocatorStateReplicator.h
 create mode 100644 src/ServiceLocatorStateReplicatorApp.cpp


- Log -----------------------------------------------------------------
commit aed907cf26570f667cc4fab752d47e85650287f8
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Dec 15 15:26:33 2010 -0400

    Add missing implementations.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 7c93a6a..b400a85 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -414,15 +414,33 @@ ServiceManagementPrx ServiceLocatorManagementImpl::addService(
 {
     lg(Debug) << "addService(" << guid << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+
+    Ice::Identity identity;
+    identity.name = IceUtil::generateUUID();
+
     ServiceManagementImplPtr new_service = new ServiceManagementImpl(this,
         service,
-        mImpl->mAdapter, mImpl->mLocatorTopic, guid);
+        mImpl->mAdapter, mImpl->mLocatorTopic, guid, identity);
 
     mImpl->mServices.push_back(new_service);
 
     return new_service->getServiceManagementPrx();
 }
 
+ServiceManagementImplPtr ServiceLocatorManagementImpl::addService(const Ice::ObjectPrx& service, 
+    const std::string& guid, const Ice::Identity& identity)
+{
+    lg(Debug) << "addService(" << guid << ')';
+    boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+    ServiceManagementImplPtr new_service = new ServiceManagementImpl(this,
+        service,
+        mImpl->mAdapter, mImpl->mLocatorTopic, guid, identity);
+
+    mImpl->mServices.push_back(new_service);
+
+    return new_service;
+}
+
 ServiceInfoSeq ServiceLocatorManagementImpl::getServices(const ::Ice::Current&) const
 {
     lg(Debug) << "getServices()";
@@ -535,3 +553,53 @@ void ServiceLocatorManagementImpl::removeService(const ServiceManagementImplPtr&
     lg(Error) << "removeService(" << service->getGuid() <<
         ") failed.  service not found";
 }
+
+/**
+ * Function which replicates state items.
+ */
+void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr service,
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr params,
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr comparator)
+{
+    ServiceLocatorStateItemSeq items;
+
+    if (service)
+    {
+	items.push_back(service);
+    }
+
+    if (params)
+    {
+	items.push_back(params);
+    }
+
+    if (comparator)
+    {
+	items.push_back(comparator);
+    }
+}
+
+/**
+ * Function which removes state items from the replicator.
+ */
+void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr service,
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr params,
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr comparator)
+{
+    Ice::StringSeq items;
+
+    if (service)
+    {
+	items.push_back(service->key);
+    }
+
+    if (params)
+    {
+	items.push_back(params->key);
+    }
+
+    if (comparator)
+    {
+	items.push_back(comparator->key);
+    }
+}
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 8aeb092..c0d17b7 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -88,7 +88,7 @@ class ServiceManagementImplPriv
 public:
     ServiceManagementImplPriv(ServiceManagementImpl* impl, ServiceLocatorManagementImplPtr management,
         const Ice::ObjectPrx& service, const Ice::ObjectAdapterPtr& adapter, const AsteriskSCF::System::Discovery::EventsPrx& serviceDiscoveryTopic,
-        const string& guid) :
+        const string& guid, const Ice::Identity& identity) :
 	mStateItem(new ServiceLocatorServiceStateItem()),
         mManagement(management), mAdapter(adapter), mLocatorTopic(serviceDiscoveryTopic)
     {
@@ -96,8 +96,8 @@ public:
 	mStateItem->mSuspended = false;
 	mStateItem->mService = service;
 	mStateItem->mGuid = guid;
-        mManagementPrx = ServiceManagementPrx::uncheckedCast(mAdapter->addWithUUID(impl));
-	mStateItem->mManagementIdentity = mManagementPrx->ice_getIdentity();
+	mManagementPrx = ServiceManagementPrx::uncheckedCast(mAdapter->add(impl, identity));
+	mStateItem->mManagementIdentity = identity;
         if (mLocatorTopic)
         {
             mLocatorTopic->serviceRegistered(guid);
@@ -150,8 +150,9 @@ using namespace AsteriskSCF::System::Discovery;
  * also sends out an event for those that are listening.
  */
 ServiceManagementImpl::ServiceManagementImpl(ServiceLocatorManagementImplPtr management,
-    const Ice::ObjectPrx& service, const Ice::ObjectAdapterPtr& adapter, const EventsPrx& serviceDiscoveryTopic, const string& guid) :
-    mImpl(new ServiceManagementImplPriv(this, management, service, adapter, serviceDiscoveryTopic, guid))
+    const Ice::ObjectPrx& service, const Ice::ObjectAdapterPtr& adapter, const EventsPrx& serviceDiscoveryTopic, const string& guid,
+    const Ice::Identity& identity) :
+    mImpl(new ServiceManagementImplPriv(this, management, service, adapter, serviceDiscoveryTopic, guid, identity))
 {
 }
 
diff --git a/src/ServiceManagement.h b/src/ServiceManagement.h
index ecd3e5c..14b5b13 100644
--- a/src/ServiceManagement.h
+++ b/src/ServiceManagement.h
@@ -33,8 +33,8 @@ class ServiceManagementImplPriv;
 class ServiceManagementImpl : public AsteriskSCF::Core::Discovery::V1::ServiceManagement
 {
 public:
-    ServiceManagementImpl(ServiceLocatorManagementImplPtr, const Ice::ObjectPrx&, const Ice::ObjectAdapterPtr&,
-        const AsteriskSCF::System::Discovery::EventsPrx&, const std::string&);
+   ServiceManagementImpl(ServiceLocatorManagementImplPtr, const Ice::ObjectPrx&, const Ice::ObjectAdapterPtr&,
+        const AsteriskSCF::System::Discovery::EventsPrx&, const std::string&, const Ice::Identity&);
 
     //
     // AsteriskSCF::Core::Discovery::V1::ServiceManagement interface.

commit 4aadc688e48d3c3f4ac2b3dafb7f9983ff489662
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Dec 15 14:46:32 2010 -0400

    Add calls to replicateState and removeState in places where it should be done.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index cb7885b..7c93a6a 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -94,12 +94,24 @@ public:
      *
      * @param compare A proxy to the comparator service we are wrapping.
      */
-    ServiceLocatorComparator(const ServiceLocatorParamsComparePrx& compare, std::string name) :
+    ServiceLocatorComparator(const ServiceLocatorParamsComparePrx& compare, std::string name,
+	ServiceLocatorManagementImplPtr management) :
+	mManagement(management),
 	mStateItem(new ServiceLocatorComparatorStateItem())
     {
 	mStateItem->key = IceUtil::generateUUID();
 	mStateItem->mName = name;
 	mStateItem->mService = compare;
+	mManagement->replicateState(0, 0, mStateItem);
+    }
+
+    /**
+     * Destructor for the ServiceLocatorComparator class.
+     *
+     */
+    ~ServiceLocatorComparator()
+    {
+	mManagement->removeState(0, 0, mStateItem);
     }
 
     /**
@@ -123,6 +135,11 @@ public:
     }
 private:
     /**
+     * A pointer to the locator management instance.
+     */
+    ServiceLocatorManagementImplPtr mManagement;
+
+    /**
      * Comparator state replication item.
      */
     ServiceLocatorComparatorStateItemPtr mStateItem;
@@ -444,7 +461,7 @@ void ServiceLocatorManagementImpl::addCompare(const string& guid,
 {
     lg(Info) << "addCompare(" << guid << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-    ServiceLocatorComparator newComparator(service, guid);
+    ServiceLocatorComparator newComparator(service, guid, this);
 
     pair<map<string, ServiceLocatorComparator>::iterator, bool> insertPair = mImpl->mCompares.insert(pair<string, ServiceLocatorComparator>(guid,
             newComparator));
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 4607d14..214bb90 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -20,6 +20,8 @@
 
 #include <IceUtil/Shared.h>
 
+#include "ServiceLocatorStateReplicationIf.h"
+
 namespace AsteriskSCF
 {
 namespace ServiceDiscovery
@@ -74,6 +76,12 @@ public:
     // Replication related functions.
     ServiceManagementImplPtr addService(const Ice::ObjectPrx&, const std::string&, const
         Ice::Identity&);
+    void replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr, 
+        AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr,
+        AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr);
+    void removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr,
+        AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr,
+        AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr);	
 
     //
     // AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagement interface.
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 579951e..8aeb092 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -50,7 +50,7 @@ class ServiceLocatorParamsSpec
 public:
     ServiceLocatorParamsSpec(const ServiceLocatorParamsPtr& params,
         const std::string& compareGuid,
-        ServiceLocatorManagementImpl* management)
+        ServiceLocatorManagementImplPtr management)
         :
 	mStateItem(new ServiceLocatorParamsStateItem()),
         mManagement(management)
@@ -58,6 +58,12 @@ public:
 	mStateItem->key = IceUtil::generateUUID();
 	mStateItem->mParams = params;
 	mStateItem->mCompareGuid = compareGuid;
+	mManagement->replicateState(0, mStateItem, 0);
+    }
+
+    ~ServiceLocatorParamsSpec()
+    {
+	mManagement->removeState(0, mStateItem, 0);
     }
 
     void isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const IsSupportedCallbackPtr&);
@@ -71,7 +77,7 @@ private:
     /**
      * A pointer to the service locator management implementation that instantiated this class.
      */
-    ServiceLocatorManagementImpl* mManagement;
+    ServiceLocatorManagementImplPtr mManagement;
 };
 
 /**
@@ -80,7 +86,7 @@ private:
 class ServiceManagementImplPriv
 {
 public:
-    ServiceManagementImplPriv(ServiceManagementImpl* impl, ServiceLocatorManagementImpl* management,
+    ServiceManagementImplPriv(ServiceManagementImpl* impl, ServiceLocatorManagementImplPtr management,
         const Ice::ObjectPrx& service, const Ice::ObjectAdapterPtr& adapter, const AsteriskSCF::System::Discovery::EventsPrx& serviceDiscoveryTopic,
         const string& guid) :
 	mStateItem(new ServiceLocatorServiceStateItem()),
@@ -96,6 +102,7 @@ public:
         {
             mLocatorTopic->serviceRegistered(guid);
         }
+	mManagement->replicateState(mStateItem, 0, 0);
     }
 
     /**
@@ -111,7 +118,7 @@ public:
     /**
      * A pointer to the service locator management implementation that instantiated this call.
      */
-    ServiceLocatorManagementImpl* mManagement;
+    ServiceLocatorManagementImplPtr mManagement;
 
     /**
      * A pointer to the object adapter that this service is available on.
@@ -142,7 +149,7 @@ using namespace AsteriskSCF::System::Discovery;
  * Constructor for the ServiceManagementImpl class. This adds itself to the object adapter so the service can perform some management and
  * also sends out an event for those that are listening.
  */
-ServiceManagementImpl::ServiceManagementImpl(ServiceLocatorManagementImpl* management,
+ServiceManagementImpl::ServiceManagementImpl(ServiceLocatorManagementImplPtr management,
     const Ice::ObjectPrx& service, const Ice::ObjectAdapterPtr& adapter, const EventsPrx& serviceDiscoveryTopic, const string& guid) :
     mImpl(new ServiceManagementImplPriv(this, management, service, adapter, serviceDiscoveryTopic, guid))
 {
@@ -313,6 +320,7 @@ void ServiceManagementImpl::suspend(const Ice::Current&)
     {
         lg(Info) << "Suspending " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
         mImpl->mStateItem->mSuspended = true;
+	mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
     }
 
     if (mImpl->mLocatorTopic)
@@ -332,6 +340,7 @@ void ServiceManagementImpl::unsuspend(const Ice::Current&)
     {
         lg(Info) << "Un-suspending " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
         mImpl->mStateItem->mSuspended = false;
+	mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
     }
 
     if (mImpl->mLocatorTopic)
@@ -363,6 +372,8 @@ void ServiceManagementImpl::unregister(const Ice::Current&)
      */
     lg(Info) << "Un-register " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
 
+    mImpl->mManagement->removeState(mImpl->mStateItem, 0, 0);
+
     mImpl->mAdapter->remove(mImpl->mManagementPrx->ice_getIdentity());
 
     mImpl->mManagement->removeService(this);
diff --git a/src/ServiceManagement.h b/src/ServiceManagement.h
index 24236c1..ecd3e5c 100644
--- a/src/ServiceManagement.h
+++ b/src/ServiceManagement.h
@@ -33,7 +33,7 @@ class ServiceManagementImplPriv;
 class ServiceManagementImpl : public AsteriskSCF::Core::Discovery::V1::ServiceManagement
 {
 public:
-    ServiceManagementImpl(ServiceLocatorManagementImpl*, const Ice::ObjectPrx&, const Ice::ObjectAdapterPtr&,
+    ServiceManagementImpl(ServiceLocatorManagementImplPtr, const Ice::ObjectPrx&, const Ice::ObjectAdapterPtr&,
         const AsteriskSCF::System::Discovery::EventsPrx&, const std::string&);
 
     //

commit 5bfc3333e8192b5ebba8b7fd83328d955661bcb4
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Dec 15 14:03:41 2010 -0400

    Add listener implementation for service locator replication.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c69f2e1..159fd8f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,6 +15,7 @@ asterisk_scf_component_init(service_locator CXX)
 asterisk_scf_component_add_slice(service_locator ServiceLocatorIf)
 asterisk_scf_component_add_slice(service_locator ServiceLocatorEventsIf)
 asterisk_scf_component_add_slice(service_locator ServiceLocatorStateReplicationIf)
+asterisk_scf_component_add_slice(service_locator ComponentServiceIf)
 
 asterisk_scf_component_add_file(service_locator ServiceLocator.cpp)
 asterisk_scf_component_add_file(service_locator ServiceLocatorManagement.cpp)
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 0261939..4607d14 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -71,6 +71,10 @@ public:
         const AsteriskSCF::Core::Discovery::V1::AMD_ServiceLocator_locateAllPtr&,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&);
 
+    // Replication related functions.
+    ServiceManagementImplPtr addService(const Ice::ObjectPrx&, const std::string&, const
+        Ice::Identity&);
+
     //
     // AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagement interface.
     //
@@ -96,5 +100,10 @@ private:
     boost::shared_ptr<ServiceLocatorManagementImplPriv> mImpl;
 };
 
+/**
+ * A typedef which creates a smart pointer type for ServiceLocatorManagementImpl.
+ */
+typedef IceUtil::Handle<ServiceLocatorManagementImpl> ServiceLocatorManagementImplPtr;
+
 } /* end of ServiceDiscovery */
 } /* end of AsteriskSCF */
diff --git a/src/ServiceLocatorStateListener.cpp b/src/ServiceLocatorStateListener.cpp
index 4753f48..e6bb3fd 100644
--- a/src/ServiceLocatorStateListener.cpp
+++ b/src/ServiceLocatorStateListener.cpp
@@ -22,25 +22,70 @@
 #include "ReplicaIf.h"
 #include "SmartProxy.h"
 
+#include "Core/Discovery/ServiceLocatorIf.h"
+#include "Core/Discovery/ServiceLocatorEventsIf.h"
+
+#include "ServiceLocatorManagement.h"
+#include "ServiceManagement.h"
+
 #include "ServiceLocatorStateReplicator.h"
 
 using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::ServiceDiscovery;
 
 class ServiceLocatorStateReplicatorItem
 {
 public:
-    ServiceLocatorStateReplicatorItem() { }
+    ServiceLocatorStateReplicatorItem(ServiceLocatorManagementImplPtr locatorManagement) : mLocatorManagement(locatorManagement) { }
     ~ServiceLocatorStateReplicatorItem()
     {
+	Ice::Current current;
+	if (mService)
+	{
+	    mService->unregister(current);
+	}
+	if (!mComparator.empty())
+	{
+	    mLocatorManagement->removeCompare(mComparator, current);
+	}
     }
+
+    /**
+     * Helper function which sets the service.
+     */
+    void setService(ServiceManagementImplPtr service) { mService = service; };
+
+    /**
+     * Helper function which sets the comparator.
+     */
+    void setComparator(std::string name) { mComparator = name; };
+
+    /**
+     * Helper function which gets the service.
+     */
+    ServiceManagementImplPtr getService() { return mService; };
 private:
+    /**
+     * Pointer to the locator management instance.
+     */
+    ServiceLocatorManagementImplPtr mLocatorManagement;
+
+    /**
+     * Pointer to the service.
+     */
+    ServiceManagementImplPtr mService;
+
+    /**
+     * Name of the comparator.
+     */
+    std::string mComparator;
 };
 
 struct ServiceLocatorStateReplicatorListenerImpl
 {
 public:
-    ServiceLocatorStateReplicatorListenerImpl(Ice::ObjectAdapterPtr adapter)
-        : mId(IceUtil::generateUUID()), mAdapter(adapter) {}
+    ServiceLocatorStateReplicatorListenerImpl(ServiceLocatorManagementImplPtr management)
+        : mId(IceUtil::generateUUID()), mLocatorManagement(management) {}
     void removeStateNoticeImpl(const Ice::StringSeq& itemKeys)
     {
         for (Ice::StringSeq::const_iterator key = itemKeys.begin(); key != itemKeys.end(); ++key)
@@ -53,15 +98,85 @@ public:
     {
         for (ServiceLocatorStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
         {
+	    ServiceLocatorServiceStateItemPtr serviceState;
+	    ServiceLocatorParamsStateItemPtr paramsState;
+	    ServiceLocatorComparatorStateItemPtr comparatorState;
+
+	    if ((serviceState = ServiceLocatorServiceStateItemPtr::dynamicCast((*item))))
+	    {
+		Ice::Current current;
+		std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> >::iterator i = mStateItems.find((*item)->key);
+	        boost::shared_ptr<ServiceLocatorStateReplicatorItem> localitem;
+
+		if ((i == mStateItems.end()))
+		{
+		    boost::shared_ptr<ServiceLocatorStateReplicatorItem> newitem(new ServiceLocatorStateReplicatorItem(mLocatorManagement));
+                    localitem = newitem;
+                    mStateItems.insert(std::make_pair((*item)->key, newitem));
+		    ServiceManagementImplPtr service = mLocatorManagement->addService(serviceState->mService, serviceState->mGuid, serviceState->mManagementIdentity);
+		    newitem->setService(service);
+		}
+		else
+		{
+		    localitem = i->second;
+		}
+
+		// The only thing that can be changed by a subsequent state item is the suspend status
+		if (serviceState->mSuspended == true)
+		{
+		    localitem->getService()->suspend(current);
+		}
+		else
+		{
+		    localitem->getService()->unsuspend(current);
+		}
+	    }
+	    else if ((paramsState = ServiceLocatorParamsStateItemPtr::dynamicCast((*item))))
+	    {
+		// This is special, we have to find the respective service and then add parameters to it
+		std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> >::iterator i = mStateItems.find(paramsState->mServiceKey);
+
+	        if ((i == mStateItems.end()))
+		{
+		    continue;
+		}
+
+		// Parameters are only ever added, they are never modified or removed
+		Ice::Current current;
+		i->second->getService()->addLocatorParams(paramsState->mParams, paramsState->mCompareGuid, current);
+	    }
+	    else if ((comparatorState = ServiceLocatorComparatorStateItemPtr::dynamicCast((*item))))
+	    {
+		std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> >::iterator i = mStateItems.find((*item)->key);
+
+                if ((i != mStateItems.end()))
+		{
+		    // If this happens we essentially got a duplicate state item for something that should never change, so ignore it
+		    continue;
+		}
+
+		try
+		{
+		    Ice::Current current;
+		    mLocatorManagement->addCompare(comparatorState->mName, comparatorState->mService, current);
+		    boost::shared_ptr<ServiceLocatorStateReplicatorItem> newitem(new ServiceLocatorStateReplicatorItem(mLocatorManagement));
+		    mStateItems.insert(std::make_pair((*item)->key, newitem));
+		    newitem->setComparator(comparatorState->mName);
+		}
+		catch (...)
+		{
+		    // It is possible for this to get reached if a comparator exists locally with the same name as the one we just tried to add
+		}
+	    }
         }
     }
     std::string mId;
     std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> > mStateItems;
-    Ice::ObjectAdapterPtr mAdapter;
+    ServiceLocatorManagementImplPtr mLocatorManagement;
 };
 
-ServiceLocatorStateReplicatorListenerI::ServiceLocatorStateReplicatorListenerI(Ice::ObjectAdapterPtr adapter)
-    : mImpl(new ServiceLocatorStateReplicatorListenerImpl(adapter)) {}
+ServiceLocatorStateReplicatorListenerI::ServiceLocatorStateReplicatorListenerI(ServiceLocatorManagementImplPtr management)
+    : mImpl(new ServiceLocatorStateReplicatorListenerImpl(management)) {}
 
 ServiceLocatorStateReplicatorListenerI::~ServiceLocatorStateReplicatorListenerI()
 {
diff --git a/src/ServiceLocatorStateReplicator.h b/src/ServiceLocatorStateReplicator.h
index 02579f9..dfaf388 100644
--- a/src/ServiceLocatorStateReplicator.h
+++ b/src/ServiceLocatorStateReplicator.h
@@ -17,7 +17,11 @@
 #pragma once
 
 #include <Ice/Ice.h>
+#include "Core/Discovery/ServiceLocatorIf.h"
+#include "Core/Discovery/ServiceLocatorEventsIf.h"
 #include "ServiceLocatorStateReplicationIf.h"
+#include "ServiceLocatorManagement.h"
+#include "ServiceManagement.h"
 #include "StateReplicator.h"
 
 using namespace AsteriskSCF::Core::Discovery::V1;
@@ -28,7 +32,7 @@ typedef IceUtil::Handle<ServiceLocatorStateReplicatorI> ServiceLocatorStateRepli
 class ServiceLocatorStateReplicatorListenerI : public ServiceLocatorStateReplicatorListener
 {
 public:
-    ServiceLocatorStateReplicatorListenerI(Ice::ObjectAdapterPtr);
+    ServiceLocatorStateReplicatorListenerI(AsteriskSCF::ServiceDiscovery::ServiceLocatorManagementImplPtr);
     ~ServiceLocatorStateReplicatorListenerI();
     void stateRemoved(const Ice::StringSeq&, const Ice::Current&);
     void stateSet(const ServiceLocatorStateItemSeq&, const Ice::Current&);

commit 97a07d6bc5d0b0b822328138ce30bfcbc714673b
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Dec 15 10:16:51 2010 -0400

    Add skeleton listener.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2c6f010..c69f2e1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,6 +24,7 @@ asterisk_scf_component_add_file(service_locator CollocatedIceStorm.h)
 asterisk_scf_component_add_file(service_locator ServiceManagement.h)
 asterisk_scf_component_add_file(service_locator ServiceLocatorManagement.h)
 asterisk_scf_component_add_file(service_locator ServiceLocatorStateReplicator.h)
+asterisk_scf_component_add_file(service_locator ServiceLocatorStateListener.cpp)
 
 asterisk_scf_component_add_ice_libraries(service_locator IceStorm)
 asterisk_scf_component_add_ice_libraries(service_locator IceBox)
diff --git a/src/ServiceLocatorStateListener.cpp b/src/ServiceLocatorStateListener.cpp
new file mode 100644
index 0000000..4753f48
--- /dev/null
+++ b/src/ServiceLocatorStateListener.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 <IceUtil/UUID.h>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include "ReplicaIf.h"
+#include "SmartProxy.h"
+
+#include "ServiceLocatorStateReplicator.h"
+
+using namespace AsteriskSCF::Core::Discovery::V1;
+
+class ServiceLocatorStateReplicatorItem
+{
+public:
+    ServiceLocatorStateReplicatorItem() { }
+    ~ServiceLocatorStateReplicatorItem()
+    {
+    }
+private:
+};
+
+struct ServiceLocatorStateReplicatorListenerImpl
+{
+public:
+    ServiceLocatorStateReplicatorListenerImpl(Ice::ObjectAdapterPtr adapter)
+        : mId(IceUtil::generateUUID()), mAdapter(adapter) {}
+    void removeStateNoticeImpl(const Ice::StringSeq& itemKeys)
+    {
+        for (Ice::StringSeq::const_iterator key = itemKeys.begin(); key != itemKeys.end(); ++key)
+        {
+            // Just erasing this from the map will cause the destructor to actually shut things down
+            mStateItems.erase((*key));
+        }
+    }
+    void setStateNoticeImpl(const ServiceLocatorStateItemSeq& items)
+    {
+        for (ServiceLocatorStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+        {
+        }
+    }
+    std::string mId;
+    std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> > mStateItems;
+    Ice::ObjectAdapterPtr mAdapter;
+};
+
+ServiceLocatorStateReplicatorListenerI::ServiceLocatorStateReplicatorListenerI(Ice::ObjectAdapterPtr adapter)
+    : mImpl(new ServiceLocatorStateReplicatorListenerImpl(adapter)) {}
+
+ServiceLocatorStateReplicatorListenerI::~ServiceLocatorStateReplicatorListenerI()
+{
+    delete mImpl;
+}
+
+void ServiceLocatorStateReplicatorListenerI::stateRemoved(const Ice::StringSeq& itemKeys, const Ice::Current&)
+{
+    mImpl->removeStateNoticeImpl(itemKeys);
+}
+
+void ServiceLocatorStateReplicatorListenerI::stateSet(const ServiceLocatorStateItemSeq& items, const Ice::Current&)
+{
+    mImpl->setStateNoticeImpl(items);
+}
+
+bool ServiceLocatorStateReplicatorListenerI::operator==(ServiceLocatorStateReplicatorListenerI &rhs)
+{
+    return mImpl->mId == rhs.mImpl->mId;
+}

commit 0b7b92b6e857949b41554c1871e50cbf1401391f
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Dec 15 10:08:53 2010 -0400

    Add state replicator component.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ff63831..2c6f010 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,9 @@
 # All rights reserved.
 #
 
+include_directories(${utils_dir}/StateReplicator/src)
+include_directories(${utils_dir}/SmartProxy/src)
+
 # Create the actual standalone service locator component
 asterisk_scf_component_init(service_locator CXX)
 
@@ -20,6 +23,7 @@ asterisk_scf_component_add_file(service_locator CollocatedIceStorm.cpp)
 asterisk_scf_component_add_file(service_locator CollocatedIceStorm.h)
 asterisk_scf_component_add_file(service_locator ServiceManagement.h)
 asterisk_scf_component_add_file(service_locator ServiceLocatorManagement.h)
+asterisk_scf_component_add_file(service_locator ServiceLocatorStateReplicator.h)
 
 asterisk_scf_component_add_ice_libraries(service_locator IceStorm)
 asterisk_scf_component_add_ice_libraries(service_locator IceBox)
@@ -35,3 +39,19 @@ include_directories(${logger_dir}/client/src)
 asterisk_scf_component_build_icebox(service_locator)
 target_link_libraries(service_locator logging-client)
 #asterisk_scf_component_install(service_locator RUNTIME bin "Service Locator." Core)
+
+asterisk_scf_component_init(ServiceLocatorStateReplicator CXX)
+
+asterisk_scf_component_add_slice(ServiceLocatorStateReplicator ServiceLocatorIf)
+asterisk_scf_component_add_slice(ServiceLocatorStateReplicator ComponentServiceIf)
+asterisk_scf_component_add_slice(ServiceLocatorStateReplicator ServiceLocatorStateReplicationIf)
+
+asterisk_scf_component_add_file(ServiceLocatorStateReplicator ServiceLocatorStateReplicatorApp.cpp)
+asterisk_scf_component_add_file(ServiceLocatorStateReplicator ServiceLocatorStateReplicator.h)
+
+asterisk_scf_component_add_ice_libraries(ServiceLocatorStateReplicator IceStorm)
+
+asterisk_scf_component_add_boost_libraries(ServiceLocatorStateReplicator thread date_time)
+
+asterisk_scf_component_build_icebox(ServiceLocatorStateReplicator)
+target_link_libraries(ServiceLocatorStateReplicator logging-client)
diff --git a/src/ServiceLocatorStateReplicator.h b/src/ServiceLocatorStateReplicator.h
new file mode 100644
index 0000000..02579f9
--- /dev/null
+++ b/src/ServiceLocatorStateReplicator.h
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+#include "ServiceLocatorStateReplicationIf.h"
+#include "StateReplicator.h"
+
+using namespace AsteriskSCF::Core::Discovery::V1;
+
+typedef AsteriskSCF::StateReplication::StateReplicator<ServiceLocatorStateReplicator, ServiceLocatorStateItemPtr, std::string, ServiceLocatorStateReplicatorListenerPrx> ServiceLocatorStateReplicatorI;
+typedef IceUtil::Handle<ServiceLocatorStateReplicatorI> ServiceLocatorStateReplicatorIPtr;
+
+class ServiceLocatorStateReplicatorListenerI : public ServiceLocatorStateReplicatorListener
+{
+public:
+    ServiceLocatorStateReplicatorListenerI(Ice::ObjectAdapterPtr);
+    ~ServiceLocatorStateReplicatorListenerI();
+    void stateRemoved(const Ice::StringSeq&, const Ice::Current&);
+    void stateSet(const ServiceLocatorStateItemSeq&, const Ice::Current&);
+    bool operator==(ServiceLocatorStateReplicatorListenerI &rhs);
+private:
+    struct ServiceLocatorStateReplicatorListenerImpl *mImpl;
+};
diff --git a/src/ServiceLocatorStateReplicatorApp.cpp b/src/ServiceLocatorStateReplicatorApp.cpp
new file mode 100644
index 0000000..c125aa2
--- /dev/null
+++ b/src/ServiceLocatorStateReplicatorApp.cpp
@@ -0,0 +1,129 @@
+/*
+ * 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 <pjlib.h>
+
+#include "ServiceLocatorIf.h"
+#include "ComponentServiceIf.h"
+#include "ServiceLocatorStateReplicator.h"
+#include "IceLogger.h"
+#include "logger.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;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
+}
+
+class ServiceLocatorStateReplicatorService : public IceBox::Service
+{
+public:
+    ServiceLocatorStateReplicatorService() { };
+    ~ServiceLocatorStateReplicatorService()
+    {
+        mComponentService = 0;
+        mAdapter = 0;
+        mStateReplicator = 0;
+    };
+    virtual void start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
+    virtual void stop();
+private:
+    void initialize(std::string appName, const Ice::CommunicatorPtr& ic);
+    std::string mAppName;
+    Ice::ObjectAdapterPtr mAdapter;
+    ConfiguredIceLoggerPtr mIceLogger;
+    ComponentServicePtr mComponentService;
+    ServiceLocatorStateReplicatorIPtr mStateReplicator;
+};
+
+static const string ComponentServiceId("ServiceLocatorStateReplicatorComponent");
+static const string ServiceDiscoveryId("ServiceLocatorStateReplicatorService");
+
+/**
+ * This class provides implementation for the ComponentService interface, which
+ * every Asterisk SCF component is expected to publish.
+ */
+class ComponentServiceImpl : public ComponentService
+{
+public:
+    ComponentServiceImpl(ServiceLocatorStateReplicatorService &service) : mService(service) {}
+
+public: // Overrides of the ComponentService interface.
+    virtual void suspend(const ::Ice::Current& = ::Ice::Current())
+    {
+        // TBD
+    }
+
+    virtual void resume(const ::Ice::Current& = ::Ice::Current())
+    {
+        // TBD
+    }
+
+    virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
+    {
+        // TBD
+    }
+
+private:
+    ServiceLocatorStateReplicatorService& mService;
+};
+
+void ServiceLocatorStateReplicatorService::initialize(const std::string appName, const Ice::CommunicatorPtr& ic)
+{
+    mAdapter = ic->createObjectAdapter("ServiceLocatorStateReplicator");
+
+    // setup logging client
+    mIceLogger = createIceLogger(mAdapter);
+    getLoggerFactory().setLogOutput(mIceLogger->getLogger());
+
+    mAppName = appName;
+
+    // Create and publish our ComponentService interface support.
+    mComponentService = new ComponentServiceImpl(*this);
+    mAdapter->add(mComponentService, ic->stringToIdentity(ComponentServiceId));
+    mStateReplicator = new ServiceLocatorStateReplicatorI();
+    mAdapter->add(mStateReplicator, ic->stringToIdentity(ServiceDiscoveryId));
+
+    mAdapter->activate();
+}
+
+void ServiceLocatorStateReplicatorService::start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args)
+{
+    initialize(name, ic);
+}
+
+void ServiceLocatorStateReplicatorService::stop()
+{
+}
+
+extern "C"
+{
+ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr communicator)
+{
+    return new ServiceLocatorStateReplicatorService;
+}
+}
+

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


-- 
asterisk-scf/integration/servicediscovery.git



More information about the asterisk-scf-commits mailing list