[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "retry_deux" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jan 31 14:58:16 CST 2012
branch "retry_deux" has been updated
via 1cc46335e9e0efd2a0baea66c2e002267c12da56 (commit)
from 744a068b60119bdec7fa9d26cadd856db1cd0fc1 (commit)
Summary of changes:
.../Discovery/LocatorRegistrationWrapper.h | 118 ++++++++++++++++++-
1 files changed, 111 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 1cc46335e9e0efd2a0baea66c2e002267c12da56
Author: Ken Hunt <ken.hunt at digium.com>
Date: Tue Jan 31 14:57:35 2012 -0600
Added retry logic to LocatorRegistrationWrapper.
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index e6d410f..752325b 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -17,9 +17,12 @@
#include <Ice/Ice.h>
#include <IceUtil/Thread.h>
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <IceUtil/UUID.h>
#include <string>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Helpers/Retry.h>
+
namespace AsteriskSCF
{
namespace Discovery
@@ -52,12 +55,91 @@ public:
mService(service),
mName(name),
mParameters(params),
- mComparatorGUID(comparatorGUID)
+ mComparatorGUID(comparatorGUID),
+ mAddServiceOpContext(new AsteriskSCF::System::V1::OperationContext(IceUtil::generateUUID())),
+ mAddParamsOpContext(new AsteriskSCF::System::V1::OperationContext(IceUtil::generateUUID()))
+ {
+ }
+
+ void addLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
+ const std::string& comparatorGUID)
+ {
+ mServiceManagement->addLocatorParams(mAddServiceOpContext, params, comparatorGUID);
+ }
+
+ /**
+ * Retries adding the locator params for the service.
+ * @return true Successful
+ */
+ bool retryAddLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
+ const std::string& comparatorGUID)
+ {
+ AsteriskSCF::RetryPolicy retryPolicy(5,500);
+
+ while(retryPolicy.canRetry())
+ {
+ try
+ {
+ addLocatorParams(params, comparatorGUID);
+ return true;
+ }
+ catch(const Ice::ConnectionLostException&)
+ {
+ // For this exception, we'll just loop and rety as long as policy allows.
+ }
+ catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
+ {
+ if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
+ {
+ return true;
+ }
+ return false;
+ }
+ }
+ return false;
+ }
+
+ void addService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
+ {
+ mServiceManagement =
+ AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(
+ management->addService(mService, mName));
+ }
+
+ /**
+ * Retries adding the service to the ServiceLocator.
+ * @return true Successful
+ */
+ bool retryAddService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
{
+ AsteriskSCF::RetryPolicy retryPolicy(5,500);
+
+ while(retryPolicy.canRetry())
+ {
+ try
+ {
+ addService(management);
+ return true;
+ }
+ catch(const Ice::ConnectionLostException&)
+ {
+ // For this exception, we'll just loop and rety as long as policy allows.
+ }
+ catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
+ {
+ if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
+ {
+ return true;
+ }
+ return false;
+ }
+ }
+ return false;
}
/**
- * The main registration function. There is *no* exception handling, so the caller must be prepared
+ * The main registration function. The only exceptions handled are those related
+ * to retries (for failover scenarios) so the caller must be prepared
* to handle whatever might be thrown.
**/
bool registerService()
@@ -68,12 +150,32 @@ public:
if (management)
{
IceUtil::Mutex::Lock lock(mLock);
- mServiceManagement =
- AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(
- management->addService(mService, mName));
+
+ try
+ {
+ addService(management);
+ }
+ catch(const Ice::ConnectionLostException&)
+ {
+ if (!retryAddService(management))
+ {
+ return false;
+ }
+ }
+
if (mServiceManagement)
{
- mServiceManagement->addLocatorParams(mParameters, mComparatorGUID);
+ try
+ {
+ addLocatorParams(mParameters, mComparatorGUID);
+ }
+ catch(const Ice::ConnectionLostException&)
+ {
+ if (!retryAddLocatorParams(mParameters, mComparatorGUID))
+ {
+ return false;
+ }
+ }
return true;
}
}
@@ -141,6 +243,8 @@ private:
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mParameters;
AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx mServiceManagement;
std::string mComparatorGUID;
+ AsteriskSCF::System::V1::OperationContextPtr mAddServiceOpContext;
+ AsteriskSCF::System::V1::OperationContextPtr mAddParamsOpContext;
};
typedef ASTSCF_DLL_EXPORT IceUtil::Handle<LocatorRegistrationWrapper> LocatorRegistrationWrapperPtr;
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list