diff options
8 files changed, 224 insertions, 35 deletions
diff --git a/cpp/src/IceLocatorDiscovery/PluginI.cpp b/cpp/src/IceLocatorDiscovery/PluginI.cpp index fde4c106e97..92295c261c0 100644 --- a/cpp/src/IceLocatorDiscovery/PluginI.cpp +++ b/cpp/src/IceLocatorDiscovery/PluginI.cpp @@ -106,9 +106,9 @@ private: LookupPrxPtr _lookup; vector<pair<LookupPrxPtr, LookupReplyPrxPtr> > _lookups; - const IceUtil::Time _timeout; - const int _retryCount; - const IceUtil::Time _retryDelay; + IceUtil::Time _timeout; + int _retryCount; + IceUtil::Time _retryDelay; const IceUtil::TimerPtr _timer; const int _traceLevel; @@ -119,6 +119,7 @@ private: Ice::LocatorPrxPtr _voidLocator; IceUtil::Time _nextRetry; + bool _pending; int _pendingRetryCount; size_t _failureCount; bool _warnOnce; @@ -574,10 +575,24 @@ LocatorI::LocatorI(const string& name, _warned(false), _locator(lookup->ice_getCommunicator()->getDefaultLocator()), _voidLocator(voidLocator), + _pending(false), _pendingRetryCount(0), _failureCount(0), _warnOnce(true) { + if(_timeout < IceUtil::Time::milliSeconds(0)) + { + _timeout = IceUtil::Time::milliSeconds(300); + } + if(_retryCount < 0) + { + _retryCount = 0; + } + if(_retryDelay < IceUtil::Time::milliSeconds(0)) + { + _retryDelay = IceUtil::Time::milliSeconds(0); + } + // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. @@ -669,7 +684,7 @@ LocatorI::getLocators(const string& instanceName, const IceUtil::Time& waitTime) else { Lock sync(*this); - while(_locators.find(instanceName) == _locators.end() && _pendingRetryCount > 0) + while(_locators.find(instanceName) == _locators.end() && _pending) { timedWait(waitTime); } @@ -725,10 +740,11 @@ LocatorI::foundLocator(const Ice::LocatorPrxPtr& locator) return; } - if(_pendingRetryCount > 0) // No need to retry, we found a locator. + if(_pending) // No need to continue, we found a locator. { _timer->cancel(ICE_SHARED_FROM_THIS); _pendingRetryCount = 0; + _pending = false; } if(_traceLevel > 0) @@ -821,8 +837,9 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) _pendingRequests.push_back(request); } - if(_pendingRetryCount == 0) // No request in progress + if(!_pending) // No request in progress { + _pending = true; _failureCount = 0; _pendingRetryCount = _retryCount; try @@ -877,6 +894,7 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) (*p)->invoke(_voidLocator); } _pendingRequests.clear(); + _pending = false; _pendingRetryCount = 0; } } @@ -887,13 +905,14 @@ void LocatorI::exception(const Ice::LocalException& ex) { Lock sync(*this); - if(++_failureCount == _lookups.size() && _pendingRetryCount > 0) + if(++_failureCount == _lookups.size() && _pending) { // // All the lookup calls failed, cancel the timer and propagate the error to the requests. // _timer->cancel(ICE_SHARED_FROM_THIS); _pendingRetryCount = 0; + _pending = false; if(_warnOnce) { @@ -932,8 +951,15 @@ void LocatorI::runTimerTask() { Lock sync(*this); - if(--_pendingRetryCount > 0) + if(!_pending) { + assert(_pendingRequests.empty()); + return; // The request failed + } + + if(_pendingRetryCount > 0) + { + --_pendingRetryCount; try { if(_traceLevel > 1) @@ -976,6 +1002,9 @@ LocatorI::runTimerTask() _pendingRetryCount = 0; } + assert(_pendingRetryCount == 0); + _pending = false; + if(_traceLevel > 0) { Ice::Trace out(_lookup->ice_getCommunicator()->getLogger(), "Lookup"); diff --git a/cpp/test/IceGrid/simple/AllTests.cpp b/cpp/test/IceGrid/simple/AllTests.cpp index 037d5627447..8ac52b2b58a 100644 --- a/cpp/test/IceGrid/simple/AllTests.cpp +++ b/cpp/test/IceGrid/simple/AllTests.cpp @@ -165,6 +165,26 @@ allTests(Test::TestHelper* helper) initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.Default.Locator", ""); + initData.properties->setProperty("IceLocatorDiscovery.RetryCount", "0"); + initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", + "IceLocatorDiscovery:createIceLocatorDiscovery"); + initData.properties->setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown"); + com = Ice::initialize(initData); + test(com->getDefaultLocator()); + try + { + com->stringToProxy("test @ TestAdapter")->ice_ping(); + test(false); + } + catch(const Ice::NoEndpointException&) + { + } + com->destroy(); + + initData.properties = communicator->getProperties()->clone(); + initData.properties->setProperty("Ice.Default.Locator", ""); + initData.properties->setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:createIceLocatorDiscovery"); { diff --git a/csharp/src/IceLocatorDiscovery/PluginI.cs b/csharp/src/IceLocatorDiscovery/PluginI.cs index c0698ed93ff..2bc28527f1b 100644 --- a/csharp/src/IceLocatorDiscovery/PluginI.cs +++ b/csharp/src/IceLocatorDiscovery/PluginI.cs @@ -139,14 +139,27 @@ namespace IceLocatorDiscovery { _lookup = lookup; _timeout = properties.getPropertyAsIntWithDefault(name + ".Timeout", 300); + if(_timeout < 0) + { + _timeout = 300; + } _retryCount = properties.getPropertyAsIntWithDefault(name + ".RetryCount", 3); + if(_retryCount < 0) + { + _retryCount = 0; + } _retryDelay = properties.getPropertyAsIntWithDefault(name + ".RetryDelay", 2000); + if(_retryDelay < 0) + { + _retryDelay = 0; + } _timer = IceInternal.Util.getInstance(lookup.ice_getCommunicator()).timer(); _traceLevel = properties.getPropertyAsInt(name + ".Trace.Lookup"); _instanceName = instanceName; _warned = false; _locator = lookup.ice_getCommunicator().getDefaultLocator(); _voidLocator = voidLocator; + _pending = false; _pendingRetryCount = 0; _failureCount = 0; _warnOnce = true; @@ -233,7 +246,7 @@ namespace IceLocatorDiscovery { lock(this) { - while(!_locators.ContainsKey(instanceName) && _pendingRetryCount > 0) + while(!_locators.ContainsKey(instanceName) && _pending) { Monitor.Wait(this, waitTime); } @@ -290,10 +303,11 @@ namespace IceLocatorDiscovery return; } - if(_pendingRetryCount > 0) // No need to retry, we found a locator + if(_pending) // No need to continue, we found a locator { _timer.cancel(this); _pendingRetryCount = 0; + _pending = false; } if(_traceLevel > 0) @@ -396,8 +410,9 @@ namespace IceLocatorDiscovery _pendingRequests.Add(request); } - if(_pendingRetryCount == 0) // No request in progress + if(!_pending) // No request in progress { + _pending = true; _pendingRetryCount = _retryCount; _failureCount = 0; try @@ -448,6 +463,7 @@ namespace IceLocatorDiscovery } _pendingRequests.Clear(); _pendingRetryCount = 0; + _pending = false; } } } @@ -458,14 +474,14 @@ namespace IceLocatorDiscovery { lock(this) { - if(++_failureCount == _lookups.Count && _pendingRetryCount > 0) + if(++_failureCount == _lookups.Count && _pending) { // // All the lookup calls failed, cancel the timer and propagate the error to the requests. // _timer.cancel(this); - _pendingRetryCount = 0; + _pending = false; if(_warnOnce) { @@ -510,8 +526,15 @@ namespace IceLocatorDiscovery { lock(this) { - if(--_pendingRetryCount > 0) + if(!_pending) { + Debug.Assert(_pendingRequests.Count == 0); + return; // Request failed + } + + if(_pendingRetryCount > 0) + { + --_pendingRetryCount; try { if(_traceLevel > 1) @@ -548,6 +571,9 @@ namespace IceLocatorDiscovery _pendingRetryCount = 0; } + Debug.Assert(_pendingRetryCount == 0); + _pending = false; + if(_traceLevel > 0) { StringBuilder s = new StringBuilder("locator lookup timed out:\nlookup = "); @@ -589,6 +615,7 @@ namespace IceLocatorDiscovery private Ice.LocatorPrx _voidLocator; private Dictionary<string, Ice.LocatorPrx> _locators = new Dictionary<string, Ice.LocatorPrx>(); + private bool _pending; private int _pendingRetryCount; private int _failureCount; private bool _warnOnce = true; diff --git a/csharp/test/IceGrid/simple/AllTests.cs b/csharp/test/IceGrid/simple/AllTests.cs index f52a30ebf39..4fd91284af4 100644 --- a/csharp/test/IceGrid/simple/AllTests.cs +++ b/csharp/test/IceGrid/simple/AllTests.cs @@ -160,6 +160,26 @@ public class AllTests : Test.AllTests initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Default.Locator", ""); + initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "0"); + initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", + "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); + initData.properties.setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown"); + com = Ice.Util.initialize(initData); + test(com.getDefaultLocator() != null); + try + { + com.stringToProxy("test @ TestAdapter").ice_ping(); + test(false); + } + catch(Ice.NoEndpointException) + { + } + com.destroy(); + + initData.properties = communicator.getProperties().ice_clone_(); + initData.properties.setProperty("Ice.Default.Locator", ""); + initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); { diff --git a/java-compat/src/IceLocatorDiscovery/src/main/java/IceLocatorDiscovery/PluginI.java b/java-compat/src/IceLocatorDiscovery/src/main/java/IceLocatorDiscovery/PluginI.java index 8939c2b9d6d..a2386d2183a 100644 --- a/java-compat/src/IceLocatorDiscovery/src/main/java/IceLocatorDiscovery/PluginI.java +++ b/java-compat/src/IceLocatorDiscovery/src/main/java/IceLocatorDiscovery/PluginI.java @@ -142,14 +142,27 @@ class PluginI implements Plugin { _lookup = lookup; _timeout = properties.getPropertyAsIntWithDefault(name + ".Timeout", 300); + if(_timeout < 0) + { + _timeout = 300; + } _retryCount = properties.getPropertyAsIntWithDefault(name + ".RetryCount", 3); + if(_retryCount < 0) + { + _retryCount = 0; + } _retryDelay = properties.getPropertyAsIntWithDefault(name + ".RetryDelay", 2000); + if(_retryDelay < 0) + { + _retryDelay = 0; + } _timer = IceInternal.Util.getInstance(lookup.ice_getCommunicator()).timer(); _traceLevel = properties.getPropertyAsInt(name + ".Trace.Lookup"); _instanceName = instanceName; _warned = false; _locator = lookup.ice_getCommunicator().getDefaultLocator(); _voidLocator = voidLocator; + _pending = false; _pendingRetryCount = 0; _failureCount = 0; _warnOnce = true; @@ -234,7 +247,7 @@ class PluginI implements Plugin { synchronized(this) { - while(!_locators.containsKey(instanceName) && _pendingRetryCount > 0) + while(!_locators.containsKey(instanceName) && _pending) { wait(waitTime); } @@ -293,12 +306,12 @@ class PluginI implements Plugin return; } - if(_pendingRetryCount > 0) // No need to retry, we found a locator + if(_pending) // No need to continue, we found a locator { _future.cancel(false); _future = null; - _pendingRetryCount = 0; + _pending = false; } if(_traceLevel > 0) @@ -392,8 +405,9 @@ class PluginI implements Plugin _pendingRequests.add(request); } - if(_pendingRetryCount == 0) // No request in progress + if(!_pending) // No request in progress { + _pending = true; _pendingRetryCount = _retryCount; _failureCount = 0; try @@ -447,6 +461,7 @@ class PluginI implements Plugin req.invoke(_voidLocator); } _pendingRequests.clear(); + _pending = false; _pendingRetryCount = 0; } } @@ -456,15 +471,15 @@ class PluginI implements Plugin synchronized void exception(Ice.LocalException ex) { - if(++_failureCount == _lookups.size() && _pendingRetryCount > 0) + if(++_failureCount == _lookups.size() && _pending) { // // All the lookup calls failed, cancel the timer and propagate the error to the requests. // _future.cancel(false); _future = null; - _pendingRetryCount = 0; + _pending = false; if(_warnOnce) { @@ -511,8 +526,15 @@ class PluginI implements Plugin { synchronized(LocatorI.this) { - if(--_pendingRetryCount > 0) + if(!_pending) + { + assert(_pendingRequests.isEmpty()); + return; // Request failed + } + + if(_pendingRetryCount > 0) { + --_pendingRetryCount; try { if(_traceLevel > 1) @@ -555,6 +577,9 @@ class PluginI implements Plugin _pendingRetryCount = 0; } + assert(_pendingRetryCount == 0); + _pending = false; + if(_traceLevel > 0) { StringBuilder s = new StringBuilder("locator lookup timed out:\nlookup = "); @@ -586,12 +611,12 @@ class PluginI implements Plugin private final LookupPrx _lookup; private final java.util.Map<LookupPrx, LookupReplyPrx> _lookups = new java.util.HashMap<>(); - private final int _timeout; + private int _timeout; private java.util.concurrent.Future<?> _future; private final java.util.concurrent.ScheduledExecutorService _timer; private final int _traceLevel; - private final int _retryCount; - private final int _retryDelay; + private int _retryCount; + private int _retryDelay; private String _instanceName; private boolean _warned; @@ -599,6 +624,7 @@ class PluginI implements Plugin private Ice.LocatorPrx _voidLocator; private Map<String, Ice.LocatorPrx> _locators = new java.util.HashMap<>(); + private boolean _pending; private int _pendingRetryCount; private int _failureCount; private boolean _warnOnce; diff --git a/java-compat/test/src/main/java/test/IceGrid/simple/AllTests.java b/java-compat/test/src/main/java/test/IceGrid/simple/AllTests.java index fdafdd3ff01..aef9a9f35a7 100644 --- a/java-compat/test/src/main/java/test/IceGrid/simple/AllTests.java +++ b/java-compat/test/src/main/java/test/IceGrid/simple/AllTests.java @@ -158,6 +158,27 @@ public class AllTests // properties = communicator.getProperties()._clone(); properties.setProperty("Ice.Default.Locator", ""); + properties.setProperty("IceLocatorDiscovery.RetryCount", "0"); + properties.setProperty("Ice.Plugin.IceLocatorDiscovery", + "IceLocatorDiscovery.PluginFactory"); + properties.setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown"); + try(Ice.Communicator com = helper.initialize(properties)) + { + test(com.getDefaultLocator() != null); + try + { + com.stringToProxy("test @ TestAdapter").ice_ping(); + test(false); + } + catch(Ice.NoEndpointException ex) + { + } + } + + properties = communicator.getProperties()._clone(); + properties.setProperty("Ice.Default.Locator", ""); + properties.setProperty("IceLocatorDiscovery.RetryCount", "1"); properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery.PluginFactory"); properties.setProperty("IceLocatorDiscovery.Lookup", diff --git a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java index 18e0043493e..07c709c221f 100644 --- a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java +++ b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java @@ -138,8 +138,20 @@ class PluginI implements Plugin { _lookup = lookup; _timeout = properties.getPropertyAsIntWithDefault(name + ".Timeout", 300); + if(_timeout < 0) + { + _timeout = 300; + } _retryCount = properties.getPropertyAsIntWithDefault(name + ".RetryCount", 3); + if(_retryCount < 0) + { + _retryCount = 0; + } _retryDelay = properties.getPropertyAsIntWithDefault(name + ".RetryDelay", 2000); + if(_retryDelay < 0) + { + _retryDelay = 0; + } _timer = com.zeroc.IceInternal.Util.getInstance(lookup.ice_getCommunicator()).timer(); _traceLevel = properties.getPropertyAsInt(name + ".Trace.Lookup"); _instanceName = instanceName; @@ -147,6 +159,7 @@ class PluginI implements Plugin _locator = lookup.ice_getCommunicator().getDefaultLocator(); _voidLocator = voidLocator; _pendingRetryCount = 0; + _pending = false; _failureCount = 0; _warnOnce = true; @@ -232,7 +245,7 @@ class PluginI implements Plugin { synchronized(this) { - while(!_locators.containsKey(instanceName) && _pendingRetryCount > 0) + while(!_locators.containsKey(instanceName) && _pending) { wait(waitTime); } @@ -290,12 +303,12 @@ class PluginI implements Plugin return; } - if(_pendingRetryCount > 0) // No need to retry, we found a locator + if(_pending) // No need to continue, we found a locator { _future.cancel(false); _future = null; - _pendingRetryCount = 0; + _pending = false; } if(_traceLevel > 0) @@ -389,10 +402,11 @@ class PluginI implements Plugin _pendingRequests.add(request); } - if(_pendingRetryCount == 0) // No request in progress + if(!_pending) // No request in progress { - _failureCount = 0; + _pending = true; _pendingRetryCount = _retryCount; + _failureCount = 0; try { if(_traceLevel > 1) @@ -436,6 +450,7 @@ class PluginI implements Plugin req.invoke(_voidLocator); } _pendingRequests.clear(); + _pending = false; _pendingRetryCount = 0; } } @@ -444,15 +459,15 @@ class PluginI implements Plugin synchronized void exception(Throwable ex) { - if(++_failureCount == _lookups.size() && _pendingRetryCount > 0) + if(++_failureCount == _lookups.size() && _pending) { // // All the lookup calls failed, cancel the timer and propagate the error to the requests. // _future.cancel(false); _future = null; - _pendingRetryCount = 0; + _pending = false; if(_warnOnce) { @@ -499,8 +514,15 @@ class PluginI implements Plugin { synchronized(LocatorI.this) { - if(--_pendingRetryCount > 0) + if(!_pending) { + assert(_pendingRequests.isEmpty()); + return; // Request failed + } + + if(_pendingRetryCount > 0) + { + --_pendingRetryCount; try { if(_traceLevel > 1) @@ -535,6 +557,9 @@ class PluginI implements Plugin _pendingRetryCount = 0; } + assert(_pendingRetryCount == 0); + _pending = false; + if(_traceLevel > 0) { StringBuilder s = new StringBuilder("locator lookup timed out:\nlookup = "); @@ -566,12 +591,12 @@ class PluginI implements Plugin private final LookupPrx _lookup; private final Map<LookupPrx, LookupReplyPrx> _lookups = new java.util.HashMap<>(); - private final int _timeout; + private int _timeout; private java.util.concurrent.Future<?> _future; private final java.util.concurrent.ScheduledExecutorService _timer; private final int _traceLevel; - private final int _retryCount; - private final int _retryDelay; + private int _retryCount; + private int _retryDelay; private String _instanceName; private boolean _warned; @@ -579,6 +604,7 @@ class PluginI implements Plugin private com.zeroc.Ice.LocatorPrx _voidLocator; private Map<String, com.zeroc.Ice.LocatorPrx> _locators = new HashMap<>(); + private boolean _pending; private int _pendingRetryCount; private int _failureCount; private boolean _warnOnce; diff --git a/java/test/src/main/java/test/IceGrid/simple/AllTests.java b/java/test/src/main/java/test/IceGrid/simple/AllTests.java index 9c53a754803..1132be3b311 100644 --- a/java/test/src/main/java/test/IceGrid/simple/AllTests.java +++ b/java/test/src/main/java/test/IceGrid/simple/AllTests.java @@ -173,6 +173,26 @@ public class AllTests initData.properties = communicator.getProperties()._clone(); initData.properties.setProperty("Ice.Default.Locator", ""); + initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "0"); + initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", + "com.zeroc.IceLocatorDiscovery.PluginFactory"); + initData.properties.setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown"); + comm = com.zeroc.Ice.Util.initialize(initData); + test(comm.getDefaultLocator() != null); + try + { + comm.stringToProxy("test @ TestAdapter").ice_ping(); + test(false); + } + catch(com.zeroc.Ice.NoEndpointException ex) + { + } + comm.destroy(); + + initData.properties = communicator.getProperties()._clone(); + initData.properties.setProperty("Ice.Default.Locator", ""); + initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "com.zeroc.IceLocatorDiscovery.PluginFactory"); { |