[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "basecomponent" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Jul 15 17:32:31 CDT 2011
branch "basecomponent" has been updated
via ef03e42a73fdb41fa8d383a8e73c1a453b0f676d (commit)
from 454a11c6eafa4a139938aa322a7ae92519861f5d (commit)
Summary of changes:
include/AsteriskSCF/Component/Component.h | 14 +++--
include/AsteriskSCF/Discovery/SmartProxy.h | 74 +++++++++++++++++++++++++++-
src/Component/Component.cpp | 65 +++++++++++-------------
test/Component/MockComponent.cpp | 15 ++----
4 files changed, 116 insertions(+), 52 deletions(-)
- Log -----------------------------------------------------------------
commit ef03e42a73fdb41fa8d383a8e73c1a453b0f676d
Author: Ken Hunt <ken.hunt at digium.com>
Date: Fri Jul 15 17:31:39 2011 -0500
Updates made refactoring the components to use the base Component class.
diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
index d37c5ad..33f11ee 100644
--- a/include/AsteriskSCF/Component/Component.h
+++ b/include/AsteriskSCF/Component/Component.h
@@ -194,15 +194,19 @@ protected:
/**
* Helper that caches the service references for the primary adapter, and invokes
- * the register method of the registration wrapper.
+ * the register method of the registration wrapper if the component is active.
+ * @return true if the service is registered. Always returns false if the component
+ * is in standby mode.
*/
- bool registerPrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+ bool managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
/**
* Helper that caches the service references for the backplane adapter, and invokes
- * the register method of the registration wrapper.
+ * the register method of the registration wrapper if the component is active.
+ * @return true if the service is registered. Always returns false if the component
+ * is in standby mode.
*/
- bool registerBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+ bool manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
/**
* Helper that wraps a service for registration by making some assumptions that
@@ -256,7 +260,7 @@ protected:
// Allow setting an alternative communicator.
// This should only be done in onPreInitialize() override, or
- // something may be using the IceBox-provided communicator.
+ // things may already be using the IceBox-provided communicator.
void setCommunicator(const Ice::CommunicatorPtr& communicator) {mCommunicator = communicator;}
// State data
diff --git a/include/AsteriskSCF/Discovery/SmartProxy.h b/include/AsteriskSCF/Discovery/SmartProxy.h
index 68a781c..eda54fb 100644
--- a/include/AsteriskSCF/Discovery/SmartProxy.h
+++ b/include/AsteriskSCF/Discovery/SmartProxy.h
@@ -44,7 +44,7 @@ template <class P>
class SmartProxy
{
public:
- SmartProxy() : mServiceLocator(0), mLocatorParams(0), mLogger(0) {}
+ SmartProxy() : mServiceLocator(0), mLocatorParams(0), mLogger(0), mSupportsOneWay(false) {}
SmartProxy(const SmartProxy &rhs)
{
@@ -55,7 +55,8 @@ public:
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
AsteriskSCF::System::Logging::Logger const &lg)
- : mServiceLocator(locator), mLocatorParams(params), mLogger(&lg)
+ : mServiceLocator(locator), mLocatorParams(params), mLogger(&lg),
+ mSupportsOneWay(false)
{
using namespace AsteriskSCF::System::Logging;
if (!mLocatorParams)
@@ -80,6 +81,40 @@ public:
return t;
}
+ /**
+ * Attempts to offer a oneway proxy. If oneway isn't supported, will return the
+ * two-way proxy without throwing the typical NoEndpointException that ice_oneway
+ * might have thrown. If the caller needs to know, the supportsOneWay() is available.
+ * Note that TwoWayOnly exception can still be generated if
+ * calling an operation that needs to send info back to client.
+ * @see supportsOneWay
+ */
+ P tryOneWay()
+ {
+ initOneWay();
+
+ return mOneWayProxy;
+ }
+
+ /**
+ * If you want to know whether or not a one_way proxy can even be
+ * created, you can test with this.
+ */
+ bool supportsOneWay()
+ {
+ try
+ {
+ initOneWay();
+ }
+ catch(const steriskSCF::Core::Discovery::V1::ServiceNotFound&)
+ {
+ // The original proxy isn't reachable.
+ return false;
+ }
+
+ return mSupportsOneWay;
+ }
+
SmartProxy &operator=(const SmartProxy &rhs)
{
// copy is thread safe. no need to lock.
@@ -167,6 +202,39 @@ public:
private:
+ /**
+ * Attempts to create (and cache) a oneway proxy for
+ * this proxy.
+ */
+ void initOneWay()
+ {
+ if (mOneWayProxy != 0)
+ {
+ // This has been done.
+ return;
+ }
+
+ Ice::ObjectPrx oneway;
+ try
+ {
+ P t = initialize();
+ if (!t)
+ {
+ // We can't create a one way to a proxy we haven't located yet.
+ throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
+ }
+
+ oneway = t->ice_oneway();
+ mOneWayProxy = P::uncheckedCast(oneway);
+ mSupportsOneWay = true;
+ }
+ catch (const Ice::NoEndpointException&)
+ {
+ (*mLogger)(AsteriskSCF::System::Logging::Warning) << "No endpoint for oneway invocation. Defaulting to two-way.";
+ mOneWayProxy = mProxy;
+ }
+ }
+
void copy(const SmartProxy &rhs)
{
// thread safe
@@ -182,9 +250,11 @@ private:
// we want to lock even const instances, so mMutex must be mutable
mutable IceUtil::Mutex mMutex;
P mProxy;
+ P mOneWayProxy;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
AsteriskSCF::System::Logging::Logger const *mLogger;
+ bool mSupportsOneWay;
};
}; // end SmartProxy
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index a829059..17397e5 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -320,16 +320,20 @@ LocatorRegistrationWrapperPtr Component::wrapServiceForRegistration(const Ice::O
}
/**
- * In the override of registerServices(), this operation should
+ * In the override of registerPrimaryServices(), this operation should
* be called for each primary interface registered with the service locator.
*/
-bool Component::registerPrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
+bool Component::managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
{
bool result(false);
try
{
mPrimaryServices.push_back(service);
- result = service->registerService();
+
+ if (mReplicationContext->isActive())
+ {
+ result = service->registerService();
+ }
}
catch(const Ice::Exception& e)
{
@@ -343,13 +347,17 @@ bool Component::registerPrimaryService(const AsteriskSCF::Discovery::LocatorRegi
/**
* This operation should be called for each backplane interface registered with the service locator.
*/
-bool Component::registerBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
+bool Component::manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service)
{
bool result(false);
try
{
mBackplaneServices.push_back(service);
- result = service->registerService();
+
+ if (mReplicationContext->isActive())
+ {
+ result = service->registerService();
+ }
}
catch(const Ice::Exception& e)
{
@@ -367,19 +375,11 @@ void Component::registerBackplaneServices()
try
{
// Register the ComponentService interface with the Service Locator.
- {
- ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
- parameters->category = mComponentDiscoveryCategory;
- parameters->service = mServiceName;
- parameters->id = mName;
- mComponentRegistration =
- new LocatorRegistrationWrapper(mCommunicator,
- getServiceLocatorManagementProperty(),
- mComponentServicePrx,
- mName + ".ComponentService",
- parameters);
- registerBackplaneService(mComponentRegistration);
- }
+ mComponentRegistration = wrapServiceForRegistration(mComponentServicePrx,
+ mComponentDiscoveryCategory,
+ mServiceName,
+ mName);
+ manageBackplaneService(mComponentRegistration);
if (mPublishTestInterface)
{
@@ -392,19 +392,11 @@ void Component::registerBackplaneServices()
// Register the Replica interface with the Service Locator.
- {
- ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
- parameters->category = mComponentDiscoveryCategory + ".Replica";
- parameters->service = mServiceName;
- parameters->id = mName;
- mReplicaRegistration =
- new LocatorRegistrationWrapper(mCommunicator,
- getServiceLocatorManagementProperty(),
- mReplicaPrx,
- parameters->id,
- parameters);
- registerBackplaneService(mReplicaRegistration);
- }
+ mReplicaRegistration = wrapServiceForRegistration(mReplicaPrx,
+ mComponentDiscoveryCategory + ".Replica",
+ mServiceName,
+ mName);
+ manageBackplaneService(mReplicaRegistration);
}
catch(const std::exception& e)
{
@@ -614,7 +606,7 @@ void Component::initReplicationContext()
// the Replica interface. But for now, we default to active unless
// the soon-to-be obsolete Standby property is set.
if (AsteriskSCF::getBooleanPropertyValueWithDefault(mCommunicator->getProperties(),
- mName + ".Standby", false))
+ mName + ".Standby", false) == false)
{
state = ACTIVE_IN_REPLICA_GROUP;
}
@@ -630,7 +622,6 @@ void Component::initReplicationContext()
}
}
-
/**
* Create a TestContext for this component.
* This operation is a step in initialize()'s Template Method pattern.
@@ -718,11 +709,15 @@ void Component::initServiceLocatorProxies()
{
// Get a proxy to the management interface for the Service Locator manager.
mServiceLocatorManagement =
- ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorManagementPropertyName));
+ ServiceLocatorManagementPrx::checkedCast(mCommunicator->stringToProxy(
+ mCommunicator->getProperties()->getPropertyWithDefault(
+ ServiceLocatorManagementPropertyName, "LocatorServiceManagement:tcp -p 4422")));
// Get a proxy to the interface for the Service Locator.
mServiceLocator =
- ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy(ServiceLocatorPropertyName));
+ ServiceLocatorPrx::checkedCast(mCommunicator->stringToProxy(
+ mCommunicator->getProperties()->getPropertyWithDefault(
+ ServiceLocatorPropertyName, "LocatorService:default -p 4411")));
}
catch(const Ice::Exception& e)
{
diff --git a/test/Component/MockComponent.cpp b/test/Component/MockComponent.cpp
index cf5ec2c..f60b2a8 100644
--- a/test/Component/MockComponent.cpp
+++ b/test/Component/MockComponent.cpp
@@ -135,17 +135,12 @@ void MockComponent::registerPrimaryServices()
{
try
{
- ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
- parameters->category = "MockService";
- parameters->service = "default";
- parameters->id = getName();
LocatorRegistrationWrapperPtr registration =
- new LocatorRegistrationWrapper(getCommunicator(),
- getServiceLocatorManagementProperty(),
- mServicePrx,
- parameters->id,
- parameters);
- registerPrimaryService(registration);
+ wrapServiceForRegistration(mServicePrx,
+ "MockService",
+ "default",
+ getName());
+ managePrimaryService(registration);
}
catch(const std::exception& e)
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list