[asterisk-scf-commits] asterisk-scf/integration/serivcediscovery.git branch "replication" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Sat Jan 22 16:34:03 CST 2011
branch "replication" has been created
at ff624894aeafc47341f8fae905e2b1bab1dad896 (commit)
- Log -----------------------------------------------------------------
commit ff624894aeafc47341f8fae905e2b1bab1dad896
Author: Joshua Colp <jcolp at digium.com>
Date: Sat Jan 22 18:31:12 2011 -0400
Pass by const reference.
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 9824dc8..6faf19a 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -584,7 +584,7 @@ void ServiceLocatorManagementImpl::removeService(
/**
* Function which replicates state items.
*/
-void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr item)
+void ServiceLocatorManagementImpl::replicateState(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr& item)
{
if (!item)
{
@@ -614,7 +614,7 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
/**
* Function which removes state items from the replicator.
*/
-void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr item)
+void ServiceLocatorManagementImpl::removeState(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr& item)
{
if (!item)
{
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index f755522..2251ad5 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -79,8 +79,8 @@ public:
// Replication related functions.
ServiceManagementImplPtr addService(const Ice::ObjectPrx&, const std::string&, const
Ice::Identity&);
- void replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr);
- void removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr);
+ void replicateState(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr&);
+ void removeState(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr&);
void setStateReplicator(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateReplicatorPrx);
//
commit cf9aafe7ee4ce2e16e2088a11336cbee2c3c9094
Author: Joshua Colp <jcolp at digium.com>
Date: Sat Jan 22 18:29:05 2011 -0400
Bring up to date.
diff --git a/local-slice/CMakeLists.txt b/local-slice/CMakeLists.txt
deleted file mode 100644
index 94e9d7d..0000000
--- a/local-slice/CMakeLists.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-asterisk_scf_slice_include_directories("${CMAKE_SOURCE_DIR}/slice")
-asterisk_scf_compile_slice(ServiceLocatorStateReplicationIf.ice lib "Service Locator State Replicator" service_locator)
-
diff --git a/local-slice/ServiceLocatorStateReplicationIf.ice b/local-slice/ServiceLocatorStateReplicationIf.ice
index abb8e12..c0fc4e2 100644
--- a/local-slice/ServiceLocatorStateReplicationIf.ice
+++ b/local-slice/ServiceLocatorStateReplicationIf.ice
@@ -18,7 +18,7 @@
#include <Ice/BuiltinSequences.ice>
#include <Ice/Identity.ice>
-#include "Core/Discovery/ServiceLocatorIf.ice"
+#include "AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice"
module AsteriskSCF
{
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cfb1435..845b9fa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,6 +8,13 @@
include_directories(${utils_dir}/StateReplicator/src)
include_directories(${utils_dir}/SmartProxy/src)
+include_directories(${utils_dir}/StateReplicator/include)
+include_directories(${utils_dir}/SmartProxy/include)
+include_directories(${utils_dir}/AmiCollector/include)
+include_directories(${logger_dir}/include)
+include_directories(${API_INCLUDE_DIR})
+
+asterisk_scf_slice_include_directories(${API_SLICE_DIR})
# Create the actual standalone service locator component
asterisk_scf_component_init(service_locator CXX)
@@ -32,15 +39,10 @@ asterisk_scf_component_add_boost_libraries(service_locator core thread date_time
if(NOT logger_dir)
message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
endif()
-include_directories(${utils_dir}/AmiCollector/include)
-include_directories(${logger_dir}/include)
-include_directories(${API_INCLUDE_DIR})
asterisk_scf_component_build_icebox(service_locator)
target_link_libraries(service_locator logging-client)
-asterisk_scf_component_install(service_locator)
-
asterisk_scf_component_init(ServiceLocatorStateReplicator CXX)
asterisk_scf_component_add_slice(ServiceLocatorStateReplicator ../local-slice/ServiceLocatorStateReplicationIf.ice)
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 1a3c4d1..9824dc8 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -45,10 +45,9 @@ namespace ServiceLocatorManagementImplNS
const Logger& lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
-<<<<<<< HEAD
/** Parameter type for Locator, to allow use of ResponseCollector. */
typedef std::pair<bool, ServiceManagementImplPtr> LocateParam;
-=======
+
/**
* Callback class for isSupported AMI calls. Acts as a bridge between
* Ice callbacks and IsSupportedCallback.
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 168fae9..f755522 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -20,7 +20,7 @@
#include <IceUtil/Shared.h>
-#include "System/Component/ReplicaIf.h"
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
#include "ServiceLocatorStateReplicationIf.h"
diff --git a/src/ServiceLocatorStateListener.cpp b/src/ServiceLocatorStateListener.cpp
index 1018ad4..d4df1e5 100644
--- a/src/ServiceLocatorStateListener.cpp
+++ b/src/ServiceLocatorStateListener.cpp
@@ -19,11 +19,11 @@
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
-#include "ReplicaIf.h"
-#include "SmartProxy.h"
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
+#include <AsteriskSCF/SmartProxy.h>
-#include "Core/Discovery/ServiceLocatorIf.h"
-#include "Core/Discovery/ServiceLocatorEventsIf.h"
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
diff --git a/src/ServiceLocatorStateReplicator.h b/src/ServiceLocatorStateReplicator.h
index dfaf388..0dea777 100644
--- a/src/ServiceLocatorStateReplicator.h
+++ b/src/ServiceLocatorStateReplicator.h
@@ -17,12 +17,12 @@
#pragma once
#include <Ice/Ice.h>
-#include "Core/Discovery/ServiceLocatorIf.h"
-#include "Core/Discovery/ServiceLocatorEventsIf.h"
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
#include "ServiceLocatorStateReplicationIf.h"
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
-#include "StateReplicator.h"
+#include <AsteriskSCF/StateReplicator.h>
using namespace AsteriskSCF::Core::Discovery::V1;
diff --git a/src/ServiceLocatorStateReplicatorApp.cpp b/src/ServiceLocatorStateReplicatorApp.cpp
index c125aa2..d9a3957 100644
--- a/src/ServiceLocatorStateReplicatorApp.cpp
+++ b/src/ServiceLocatorStateReplicatorApp.cpp
@@ -21,11 +21,13 @@
#include <pjlib.h>
-#include "ServiceLocatorIf.h"
-#include "ComponentServiceIf.h"
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+
#include "ServiceLocatorStateReplicator.h"
-#include "IceLogger.h"
-#include "logger.h"
+
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Logger/IceLogger.h>
using namespace std;
using namespace AsteriskSCF::Core;
commit de5e1dd281554f4c0f4c700e8fd0eac80690042c
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:55:23 2011 -0400
Provide a default value for Ice::Current in the declaration so one does not need to be created before using it elsewhere.
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 98ca5e7..168fae9 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -95,7 +95,7 @@ public:
void addCompare(const std::string&,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsComparePrx&,
const Ice::Current&);
- void removeCompare(const std::string&, const Ice::Current&);
+ void removeCompare(const std::string&, const Ice::Current& = Ice::Current());
void isSupported(const std::string&,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&,
diff --git a/src/ServiceLocatorStateListener.cpp b/src/ServiceLocatorStateListener.cpp
index 38d79dd..1018ad4 100644
--- a/src/ServiceLocatorStateListener.cpp
+++ b/src/ServiceLocatorStateListener.cpp
@@ -36,17 +36,18 @@ using namespace AsteriskSCF::ServiceDiscovery;
class ServiceLocatorStateReplicatorItem
{
public:
- ServiceLocatorStateReplicatorItem(ServiceLocatorManagementImplPtr locatorManagement) : mLocatorManagement(locatorManagement) { }
+ ServiceLocatorStateReplicatorItem(ServiceLocatorManagementImplPtr locatorManagement) :
+ mLocatorManagement(locatorManagement) { }
+
~ServiceLocatorStateReplicatorItem()
{
- Ice::Current current;
if (mService)
{
- mService->unregister(current);
+ mService->unregister();
}
if (!mComparator.empty())
{
- mLocatorManagement->removeCompare(mComparator, current);
+ mLocatorManagement->removeCompare(mComparator);
}
}
@@ -104,7 +105,6 @@ public:
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;
@@ -124,11 +124,11 @@ public:
// The only thing that can be changed by a subsequent state item is the suspend status
if (serviceState->suspended == true)
{
- localitem->getService()->suspend(current);
+ localitem->getService()->suspend();
}
else
{
- localitem->getService()->unsuspend(current);
+ localitem->getService()->unsuspend();
}
}
else if ((paramsState = ServiceLocatorParamsStateItemPtr::dynamicCast((*item))))
@@ -142,8 +142,7 @@ public:
}
// Parameters are only ever added, they are never modified or removed
- Ice::Current current;
- i->second->getService()->addLocatorParams(paramsState->params, paramsState->compareGuid, current);
+ i->second->getService()->addLocatorParams(paramsState->params, paramsState->compareGuid);
}
else if ((comparatorState = ServiceLocatorComparatorStateItemPtr::dynamicCast((*item))))
{
diff --git a/src/ServiceManagement.h b/src/ServiceManagement.h
index 14b5b13..66fd43f 100644
--- a/src/ServiceManagement.h
+++ b/src/ServiceManagement.h
@@ -39,10 +39,10 @@ public:
//
// AsteriskSCF::Core::Discovery::V1::ServiceManagement interface.
//
- void addLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const std::string&, const Ice::Current&);
- void suspend(const Ice::Current&);
- void unsuspend(const Ice::Current&);
- void unregister(const Ice::Current&);
+ void addLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const std::string&, const Ice::Current& = Ice::Current());
+ void suspend(const Ice::Current& = Ice::Current());
+ void unsuspend(const Ice::Current& = Ice::Current());
+ void unregister(const Ice::Current& = Ice::Current());
AsteriskSCF::Core::Discovery::V1::ServiceStatus getStatus(const Ice::Current&) const { return getStatus(); }
Ice::ObjectPrx getService();
commit 17f568684d3cc135a0a899da6c9ce1b46bab79c2
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:42:26 2011 -0400
Add proper logging if a suitable proxy is not available for replication.
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index e07ed43..1a3c4d1 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -606,8 +606,9 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
ServiceLocatorStateReplicatorPrx oneway = ServiceLocatorStateReplicatorPrx::uncheckedCast(mImpl->mStateReplicator->ice_oneway());
oneway->setState(items);
}
- catch (...)
+ catch (const Ice::NoEndpointException&)
{
+ lg(Error) << "No endpoint for oneway invocation of replicateState() for state replication." << std::endl;
}
}
@@ -635,8 +636,9 @@ void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1:
ServiceLocatorStateReplicatorPrx oneway = ServiceLocatorStateReplicatorPrx::uncheckedCast(mImpl->mStateReplicator->ice_oneway());
oneway->removeState(items);
}
- catch (...)
+ catch (const Ice::NoEndpointException&)
{
+ lg(Error) << "No endpoint for oneway invocation of replicateState() for state replication." << std::endl;
}
}
commit 217983d502f1014ead662cb9c9be0d990488160e
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:35:33 2011 -0400
Since only one item is ever passed to replicateState and removeState simply make it accept the base class.
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index f6b436f..e07ed43 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -108,7 +108,7 @@ public:
mStateItem->key = IceUtil::generateUUID();
mStateItem->name = name;
mStateItem->comparator = compare;
- mManagement->replicateState(0, 0, mStateItem);
+ mManagement->replicateState(mStateItem);
}
/**
@@ -117,7 +117,7 @@ public:
*/
~ServiceLocatorComparator()
{
- mManagement->removeState(0, 0, mStateItem);
+ mManagement->removeState(mStateItem);
}
/**
@@ -585,10 +585,13 @@ void ServiceLocatorManagementImpl::removeService(
/**
* 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)
+void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr item)
{
+ if (!item)
+ {
+ return;
+ }
+
if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
{
return;
@@ -596,25 +599,7 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
ServiceLocatorStateItemSeq items;
- if (service)
- {
- items.push_back(service);
- }
-
- if (params)
- {
- items.push_back(params);
- }
-
- if (comparator)
- {
- items.push_back(comparator);
- }
-
- if (items.size() == 0)
- {
- return;
- }
+ items.push_back(item);
try
{
@@ -629,10 +614,13 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
/**
* 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)
+void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr item)
{
+ if (!item)
+ {
+ return;
+ }
+
if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
{
return;
@@ -640,25 +628,7 @@ void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1:
Ice::StringSeq items;
- if (service)
- {
- items.push_back(service->key);
- }
-
- if (params)
- {
- items.push_back(params->key);
- }
-
- if (comparator)
- {
- items.push_back(comparator->key);
- }
-
- if (items.size() == 0)
- {
- return;
- }
+ items.push_back(item->key);
try
{
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index b80aaec..98ca5e7 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -79,12 +79,8 @@ 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);
+ void replicateState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr);
+ void removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr);
void setStateReplicator(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateReplicatorPrx);
//
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 423796f..e959072 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -64,12 +64,12 @@ public:
mStateItem->serviceKey = serviceState->key;
mStateItem->params = params;
mStateItem->compareGuid = compareGuid;
- mManagement->replicateState(0, mStateItem, 0);
+ mManagement->replicateState(mStateItem);
}
~ServiceLocatorParamsSpec()
{
- mManagement->removeState(0, mStateItem, 0);
+ mManagement->removeState(mStateItem);
}
void isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const IsSupportedCallbackPtr&);
@@ -108,7 +108,7 @@ public:
{
mLocatorTopic->serviceRegistered(guid);
}
- mManagement->replicateState(mStateItem, 0, 0);
+ mManagement->replicateState(mStateItem);
}
/**
@@ -325,7 +325,7 @@ void ServiceManagementImpl::suspend(const Ice::Current&)
{
lg(Info) << "Suspending " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
mImpl->mStateItem->suspended = true;
- mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
+ mImpl->mManagement->replicateState(mImpl->mStateItem);
}
if (mImpl->mLocatorTopic)
@@ -345,7 +345,7 @@ void ServiceManagementImpl::unsuspend(const Ice::Current&)
{
lg(Info) << "Un-suspending " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
mImpl->mStateItem->suspended = false;
- mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
+ mImpl->mManagement->replicateState(mImpl->mStateItem);
}
if (mImpl->mLocatorTopic)
@@ -377,7 +377,7 @@ void ServiceManagementImpl::unregister(const Ice::Current&)
*/
lg(Info) << "Un-register " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
- mImpl->mManagement->removeState(mImpl->mStateItem, 0, 0);
+ mImpl->mManagement->removeState(mImpl->mStateItem);
mImpl->mAdapter->remove(mImpl->mManagementPrx->ice_getIdentity());
commit 0a76aef56e08a1c4a5be2ab07be3b4a4c1671309
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:28:21 2011 -0400
If we can't talk to the state replicator for some reason give more detail on why not if an exception is thrown.
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index e050473..d2e787e 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -258,6 +258,10 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
lg(Info) << "Operating in an active state and pushing updates." << endl;
}
}
+ catch (const std::exception& e)
+ {
+ lg(Info) << "Operating in an active and standalone state since we got an exception: " << e.what() << endl;
+ }
catch (...)
{
// If we reach this point then no state replicator is present and we are acting in a stand-alone fashion
commit 56102bd97d95b4df46d6aa4f339fd02841ed6a19
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:23:32 2011 -0400
Don't prefix local variables with m, since they aren't member variables.
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index b09ebe2..e050473 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -242,15 +242,15 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
try
{
mStateReplicator = ServiceLocatorStateReplicatorPrx::checkedCast(communicator->propertyToProxy("ServiceLocator.StateReplicator.Proxy"));
- ServiceLocatorStateReplicatorListenerPtr mReplicatorListener = new ServiceLocatorStateReplicatorListenerI(locatorServiceManagement);
- ServiceLocatorStateReplicatorListenerPrx mReplicatorListenerProxy = ServiceLocatorStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
+ ServiceLocatorStateReplicatorListenerPtr replicatorListener = new ServiceLocatorStateReplicatorListenerI(locatorServiceManagement);
+ ServiceLocatorStateReplicatorListenerPrx replicatorListenerProxy = ServiceLocatorStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(replicatorListener));
locatorServiceManagement->setStateReplicator(mStateReplicator);
if (communicator->getProperties()->getPropertyWithDefault("ServiceLocatorStateReplicatorListener", "no") == "yes")
{
mReplicaService->standby();
- mStateReplicator->addListener(mReplicatorListenerProxy);
+ mStateReplicator->addListener(replicatorListenerProxy);
lg(Info) << "Operating as a standby replica." << endl;
}
else
commit b6b0ce00c03de1ff94dcc695ed7433922a134c0d
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:22:08 2011 -0400
Get rid of the logger adapter in favor of the local adapter.
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index 93dae6f..b09ebe2 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -56,7 +56,6 @@ private:
Ice::ObjectAdapterPtr mLocalAdapter;
Ice::ObjectAdapterPtr mDiscoveryAdapter;
Ice::ObjectAdapterPtr mManagementAdapter;
- Ice::ObjectAdapterPtr mLoggerAdapter;
AsteriskSCF::ServiceDiscovery::CollocatedIceStormPtr mIceStorm;
ReplicaPtr mReplicaService;
ServiceLocatorStateReplicatorPrx mStateReplicator;
@@ -169,13 +168,13 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
{
mIceStorm = new AsteriskSCF::ServiceDiscovery::CollocatedIceStorm("AsteriskSCFIceStorm", communicator->getProperties());
- mLoggerAdapter = communicator->createObjectAdapter("LoggerAdapter");
+ mLocalAdapter = communicator->createObjectAdapter("ServiceLocatorLocalAdapter");
- ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mLoggerAdapter);
+ ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mLocalAdapter);
getLoggerFactory().setLogOutput(mIceLogger->getLogger());
- mLoggerAdapter->activate();
+ mLocalAdapter->activate();
lg(Info) << "Initializing service discovery component";
@@ -222,14 +221,9 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
lg(Info) << "IceStorm topic manager proxy not present, events disabled.";
}
- mLocalAdapter = communicator->createObjectAdapter(
- "ServiceLocatorLocalAdapter");
-
mReplicaService = new ReplicaImpl(mLocalAdapter);
mLocalAdapter->add(mReplicaService, communicator->stringToIdentity(ReplicaServiceId));
- mLocalAdapter->activate();
-
/* Management and discovery use separate adapters to provide a level of security,
* management may want to be protected so arbitrary people can't inject bad services
* into the infrastructure while discovery as a read only function may be allowed to all.
commit ba13a11dbecc46312e86aa1b8a7661cc6b20c086
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:20:36 2011 -0400
Constify the passing of the locator service management pointer.
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index c95aab3..93dae6f 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -123,7 +123,7 @@ private:
class ServiceLocatorImpl : public ServiceLocator
{
public:
- ServiceLocatorImpl(ServiceLocatorManagementImplPtr LocatorServiceManagement) :
+ ServiceLocatorImpl(const ServiceLocatorManagementImplPtr& LocatorServiceManagement) :
mLocatorServiceManagement(LocatorServiceManagement) { };
/**
* Asynchronously locate a service for the given parameters.
commit 7ec86d4e8eba33cbdb94bd768e725d0ffcb9db8f
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 3 09:17:59 2011 -0400
Don't prefix state items with m, and don't call a comparator proxy a service call it a comparator.
diff --git a/local-slice/ServiceLocatorStateReplicationIf.ice b/local-slice/ServiceLocatorStateReplicationIf.ice
index 7d4c71f..abb8e12 100644
--- a/local-slice/ServiceLocatorStateReplicationIf.ice
+++ b/local-slice/ServiceLocatorStateReplicationIf.ice
@@ -57,23 +57,23 @@ module V1
class ServiceLocatorServiceStateItem extends ServiceLocatorStateItem
{
- bool mSuspended;
- Object *mService;
- Ice::Identity mManagementIdentity;
- string mGuid;
+ bool suspended;
+ Object *service;
+ Ice::Identity managementIdentity;
+ string guid;
};
class ServiceLocatorParamsStateItem extends ServiceLocatorStateItem
{
- string mServiceKey;
- ServiceLocatorParams mParams;
- string mCompareGuid;
+ string serviceKey;
+ ServiceLocatorParams params;
+ string compareGuid;
};
class ServiceLocatorComparatorStateItem extends ServiceLocatorStateItem
{
- string mName;
- ServiceLocatorParamsCompare *mService;
+ string name;
+ ServiceLocatorParamsCompare *comparator;
};
}; //module V1
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index b6731c0..f6b436f 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -106,8 +106,8 @@ public:
mStateItem(new ServiceLocatorComparatorStateItem())
{
mStateItem->key = IceUtil::generateUUID();
- mStateItem->mName = name;
- mStateItem->mService = compare;
+ mStateItem->name = name;
+ mStateItem->comparator = compare;
mManagement->replicateState(0, 0, mStateItem);
}
@@ -137,7 +137,7 @@ public:
Ice::CallbackPtr d = Ice::newCallback(iceCallback,
&Comparator_IsSupported_Callback::finished);
// async forward to the comparator
- mStateItem->mService->begin_isSupported(params, d);
+ mStateItem->comparator->begin_isSupported(params, d);
}
private:
/**
diff --git a/src/ServiceLocatorStateListener.cpp b/src/ServiceLocatorStateListener.cpp
index e6bb3fd..38d79dd 100644
--- a/src/ServiceLocatorStateListener.cpp
+++ b/src/ServiceLocatorStateListener.cpp
@@ -113,7 +113,7 @@ public:
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);
+ ServiceManagementImplPtr service = mLocatorManagement->addService(serviceState->service, serviceState->guid, serviceState->managementIdentity);
newitem->setService(service);
}
else
@@ -122,7 +122,7 @@ public:
}
// The only thing that can be changed by a subsequent state item is the suspend status
- if (serviceState->mSuspended == true)
+ if (serviceState->suspended == true)
{
localitem->getService()->suspend(current);
}
@@ -134,7 +134,7 @@ public:
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);
+ std::map<std::string, boost::shared_ptr<ServiceLocatorStateReplicatorItem> >::iterator i = mStateItems.find(paramsState->serviceKey);
if ((i == mStateItems.end()))
{
@@ -143,7 +143,7 @@ public:
// Parameters are only ever added, they are never modified or removed
Ice::Current current;
- i->second->getService()->addLocatorParams(paramsState->mParams, paramsState->mCompareGuid, current);
+ i->second->getService()->addLocatorParams(paramsState->params, paramsState->compareGuid, current);
}
else if ((comparatorState = ServiceLocatorComparatorStateItemPtr::dynamicCast((*item))))
{
@@ -158,10 +158,10 @@ public:
try
{
Ice::Current current;
- mLocatorManagement->addCompare(comparatorState->mName, comparatorState->mService, current);
+ mLocatorManagement->addCompare(comparatorState->name, comparatorState->comparator, current);
boost::shared_ptr<ServiceLocatorStateReplicatorItem> newitem(new ServiceLocatorStateReplicatorItem(mLocatorManagement));
mStateItems.insert(std::make_pair((*item)->key, newitem));
- newitem->setComparator(comparatorState->mName);
+ newitem->setComparator(comparatorState->name);
}
catch (...)
{
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 15ad1d2..423796f 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -61,9 +61,9 @@ public:
mManagement(management)
{
mStateItem->key = IceUtil::generateUUID();
- mStateItem->mServiceKey = serviceState->key;
- mStateItem->mParams = params;
- mStateItem->mCompareGuid = compareGuid;
+ mStateItem->serviceKey = serviceState->key;
+ mStateItem->params = params;
+ mStateItem->compareGuid = compareGuid;
mManagement->replicateState(0, mStateItem, 0);
}
@@ -99,11 +99,11 @@ public:
mManagement(management), mAdapter(adapter), mLocatorTopic(serviceDiscoveryTopic)
{
mStateItem->key = IceUtil::generateUUID();
- mStateItem->mSuspended = false;
- mStateItem->mService = service;
- mStateItem->mGuid = guid;
+ mStateItem->suspended = false;
+ mStateItem->service = service;
+ mStateItem->guid = guid;
mManagementPrx = ServiceManagementPrx::uncheckedCast(mAdapter->add(impl, identity));
- mStateItem->mManagementIdentity = identity;
+ mStateItem->managementIdentity = identity;
if (mLocatorTopic)
{
mLocatorTopic->serviceRegistered(guid);
@@ -169,7 +169,7 @@ ServiceManagementImpl::ServiceManagementImpl(ServiceLocatorManagementImplPtr man
*/
Ice::ObjectPrx ServiceManagementImpl::getService()
{
- return mImpl->mStateItem->mService;
+ return mImpl->mStateItem->service;
}
/**
@@ -245,7 +245,7 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
/* If this service is suspended we can just skip the entire check and
* return false now, easy as pie
*/
- if (mImpl->mStateItem->mSuspended)
+ if (mImpl->mStateItem->suspended)
{
callback->result(false);
return;
@@ -265,7 +265,7 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
const std::string& ServiceManagementImpl::getGuid() const
{
- return mImpl->mStateItem->mGuid;
+ return mImpl->mStateItem->guid;
}
/**
@@ -286,14 +286,14 @@ void ServiceLocatorParamsSpec::isSupported(const ServiceLocatorParamsPtr& params
}
/* This is just a simple comparison that acts as a preliminary, and
* perhaps final, check */
- else if (mStateItem->mParams->category != params->category)
+ else if (mStateItem->params->category != params->category)
{
callback->result(false);
}
/* If a comparator was provided then yield to it for a final yay or nay */
- else if (!mStateItem->mCompareGuid.empty())
+ else if (!mStateItem->compareGuid.empty())
{
- mManagement->isSupported(mStateItem->mCompareGuid, params, callback);
+ mManagement->isSupported(mStateItem->compareGuid, params, callback);
}
/* category matches, no comparator to turn us down. it's a match. */
else
@@ -321,16 +321,16 @@ void ServiceManagementImpl::suspend(const Ice::Current&)
{
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- if (!mImpl->mStateItem->mSuspended)
+ if (!mImpl->mStateItem->suspended)
{
- lg(Info) << "Suspending " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
- mImpl->mStateItem->mSuspended = true;
+ lg(Info) << "Suspending " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
+ mImpl->mStateItem->suspended = true;
mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
}
if (mImpl->mLocatorTopic)
{
- mImpl->mLocatorTopic->serviceSuspended(mImpl->mStateItem->mGuid);
+ mImpl->mLocatorTopic->serviceSuspended(mImpl->mStateItem->guid);
}
}
@@ -341,23 +341,23 @@ void ServiceManagementImpl::unsuspend(const Ice::Current&)
{
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- if (mImpl->mStateItem->mSuspended)
+ if (mImpl->mStateItem->suspended)
{
- lg(Info) << "Un-suspending " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
- mImpl->mStateItem->mSuspended = false;
+ lg(Info) << "Un-suspending " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
+ mImpl->mStateItem->suspended = false;
mImpl->mManagement->replicateState(mImpl->mStateItem, 0, 0);
}
if (mImpl->mLocatorTopic)
{
- mImpl->mLocatorTopic->serviceUnsuspended(mImpl->mStateItem->mGuid);
+ mImpl->mLocatorTopic->serviceUnsuspended(mImpl->mStateItem->guid);
}
}
ServiceStatus ServiceManagementImpl::getStatus() const
{
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- if (mImpl->mStateItem->mSuspended)
+ if (mImpl->mStateItem->suspended)
{
return Suspended;
}
@@ -375,7 +375,7 @@ void ServiceManagementImpl::unregister(const Ice::Current&)
/* You'll notice no lock here. That's because we aren't actually modifying any internal state that should
* be protected, and if we did lock here there is a chance for a deadlock which is super sad.
*/
- lg(Info) << "Un-register " << mImpl->mStateItem->mGuid << " " << mImpl->mStateItem->mService->ice_toString();
+ lg(Info) << "Un-register " << mImpl->mStateItem->guid << " " << mImpl->mStateItem->service->ice_toString();
mImpl->mManagement->removeState(mImpl->mStateItem, 0, 0);
@@ -385,7 +385,7 @@ void ServiceManagementImpl::unregister(const Ice::Current&)
if (mImpl->mLocatorTopic)
{
- mImpl->mLocatorTopic->serviceUnregistered(mImpl->mStateItem->mGuid);
+ mImpl->mLocatorTopic->serviceUnregistered(mImpl->mStateItem->guid);
}
}
commit 477c1c3cd8c2d210bf9ece4fe3e036f2103f049d
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Dec 20 08:40:24 2010 -0400
Remove service locator details from service locator replication slice. The proxies have to be specified in the configuration.
diff --git a/local-slice/ServiceLocatorStateReplicationIf.ice b/local-slice/ServiceLocatorStateReplicationIf.ice
index c475cf8..7d4c71f 100644
--- a/local-slice/ServiceLocatorStateReplicationIf.ice
+++ b/local-slice/ServiceLocatorStateReplicationIf.ice
@@ -32,14 +32,6 @@ module Discovery
["suppress"]
module V1
{
- const string StateReplicatorComponentCategory = "ServiceLocatorStateReplicatorComponent";
- const string StateReplicatorDiscoveryCategory = "ServiceLocatorStateReplicator";
-
- class ServiceLocatorStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
- {
- string mName;
- };
-
class ServiceLocatorStateItem
{
string key;
commit 31fc6079aaac6fb3ea80f28a916cd132f39f9ebb
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Dec 19 10:01:31 2010 -0400
Be more descriptive in debug messages about why an isSupported call is true or false.
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 6a3a06c..15ad1d2 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -25,6 +25,7 @@
#include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
#include <AsteriskSCF/logger.h>
#include <AsteriskSCF/ResponseCollector.h>
+
#include "ServiceLocatorStateReplicationIf.h"
#include "ServiceLocatorManagement.h"
commit 3d627cd667afbf8068f1d5c0e79bae49100a9e3c
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Dec 19 10:00:54 2010 -0400
Use a boost::shared_ptr so the parameters state item does not get prematurely removed.
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 5aee875..6a3a06c 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -19,6 +19,7 @@
#include <boost/thread.hpp>
#include <boost/thread/shared_mutex.hpp>
+#include <boost/shared_ptr.hpp>
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
@@ -137,7 +138,7 @@ public:
/**
* A vector of locator parameters that this service supports.
*/
- std::vector<ServiceLocatorParamsSpec> mSupportedLocatorParams;
+ std::vector< boost::shared_ptr<ServiceLocatorParamsSpec> > mSupportedLocatorParams;
/**
* A proxy that can be used to publish events to the service locator topic.
@@ -252,12 +253,12 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
IsSupportedCallbackPtr myCallback = new CountedIsSupported(
callback, mImpl->mSupportedLocatorParams.size());
- for (vector<ServiceLocatorParamsSpec>::iterator
+ for (vector<boost::shared_ptr<ServiceLocatorParamsSpec>>::iterator
spec = mImpl->mSupportedLocatorParams.begin();
spec != mImpl->mSupportedLocatorParams.end();
++spec)
{
- spec->isSupported(params, myCallback);
+ (*spec)->isSupported(params, myCallback);
}
}
@@ -307,7 +308,7 @@ void ServiceManagementImpl::addLocatorParams(const ServiceLocatorParamsPtr& para
{
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- ServiceLocatorParamsSpec spec(params, compareGuid, mImpl->mManagement, mImpl->mStateItem);
+ boost::shared_ptr<ServiceLocatorParamsSpec> spec(new ServiceLocatorParamsSpec(params, compareGuid, mImpl->mManagement, mImpl->mStateItem));
mImpl->mSupportedLocatorParams.push_back(spec);
}
commit a70461aef030a392832c47473a180b99c12f4f8a
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Dec 19 09:54:19 2010 -0400
Pass the service state item into the parameters spec so the key can be copied.
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 606ed92..5aee875 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -52,12 +52,14 @@ class ServiceLocatorParamsSpec
public:
ServiceLocatorParamsSpec(const ServiceLocatorParamsPtr& params,
const std::string& compareGuid,
- ServiceLocatorManagementImplPtr management)
+ ServiceLocatorManagementImplPtr management,
+ ServiceLocatorServiceStateItemPtr serviceState)
:
mStateItem(new ServiceLocatorParamsStateItem()),
mManagement(management)
{
mStateItem->key = IceUtil::generateUUID();
+ mStateItem->mServiceKey = serviceState->key;
mStateItem->mParams = params;
mStateItem->mCompareGuid = compareGuid;
mManagement->replicateState(0, mStateItem, 0);
@@ -305,7 +307,7 @@ void ServiceManagementImpl::addLocatorParams(const ServiceLocatorParamsPtr& para
{
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- ServiceLocatorParamsSpec spec(params, compareGuid, mImpl->mManagement);
+ ServiceLocatorParamsSpec spec(params, compareGuid, mImpl->mManagement, mImpl->mStateItem);
mImpl->mSupportedLocatorParams.push_back(spec);
}
commit 9a4df50a091bd899aa504a355a093643bb50e5fb
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Dec 19 09:10:11 2010 -0400
Fix a race condition where it was possible for the service locator to think it was active, thus replicating to itself for a small period of time.
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index 645eb44..c95aab3 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -255,8 +255,8 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
if (communicator->getProperties()->getPropertyWithDefault("ServiceLocatorStateReplicatorListener", "no") == "yes")
{
+ mReplicaService->standby();
mStateReplicator->addListener(mReplicatorListenerProxy);
- mReplicaService->standby();
lg(Info) << "Operating as a standby replica." << endl;
}
else
commit 6c4599f0f6eeffa088890a9b07da648e2ea40f41
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Dec 19 09:09:31 2010 -0400
Update configuration files and add new ones for state replicator.
diff --git a/config/test_service_locator.config b/config/test_service_locator.config
index d058ee6..2ad533f 100644
--- a/config/test_service_locator.config
+++ b/config/test_service_locator.config
@@ -47,10 +47,17 @@ AsteriskSCFIceStorm.Flush.Timeout=2000
# Test endpoints for the service locator management adapter
ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+# Test endpoints for the service locator local adapter
+ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
+
# Test endpoints for the service locator adapter
ServiceLocatorAdapter.Endpoints=tcp -p 4411
LocatorService.Proxy=LocatorService:tcp -p 4411
+ServiceLocator.StateReplicator.Proxy=ServiceLocatorStateReplicatorService:tcp -p 4413
+
+ServiceLocatorStateReplicatorListener=no
+
# Test endpoints for IceStorm
TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
diff --git a/config/test_service_locator.config b/config/test_service_locator_listener.config
similarity index 86%
copy from config/test_service_locator.config
copy to config/test_service_locator_listener.config
index d058ee6..12f1482 100644
--- a/config/test_service_locator.config
+++ b/config/test_service_locator_listener.config
@@ -47,10 +47,17 @@ AsteriskSCFIceStorm.Flush.Timeout=2000
# Test endpoints for the service locator management adapter
ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+# Test endpoints for the service locator local adapter
+ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
+
# Test endpoints for the service locator adapter
ServiceLocatorAdapter.Endpoints=tcp -p 4411
LocatorService.Proxy=LocatorService:tcp -p 4411
+ServiceLocator.StateReplicator.Proxy=ServiceLocatorStateReplicatorService:tcp -p 4413
+
+ServiceLocatorStateReplicatorListener=yes
+
# Test endpoints for IceStorm
TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
diff --git a/config/test_servicelocator_state_replicator.conf b/config/test_servicelocator_state_replicator.conf
new file mode 100644
index 0000000..98a48d4
--- /dev/null
+++ b/config/test_servicelocator_state_replicator.conf
@@ -0,0 +1,11 @@
+# Adapter parameters for this component
+ServiceLocatorStateReplicator.Endpoints=tcp -p 4413:udp -p 4413
+ServiceLocatorStateReplicator.ThreadPool.Size=4
+
+# A proxy to the IceStorm topic manager
+TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
+
+LocatorService.Proxy=LocatorService:tcp -p 4411
+
+IceBox.InheritProperties=1
+IceBox.Service.ServiceLocatorStateReplicator=ServiceLocatorStateReplicator:create
commit 603ff050845e98a6a6e6e4a490333793ac4ec141
Author: Joshua Colp <jcolp at digium.com>
Date: Thu Dec 16 11:08:58 2010 -0400
Get the service locator talking to the state replicator and pushing out state items.
diff --git a/config/test_component.config.in b/config/test_component.config.in
index b793c27..6d13371 100644
--- a/config/test_component.config.in
+++ b/config/test_component.config.in
@@ -40,11 +40,20 @@ AsteriskSCFIceStorm.Trace.TopicManager=2
#
AsteriskSCFIceStorm.Flush.Timeout=2000
+# Service Locator State Replicator Configuration
+IceBox.Service.ServiceDiscoveryStateReplicator=../src at ServiceLocatorStateReplicator:create
+
+# Test endpoints for the state replicator
+ServiceLocatorStateReplicator.Endpoints=tcp -p 4413:udp -p 4413
+
#
# ServiceDiscovery configuration
#
IceBox.Service.ServiceDiscovery=../src at service_locator:create
+# Test endpoints for the service locator local adapter
+ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
+
# Test endpoints for the service locator management adapter
ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
@@ -54,6 +63,12 @@ ServiceLocatorAdapter.Endpoints=tcp -p 4411
# Test endpoints for IceStorm
TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
+# Proxy to the state replicator
+ServiceLocator.StateReplicator.Proxy=ServiceLocatorStateReplicatorService:tcp -p 4413
+
+# Configure ourselves as a master
+ServiceLocatorStateReplicatorListener=no
+
#
# Logger configuration
#
@@ -70,4 +85,4 @@ ServiceLocatorManagement.proxy=ServiceLocatorManagement:tcp -p 4422
#
# IceBox load order
#
-IceBox.LoadOrder=ServiceDiscovery,ServiceDiscoveryTest
+IceBox.LoadOrder=ServiceDiscoveryStateReplicator,ServiceDiscovery,ServiceDiscoveryTest
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index 9c4f70b..645eb44 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -25,6 +25,7 @@
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
+#include "ServiceLocatorStateReplicator.h"
#include "CollocatedIceStorm.h"
using namespace std;
@@ -32,11 +33,14 @@ using namespace AsteriskSCF::System::Discovery;
using namespace AsteriskSCF::System::Logging;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::ServiceDiscovery;
+using namespace AsteriskSCF::System::Component::V1;
namespace
{
Logger const &lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
+static const string ReplicaServiceId("ServiceLocatorReplica");
+
/**
* Implementation of the Ice::Application class
*/
@@ -49,10 +53,68 @@ public:
void stop();
private:
+ Ice::ObjectAdapterPtr mLocalAdapter;
Ice::ObjectAdapterPtr mDiscoveryAdapter;
Ice::ObjectAdapterPtr mManagementAdapter;
Ice::ObjectAdapterPtr mLoggerAdapter;
AsteriskSCF::ServiceDiscovery::CollocatedIceStormPtr mIceStorm;
+ ReplicaPtr mReplicaService;
+ ServiceLocatorStateReplicatorPrx mStateReplicator;
+};
+
+/**
+ * Implementation of the Replica interface.
+ */
+class ReplicaImpl : public Replica
+{
+public:
+ ReplicaImpl(Ice::ObjectAdapterPtr adapter) : mAdapter(adapter), mPaused(false), mActive(true) { }
+
+ bool isActive(const Ice::Current&)
+ {
+ return mActive;
+ }
+
+ bool activate(const Ice::Current&)
+ {
+ mActive = true;
+
+ for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); listener != mListeners.end(); ++listener)
+ {
+ (*listener)->activated(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
+ }
+
+ return true;
+ }
+
+ void standby(const Ice::Current&)
+ {
+ mActive = false;
+
+ for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); listener != mListeners.end(); ++listener)
+ {
+ (*listener)->onStandby(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
+ }
+ }
+
+ void addListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const Ice::Current&)
+ {
+ mListeners.push_back(listener);
+ }
+
+ void removeListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const Ice::Current&)
+ {
+ mListeners.erase(std::remove(mListeners.begin(), mListeners.end(), listener), mListeners.end());
+ }
+
+private:
+ Ice::ObjectAdapterPtr mAdapter;
+
+ vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx> mListeners;
+
+ bool mPaused;
+
+ bool mActive;
};
/**
@@ -61,7 +123,7 @@ private:
class ServiceLocatorImpl : public ServiceLocator
{
public:
- ServiceLocatorImpl(ServiceLocatorManagementImpl* LocatorServiceManagement) :
+ ServiceLocatorImpl(ServiceLocatorManagementImplPtr LocatorServiceManagement) :
mLocatorServiceManagement(LocatorServiceManagement) { };
/**
* Asynchronously locate a service for the given parameters.
@@ -81,7 +143,7 @@ private:
* actually stored. Our ServiceLocator implementation simply acts as a read-only
* frontend to it.
*/
- ServiceLocatorManagementImpl* mLocatorServiceManagement;
+ ServiceLocatorManagementImplPtr mLocatorServiceManagement;
};
}
@@ -107,6 +169,14 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
{
mIceStorm = new AsteriskSCF::ServiceDiscovery::CollocatedIceStorm("AsteriskSCFIceStorm", communicator->getProperties());
+ mLoggerAdapter = communicator->createObjectAdapter("LoggerAdapter");
+
+ ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mLoggerAdapter);
+
+ getLoggerFactory().setLogOutput(mIceLogger->getLogger());
+
+ mLoggerAdapter->activate();
+
lg(Info) << "Initializing service discovery component";
/* Talk to the topic manager to either create or get the service discovery topic,
@@ -152,6 +222,14 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
lg(Info) << "IceStorm topic manager proxy not present, events disabled.";
}
+ mLocalAdapter = communicator->createObjectAdapter(
+ "ServiceLocatorLocalAdapter");
+
+ mReplicaService = new ReplicaImpl(mLocalAdapter);
+ mLocalAdapter->add(mReplicaService, communicator->stringToIdentity(ReplicaServiceId));
+
+ mLocalAdapter->activate();
+
/* Management and discovery use separate adapters to provide a level of security,
* management may want to be protected so arbitrary people can't inject bad services
* into the infrastructure while discovery as a read only function may be allowed to all.
@@ -159,14 +237,39 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
mManagementAdapter= communicator->createObjectAdapter(
"ServiceLocatorManagementAdapter");
- ServiceLocatorManagementImpl* locatorServiceManagement =
- new ServiceLocatorManagementImpl(mManagementAdapter, serviceDiscoveryTopic);
+ ServiceLocatorManagementImplPtr locatorServiceManagement =
+ new ServiceLocatorManagementImpl(mManagementAdapter, serviceDiscoveryTopic, mReplicaService);
mManagementAdapter->add(locatorServiceManagement,
communicator->stringToIdentity("LocatorServiceManagement"));
mManagementAdapter->activate();
+ try
+ {
+ mStateReplicator = ServiceLocatorStateReplicatorPrx::checkedCast(communicator->propertyToProxy("ServiceLocator.StateReplicator.Proxy"));
+ ServiceLocatorStateReplicatorListenerPtr mReplicatorListener = new ServiceLocatorStateReplicatorListenerI(locatorServiceManagement);
+ ServiceLocatorStateReplicatorListenerPrx mReplicatorListenerProxy = ServiceLocatorStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
+
+ locatorServiceManagement->setStateReplicator(mStateReplicator);
+
+ if (communicator->getProperties()->getPropertyWithDefault("ServiceLocatorStateReplicatorListener", "no") == "yes")
+ {
+ mStateReplicator->addListener(mReplicatorListenerProxy);
+ mReplicaService->standby();
+ lg(Info) << "Operating as a standby replica." << endl;
+ }
+ else
+ {
+ lg(Info) << "Operating in an active state and pushing updates." << endl;
+ }
+ }
+ catch (...)
+ {
+ // If we reach this point then no state replicator is present and we are acting in a stand-alone fashion
+ lg(Info) << "Operating in an active and standalone state." << endl;
+ }
+
lg(Info) << "Activated service discovery management.";
mDiscoveryAdapter = communicator->createObjectAdapter("ServiceLocatorAdapter");
@@ -177,14 +280,6 @@ void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& co
mDiscoveryAdapter->activate();
- mLoggerAdapter = communicator->createObjectAdapter("LoggerAdapter");
-
- ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mLoggerAdapter);
-
- getLoggerFactory().setLogOutput(mIceLogger->getLogger());
-
- mLoggerAdapter->activate();
-
lg(Info) << "Activated service discovery.";
lg(Info) << "Waiting for requests.";
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 5c861bc..b6731c0 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -314,8 +314,9 @@ class AsteriskSCF::ServiceDiscovery::ServiceLocatorManagementImplPriv :
{
public:
ServiceLocatorManagementImplPriv(const Ice::ObjectAdapterPtr& adapter,
- const EventsPrx& serviceDiscoveryTopic) :
- mAdapter(adapter), mLocatorTopic(serviceDiscoveryTopic)
+ const EventsPrx& serviceDiscoveryTopic,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr replicaService) :
+ mAdapter(adapter), mLocatorTopic(serviceDiscoveryTopic), mReplicaService(replicaService)
{
};
@@ -345,6 +346,16 @@ public:
* A proxy that can be used to publish locator events.
*/
AsteriskSCF::System::Discovery::EventsPrx mLocatorTopic;
+
+ /**
+ * A proxy to the state replicator we are pushing updates to.
+ */
+ ServiceLocatorStateReplicatorPrx mStateReplicator;
+
+ /**
+ * A pointer to an instance of our replica service.
+ */
+ AsteriskSCF::System::Component::V1::ReplicaPtr mReplicaService;
};
/**
@@ -352,8 +363,9 @@ public:
*/
ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(
const Ice::ObjectAdapterPtr& adapter,
- const EventsPrx& serviceDiscoveryTopic) :
- mImpl(new ServiceLocatorManagementImplPriv(adapter, serviceDiscoveryTopic))
+ const EventsPrx& serviceDiscoveryTopic,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr replicaService) :
+ mImpl(new ServiceLocatorManagementImplPriv(adapter, serviceDiscoveryTopic, replicaService))
{
}
@@ -577,6 +589,11 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr params,
AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr comparator)
{
+ if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
+ {
+ return;
+ }
+
ServiceLocatorStateItemSeq items;
if (service)
@@ -593,6 +610,20 @@ void ServiceLocatorManagementImpl::replicateState(AsteriskSCF::Core::Discovery::
{
items.push_back(comparator);
}
+
+ if (items.size() == 0)
+ {
+ return;
+ }
+
+ try
+ {
+ ServiceLocatorStateReplicatorPrx oneway = ServiceLocatorStateReplicatorPrx::uncheckedCast(mImpl->mStateReplicator->ice_oneway());
+ oneway->setState(items);
+ }
+ catch (...)
+ {
+ }
}
/**
@@ -602,6 +633,11 @@ void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1:
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr params,
AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr comparator)
{
+ if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
+ {
+ return;
+ }
+
Ice::StringSeq items;
if (service)
@@ -618,4 +654,26 @@ void ServiceLocatorManagementImpl::removeState(AsteriskSCF::Core::Discovery::V1:
{
items.push_back(comparator->key);
}
+
+ if (items.size() == 0)
+ {
+ return;
+ }
+
+ try
+ {
+ ServiceLocatorStateReplicatorPrx oneway = ServiceLocatorStateReplicatorPrx::uncheckedCast(mImpl->mStateReplicator->ice_oneway());
+ oneway->removeState(items);
+ }
+ catch (...)
+ {
+ }
+}
+
+/**
+ * Function which sets the proxy to the state replicator.
+ */
+void ServiceLocatorManagementImpl::setStateReplicator(ServiceLocatorStateReplicatorPrx stateReplicator)
+{
+ mImpl->mStateReplicator = stateReplicator;
}
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 705f853..b80aaec 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -20,6 +20,8 @@
#include <IceUtil/Shared.h>
+#include "System/Component/ReplicaIf.h"
+
#include "ServiceLocatorStateReplicationIf.h"
namespace AsteriskSCF
@@ -65,7 +67,8 @@ class ServiceLocatorManagementImpl :
{
public:
ServiceLocatorManagementImpl(const Ice::ObjectAdapterPtr& adapter,
- const AsteriskSCF::System::Discovery::EventsPrx& serviceDiscoveryTopic);
+ const AsteriskSCF::System::Discovery::EventsPrx& serviceDiscoveryTopic,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr);
void locate(
const AsteriskSCF::Core::Discovery::V1::AMD_ServiceLocator_locatePtr&,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&);
@@ -82,6 +85,7 @@ public:
void removeState(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateItemPtr,
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsStateItemPtr,
AsteriskSCF::Core::Discovery::V1::ServiceLocatorComparatorStateItemPtr);
+ void setStateReplicator(AsteriskSCF::Core::Discovery::V1::ServiceLocatorStateReplicatorPrx);
//
// AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagement interface.
commit a589f8b67bbe0cf8f85c3e7f95c0ce25db7ff575
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 8828c22..5c861bc 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -404,15 +404,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()";
@@ -551,3 +569,53 @@ void ServiceLocatorManagementImpl::removeService(
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 bc872fd..606ed92 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -90,7 +90,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)
{
@@ -98,8 +98,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);
@@ -152,8 +152,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 c9817aee0a4abf478598383881c6223cc6fd748d
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 1d7efd4..8828c22 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -100,12 +100,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);
}
/**
@@ -129,6 +141,11 @@ public:
}
private:
/**
+ * A pointer to the locator management instance.
+ */
+ ServiceLocatorManagementImplPtr mManagement;
+
+ /**
* Comparator state replication item.
*/
ServiceLocatorComparatorStateItemPtr mStateItem;
@@ -435,7 +452,7 @@ void ServiceLocatorManagementImpl::addCompare(const string& guid,
lg(Info) << "addCompare(" << guid << ')';
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- pair<map<string, ServiceLocatorParamsComparePrx>::iterator, bool> insertPair =
+ pair<map<string, ServiceLocatorParamsComparePrx>::iterator, bool> insertPair =
mImpl->mCompares.insert(make_pair(guid, service));
if (insertPair.second == false)
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 6ff4655..705f853 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 320c777..bc872fd 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -52,7 +52,7 @@ class ServiceLocatorParamsSpec
public:
ServiceLocatorParamsSpec(const ServiceLocatorParamsPtr& params,
const std::string& compareGuid,
- ServiceLocatorManagementImpl* management)
+ ServiceLocatorManagementImplPtr management)
:
mStateItem(new ServiceLocatorParamsStateItem()),
mManagement(management)
@@ -60,6 +60,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&);
@@ -73,7 +79,7 @@ private:
/**
* A pointer to the service locator management implementation that instantiated this class.
*/
- ServiceLocatorManagementImpl* mManagement;
+ ServiceLocatorManagementImplPtr mManagement;
};
/**
@@ -82,7 +88,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()),
@@ -98,6 +104,7 @@ public:
{
mLocatorTopic->serviceRegistered(guid);
}
+ mManagement->replicateState(mStateItem, 0, 0);
}
/**
@@ -113,7 +120,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.
@@ -144,7 +151,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 753b7cd3d8ab7b0cfbed2aec2177d51fc6baf8a2
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 4fa4b08..cfb1435 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,7 +12,7 @@ include_directories(${utils_dir}/SmartProxy/src)
# Create the actual standalone service locator component
asterisk_scf_component_init(service_locator CXX)
-asterisk_scf_component_add_slice(service_locator ../local-slice/ServiceLocatorStateReplicationIf)
+asterisk_scf_component_add_slice(service_locator ../local-slice/ServiceLocatorStateReplicationIf.ice)
asterisk_scf_component_add_file(service_locator ServiceLocator.cpp)
asterisk_scf_component_add_file(service_locator ServiceLocatorManagement.cpp)
@@ -43,9 +43,7 @@ asterisk_scf_component_install(service_locator)
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_slice(ServiceLocatorStateReplicator ../local-slice/ServiceLocatorStateReplicationIf.ice)
asterisk_scf_component_add_file(ServiceLocatorStateReplicator ServiceLocatorStateReplicatorApp.cpp)
asterisk_scf_component_add_file(ServiceLocatorStateReplicator ServiceLocatorStateReplicator.h)
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 6d9f65d..6ff4655 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.
//
@@ -99,5 +103,10 @@ private:
void finish_isSupported(const Ice::AsyncResultPtr& r);
};
+/**
+ * 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;
+
+ /**
... 20381 lines suppressed ...
--
asterisk-scf/integration/serivcediscovery.git
More information about the asterisk-scf-commits
mailing list