diff --git a/config/PropertyNames.xml b/config/PropertyNames.xml index c9d2d5531c5..31668dec7db 100644 --- a/config/PropertyNames.xml +++ b/config/PropertyNames.xml @@ -109,7 +109,6 @@ For example, consider the following definitions:
- @@ -149,7 +148,6 @@ public: // Properties.cpp const IceInternal::Property IceInternal::Properties::IcePropsData[] = { - IceInternal::Property("Ice.ChangeUser", false, 0), IceInternal::Property("Ice.Package.*", false, 0), IceInternal::Property("Ice.QuenchRequests", true, 0), IceInternal::Property("Ice.Foo", true, "Ice.Bar"), @@ -220,11 +218,9 @@ generated from the section label. - - @@ -264,7 +260,6 @@ generated from the section label. - @@ -316,8 +311,7 @@ generated from the section label. - - + diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index b20a1704022..88a9d1d2773 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -15,6 +15,7 @@ #include "ReferenceF.h" #include "RequestHandlerF.h" +#include #include #include #include @@ -165,7 +166,22 @@ namespace Ice * @param timeout The new invocation timeout (in milliseconds). * @return A proxy with the new timeout. */ - Prx ice_invocationTimeout(int timeout) const { return fromReference(asPrx()._invocationTimeout(timeout)); } + Prx ice_invocationTimeout(int timeout) const + { + return ice_invocationTimeout(std::chrono::milliseconds(timeout)); + } + + /** + * Obtains a proxy that is identical to this proxy, except for the invocation timeout. + * @param timeout The new invocation timeout. + * @return A proxy with the new timeout. + */ + template + Prx ice_invocationTimeout(const std::chrono::duration& timeout) const + { + return fromReference( + asPrx()._invocationTimeout(std::chrono::duration_cast(timeout))); + } /** * Obtains a proxy that is identical to this proxy, except for the locator. @@ -182,7 +198,22 @@ namespace Ice * @param timeout The new locator cache timeout (in seconds). * @return A proxy with the new timeout. */ - Prx ice_locatorCacheTimeout(int timeout) const { return fromReference(asPrx()._locatorCacheTimeout(timeout)); } + Prx ice_locatorCacheTimeout(int timeout) const + { + return ice_locatorCacheTimeout(std::chrono::seconds(timeout)); + } + + /** + * Obtains a proxy that is identical to this proxy, except for the locator cache timeout. + * @param timeout The new locator cache timeout. + * @return A proxy with the new timeout. + */ + template + Prx ice_locatorCacheTimeout(const std::chrono::duration& timeout) const + { + return fromReference( + asPrx()._locatorCacheTimeout(std::chrono::duration_cast(timeout))); + } /** * Obtains a proxy that is identical to this proxy, but uses oneway invocations. @@ -614,9 +645,9 @@ namespace Ice /** * Obtains the locator cache timeout of this proxy. - * @return The locator cache timeout value (in seconds). + * @return The locator cache timeout value. */ - std::int32_t ice_getLocatorCacheTimeout() const noexcept; + std::chrono::milliseconds ice_getLocatorCacheTimeout() const noexcept; /** * Determines whether this proxy caches connections. @@ -670,9 +701,9 @@ namespace Ice /** * Obtains the invocation timeout of this proxy. - * @return The invocation timeout value (in milliseconds). + * @return The invocation timeout value. */ - std::int32_t ice_getInvocationTimeout() const noexcept; + std::chrono::milliseconds ice_getInvocationTimeout() const noexcept; /** * Determines whether this proxy uses twoway invocations. @@ -787,14 +818,13 @@ namespace Ice IceInternal::ReferencePtr _identity(Identity) const; IceInternal::ReferencePtr _facet(std::string) const; IceInternal::ReferencePtr _fixed(ConnectionPtr) const; - IceInternal::ReferencePtr _invocationTimeout(int) const; + IceInternal::ReferencePtr _invocationTimeout(std::chrono::milliseconds) const; IceInternal::ReferencePtr _locator(const std::optional&) const; - IceInternal::ReferencePtr _locatorCacheTimeout(int) const; + IceInternal::ReferencePtr _locatorCacheTimeout(std::chrono::milliseconds) const; IceInternal::ReferencePtr _oneway() const; IceInternal::ReferencePtr _preferSecure(bool) const; IceInternal::ReferencePtr _router(const std::optional&) const; IceInternal::ReferencePtr _secure(bool) const; - IceInternal::ReferencePtr _timeout(int) const; IceInternal::ReferencePtr _twoway() const; // Only the assignment operators can change these fields. All other member functions must be const. diff --git a/cpp/src/Ice/CollocatedRequestHandler.cpp b/cpp/src/Ice/CollocatedRequestHandler.cpp index dafbb232a0e..0554fb26adb 100644 --- a/cpp/src/Ice/CollocatedRequestHandler.cpp +++ b/cpp/src/Ice/CollocatedRequestHandler.cpp @@ -158,7 +158,7 @@ CollocatedRequestHandler::invokeAsyncRequest(OutgoingAsyncBase* outAsync, int ba // auto self = shared_from_this(); - if (!synchronous || !_response || _reference->getInvocationTimeout() > 0) + if (!synchronous || !_response || _reference->getInvocationTimeout() > 0ms) { auto stream = make_shared(); is.swap(*stream); diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index 19f5b613335..4cde22cc46b 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace Ice; using namespace IceInternal; -IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& properties, const LoggerPtr& logger) +IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& properties) : overrideCompress(nullopt), overrideSecure(nullopt) { @@ -63,23 +63,10 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro throw ParseException(__FILE__, __LINE__, "illegal value '" + value + "'; expected 'Random' or 'Ordered'"); } - const_cast(defaultInvocationTimeout) = properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout"); - if (defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1) - { - const_cast(defaultInvocationTimeout) = -1; - Warning out(logger); - out << "invalid value for Ice.Default.InvocationTimeout `" - << properties->getIceProperty("Ice.Default.InvocationTimeout") << "': defaulting to -1"; - } - - const_cast(defaultLocatorCacheTimeout) = properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); - if (defaultLocatorCacheTimeout < -1) - { - const_cast(defaultLocatorCacheTimeout) = -1; - Warning out(logger); - out << "invalid value for Ice.Default.LocatorCacheTimeout `" - << properties->getIceProperty("Ice.Default.LocatorCacheTimeout") << "': defaulting to -1"; - } + const_cast(defaultInvocationTimeout) = + chrono::milliseconds(properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout")); + const_cast(defaultLocatorCacheTimeout) = + chrono::seconds(properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); const_cast(defaultPreferSecure) = properties->getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; diff --git a/cpp/src/Ice/DefaultsAndOverrides.h b/cpp/src/Ice/DefaultsAndOverrides.h index 46ca2499cac..f93fc9ec0b3 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.h +++ b/cpp/src/Ice/DefaultsAndOverrides.h @@ -13,20 +13,22 @@ #include "Ice/PropertiesF.h" #include "Network.h" +#include + namespace IceInternal { class DefaultsAndOverrides { public: - DefaultsAndOverrides(const Ice::PropertiesPtr&, const Ice::LoggerPtr&); + DefaultsAndOverrides(const Ice::PropertiesPtr&); std::string defaultHost; Address defaultSourceAddress; std::string defaultProtocol; bool defaultCollocationOptimization; Ice::EndpointSelectionType defaultEndpointSelection; - int defaultInvocationTimeout; - int defaultLocatorCacheTimeout; + std::chrono::milliseconds defaultInvocationTimeout; + std::chrono::seconds defaultLocatorCacheTimeout; bool defaultPreferSecure; Ice::EncodingVersion defaultEncoding; Ice::FormatType defaultFormat; diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 9a5da5aa310..fa67ea451db 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -967,45 +967,6 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator) IceInternal::printStackTraces = false; } #endif - -#ifndef _WIN32 - string newUser = _initData.properties->getIceProperty("Ice.ChangeUser"); - if (!newUser.empty()) - { - struct passwd pwbuf; - vector buffer(4096); // 4KB initial buffer - struct passwd* pw; - int err; - while ((err = getpwnam_r(newUser.c_str(), &pwbuf, &buffer[0], buffer.size(), &pw)) == ERANGE && - buffer.size() < 1024 * 1024) // Limit buffer to 1M - { - buffer.resize(buffer.size() * 2); - } - if (err != 0) - { - throw Ice::SyscallException{__FILE__, __LINE__, "getpwnam_r failed", err}; - } - else if (pw == 0) - { - throw InitializationException(__FILE__, __LINE__, "unknown user account '" + newUser + "'"); - } - - if (setgid(pw->pw_gid) == -1) - { - throw SyscallException{__FILE__, __LINE__, "setgid failed", errno}; - } - - if (initgroups(pw->pw_name, static_cast(pw->pw_gid)) == -1) - { - throw SyscallException{__FILE__, __LINE__, "initgroups failed", errno}; - } - - if (setuid(pw->pw_uid) == -1) - { - throw SyscallException{__FILE__, __LINE__, "setuid failed", errno}; - } - } -#endif oneOfDone = true; } @@ -1105,7 +1066,7 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator) const_cast(_traceLevels) = make_shared(_initData.properties); const_cast(_defaultsAndOverrides) = - make_shared(_initData.properties, _initData.logger); + make_shared(_initData.properties); const_cast(_clientConnectionOptions) = readConnectionOptions("Ice.Connection.Client"); const_cast(_serverConnectionOptions) = readConnectionOptions("Ice.Connection.Server"); diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index a69077bc794..a10c90ec835 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -159,9 +159,12 @@ IceInternal::LocatorTable::clear() } bool -IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, int ttl, vector& endpoints) +IceInternal::LocatorTable::getAdapterEndpoints( + const string& adapter, + chrono::milliseconds ttl, + vector& endpoints) { - if (ttl == 0) // No locator cache. + if (ttl == 0ms) // No locator cache. { return false; } @@ -214,9 +217,9 @@ IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter) } bool -IceInternal::LocatorTable::getObjectReference(const Identity& id, int ttl, ReferencePtr& ref) +IceInternal::LocatorTable::getObjectReference(const Identity& id, chrono::milliseconds ttl, ReferencePtr& ref) { - if (ttl == 0) // No locator cache + if (ttl == 0ms) // No locator cache { return false; } @@ -266,16 +269,16 @@ IceInternal::LocatorTable::removeObjectReference(const Identity& id) } bool -IceInternal::LocatorTable::checkTTL(const chrono::steady_clock::time_point& time, int ttl) const +IceInternal::LocatorTable::checkTTL(const chrono::steady_clock::time_point& time, chrono::milliseconds ttl) const { - assert(ttl != 0); - if (ttl < 0) // TTL = infinite + assert(ttl != 0ms); + if (ttl < 0ms) // TTL = infinite { return true; } else { - return chrono::steady_clock::now() - time <= chrono::seconds(ttl); + return chrono::steady_clock::now() - time <= ttl; } } @@ -345,7 +348,7 @@ IceInternal::LocatorInfo::RequestCallback::exception(const LocatorInfoPtr& locat IceInternal::LocatorInfo::RequestCallback::RequestCallback( const ReferencePtr& ref, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) : _reference(ref), _ttl(ttl), @@ -357,7 +360,7 @@ void IceInternal::LocatorInfo::Request::addCallback( const ReferencePtr& ref, const ReferencePtr& wellKnownRef, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) { RequestCallbackPtr callback = make_shared(ref, ttl, cb); @@ -508,7 +511,7 @@ void IceInternal::LocatorInfo::getEndpoints( const ReferencePtr& ref, const ReferencePtr& wellKnownRef, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& callback) { assert(ref->isIndirect()); diff --git a/cpp/src/Ice/LocatorInfo.h b/cpp/src/Ice/LocatorInfo.h index a94317deb3d..1a809c5f297 100644 --- a/cpp/src/Ice/LocatorInfo.h +++ b/cpp/src/Ice/LocatorInfo.h @@ -48,16 +48,16 @@ namespace IceInternal void clear(); - bool getAdapterEndpoints(const std::string&, int, std::vector&); + bool getAdapterEndpoints(const std::string&, std::chrono::milliseconds, std::vector&); void addAdapterEndpoints(const std::string&, const std::vector&); std::vector removeAdapterEndpoints(const std::string&); - bool getObjectReference(const Ice::Identity&, int, ReferencePtr&); + bool getObjectReference(const Ice::Identity&, std::chrono::milliseconds, ReferencePtr&); void addObjectReference(const Ice::Identity&, const ReferencePtr&); ReferencePtr removeObjectReference(const Ice::Identity&); private: - bool checkTTL(const std::chrono::steady_clock::time_point&, int) const; + bool checkTTL(const std::chrono::steady_clock::time_point&, std::chrono::milliseconds) const; std::map>> _adapterEndpointsMap; @@ -79,14 +79,14 @@ namespace IceInternal class RequestCallback final { public: - RequestCallback(const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + RequestCallback(const ReferencePtr&, std::chrono::milliseconds, const GetEndpointsCallbackPtr&); void response(const LocatorInfoPtr&, const std::optional&); void exception(const LocatorInfoPtr&, std::exception_ptr); private: const ReferencePtr _reference; - const int _ttl; + const std::chrono::milliseconds _ttl; const GetEndpointsCallbackPtr _callback; }; using RequestCallbackPtr = std::shared_ptr; @@ -94,7 +94,11 @@ namespace IceInternal class Request { public: - void addCallback(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + void addCallback( + const ReferencePtr&, + const ReferencePtr&, + std::chrono::milliseconds, + const GetEndpointsCallbackPtr&); void response(const std::optional&); void exception(std::exception_ptr); @@ -129,11 +133,15 @@ namespace IceInternal std::optional getLocatorRegistry(); - void getEndpoints(const ReferencePtr& ref, int ttl, const GetEndpointsCallbackPtr& cb) + void getEndpoints(const ReferencePtr& ref, std::chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) { getEndpoints(ref, 0, ttl, cb); } - void getEndpoints(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + void getEndpoints( + const ReferencePtr&, + const ReferencePtr&, + std::chrono::milliseconds, + const GetEndpointsCallbackPtr&); void clearCache(const ReferencePtr&); diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index d9f4c28975d..caa7792342d 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -1439,9 +1439,7 @@ Ice::ObjectAdapterI::filterProperties(StringSeq& unknownProps) "ThreadPool.Size", "ThreadPool.SizeMax", "ThreadPool.SizeWarn", - "ThreadPool.StackSize", - "ThreadPool.ThreadIdleTime", - "ThreadPool.ThreadPriority"}; + "ThreadPool.ThreadIdleTime"}; // // Do not create unknown properties list if Ice prefix, ie Ice, Glacier2, etc diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 61a5fb09fe6..a2303463b18 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -428,10 +428,10 @@ ProxyOutgoingAsyncBase::invokeImpl(bool userThread) { if (userThread) { - int invocationTimeout = _proxy._getReference()->getInvocationTimeout(); - if (invocationTimeout > 0) + chrono::milliseconds invocationTimeout = _proxy._getReference()->getInvocationTimeout(); + if (invocationTimeout > 0ms) { - _instance->timer()->schedule(shared_from_this(), chrono::milliseconds(invocationTimeout)); + _instance->timer()->schedule(shared_from_this(), invocationTimeout); } } else @@ -515,7 +515,7 @@ ProxyOutgoingAsyncBase::sentImpl(bool done) _sent = true; if (done) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } @@ -526,7 +526,7 @@ ProxyOutgoingAsyncBase::sentImpl(bool done) bool ProxyOutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } @@ -536,7 +536,7 @@ ProxyOutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) bool ProxyOutgoingAsyncBase::responseImpl(bool ok, bool invoke) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index dedec0764a2..e541949d996 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -// Generated by makeprops.py from PropertyNames.xml, Thu Sep 26 17:31:37 2024 +// Generated by makeprops.py from PropertyNames.xml, Fri Sep 27 14:21:19 2024 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -57,7 +57,6 @@ const IceInternal::Property IcePropsData[] = IceInternal::Property("Ice.BackgroundLocatorCacheUpdates", false, "0", false), IceInternal::Property("Ice.BatchAutoFlush", false, "", true), IceInternal::Property("Ice.BatchAutoFlushSize", false, "1024", false), - IceInternal::Property("Ice.ChangeUser", false, "", false), IceInternal::Property("Ice.ClassGraphDepthMax", false, "10", false), IceInternal::Property("Ice.Compression.Level", false, "1", false), IceInternal::Property("Ice.Config", false, "", false), @@ -141,7 +140,6 @@ const IceInternal::Property IcePropsData[] = IceInternal::Property("Ice.ThreadPool.Server.SizeWarn", false, "0", false), IceInternal::Property("Ice.ThreadPool.Server.Serialize", false, "0", false), IceInternal::Property("Ice.ThreadPool.Server.ThreadIdleTime", false, "60", false), - IceInternal::Property("Ice.ThreadPriority", false, "", false), IceInternal::Property("Ice.ToStringMode", false, "Unicode", false), IceInternal::Property("Ice.Trace.Admin.Properties", false, "0", false), IceInternal::Property("Ice.Trace.Admin.Logger", false, "0", false), diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index accb5dbab6f..39df5f1c684 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -// Generated by makeprops.py from PropertyNames.xml, Thu Sep 26 17:31:37 2024 +// Generated by makeprops.py from PropertyNames.xml, Fri Sep 27 14:21:19 2024 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index cab8682c7b6..8f517edd929 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -109,7 +109,7 @@ Ice::ObjectPrx::ice_getEndpoints() const return retSeq; } -int32_t +chrono::milliseconds Ice::ObjectPrx::ice_getLocatorCacheTimeout() const noexcept { return _reference->getLocatorCacheTimeout(); @@ -165,7 +165,7 @@ Ice::ObjectPrx::ice_isCollocationOptimized() const noexcept return _reference->getCollocationOptimized(); } -int32_t +chrono::milliseconds Ice::ObjectPrx::ice_getInvocationTimeout() const noexcept { return _reference->getInvocationTimeout(); @@ -476,14 +476,8 @@ Ice::ObjectPrx::_fixed(ConnectionPtr connection) const } ReferencePtr -Ice::ObjectPrx::_invocationTimeout(int newTimeout) const +Ice::ObjectPrx::_invocationTimeout(chrono::milliseconds newTimeout) const { - if (newTimeout < 1 && newTimeout != -1) - { - ostringstream s; - s << "invalid value passed to ice_invocationTimeout: " << newTimeout; - throw invalid_argument(s.str()); - } if (newTimeout == _reference->getInvocationTimeout()) { return _reference; @@ -509,14 +503,8 @@ Ice::ObjectPrx::_locator(const std::optional& locator) const } ReferencePtr -Ice::ObjectPrx::_locatorCacheTimeout(int newTimeout) const +Ice::ObjectPrx::_locatorCacheTimeout(chrono::milliseconds newTimeout) const { - if (newTimeout < -1) - { - ostringstream s; - s << "invalid value passed to ice_locatorCacheTimeout: " << newTimeout; - throw invalid_argument(s.str()); - } if (newTimeout == _reference->getLocatorCacheTimeout()) { return _reference; diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index a664c93c81a..3848c228f85 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -81,7 +81,7 @@ IceInternal::Reference::changeFacet(string newFacet) const } ReferencePtr -IceInternal::Reference::changeInvocationTimeout(int invocationTimeout) const +IceInternal::Reference::changeInvocationTimeout(chrono::milliseconds invocationTimeout) const { ReferencePtr r = clone(); r->_invocationTimeout = invocationTimeout; @@ -125,7 +125,7 @@ Reference::hash() const noexcept hashAdd(h, _facet); hashAdd(h, _compress); // We don't include protocol and encoding in the hash; they are using 1.0 and 1.1, respectively. - hashAdd(h, _invocationTimeout); + hashAdd(h, _invocationTimeout.count()); return h; } @@ -430,7 +430,7 @@ IceInternal::Reference::Reference( std::optional compress, const ProtocolVersion& protocol, const EncodingVersion& encoding, - int invocationTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& ctx) : _instance(instance), _communicator(communicator), @@ -473,7 +473,7 @@ IceInternal::FixedReference::FixedReference( const ProtocolVersion& protocol, const EncodingVersion& encoding, ConnectionIPtr fixedConnection, - int invocationTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& context) : Reference( instance, @@ -527,10 +527,10 @@ IceInternal::FixedReference::getEndpointSelection() const noexcept return EndpointSelectionType::Random; } -int +chrono::milliseconds IceInternal::FixedReference::getLocatorCacheTimeout() const noexcept { - return 0; + return 0ms; } string @@ -588,7 +588,7 @@ IceInternal::FixedReference::changeEndpointSelection(EndpointSelectionType) cons } ReferencePtr -IceInternal::FixedReference::changeLocatorCacheTimeout(int) const +IceInternal::FixedReference::changeLocatorCacheTimeout(chrono::milliseconds) const { throw FixedProxyException(__FILE__, __LINE__); } @@ -765,8 +765,8 @@ IceInternal::RoutableReference::RoutableReference( bool cacheConnection, bool preferSecure, EndpointSelectionType endpointSelection, - int locatorCacheTimeout, - int invocationTimeout, + chrono::milliseconds locatorCacheTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& ctx) : Reference(instance, communicator, id, facet, mode, secure, compress, protocol, encoding, invocationTimeout, ctx), _endpoints(endpoints), @@ -831,7 +831,7 @@ IceInternal::RoutableReference::getEndpointSelection() const noexcept return _endpointSelection; } -int +chrono::milliseconds IceInternal::RoutableReference::getLocatorCacheTimeout() const noexcept { return _locatorCacheTimeout; @@ -953,7 +953,7 @@ IceInternal::RoutableReference::changeEndpointSelection(EndpointSelectionType ne } ReferencePtr -IceInternal::RoutableReference::changeLocatorCacheTimeout(int timeout) const +IceInternal::RoutableReference::changeLocatorCacheTimeout(chrono::milliseconds timeout) const { RoutableReferencePtr r = dynamic_pointer_cast(clone()); r->_locatorCacheTimeout = timeout; @@ -1092,8 +1092,9 @@ IceInternal::RoutableReference::toProperty(const string& prefix) const properties[prefix + ".PreferSecure"] = _preferSecure ? "1" : "0"; properties[prefix + ".EndpointSelection"] = _endpointSelection == EndpointSelectionType::Random ? "Random" : "Ordered"; - properties[prefix + ".LocatorCacheTimeout"] = to_string(_locatorCacheTimeout); - properties[prefix + ".InvocationTimeout"] = to_string(getInvocationTimeout()); + properties[prefix + ".LocatorCacheTimeout"] = + to_string(chrono::duration_cast(_locatorCacheTimeout).count()); + properties[prefix + ".InvocationTimeout"] = to_string(getInvocationTimeout().count()); if (_routerInfo) { diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 681fc079f23..a2dc895064b 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -55,7 +55,7 @@ namespace IceInternal const std::string& getFacet() const noexcept { return _facet; } const InstancePtr& getInstance() const noexcept { return _instance; } const SharedContextPtr& getContext() const noexcept { return _context; } - int getInvocationTimeout() const noexcept { return _invocationTimeout; } + std::chrono::milliseconds getInvocationTimeout() const noexcept { return _invocationTimeout; } std::optional getCompress() const noexcept { return _compress; } Ice::CommunicatorPtr getCommunicator() const noexcept; @@ -68,7 +68,7 @@ namespace IceInternal virtual bool getCacheConnection() const noexcept = 0; virtual bool getPreferSecure() const noexcept = 0; virtual Ice::EndpointSelectionType getEndpointSelection() const noexcept = 0; - virtual int getLocatorCacheTimeout() const noexcept = 0; + virtual std::chrono::milliseconds getLocatorCacheTimeout() const noexcept = 0; virtual std::string getConnectionId() const = 0; // @@ -80,7 +80,7 @@ namespace IceInternal ReferencePtr changeSecure(bool) const; ReferencePtr changeIdentity(Ice::Identity) const; ReferencePtr changeFacet(std::string) const; - ReferencePtr changeInvocationTimeout(int) const; + ReferencePtr changeInvocationTimeout(std::chrono::milliseconds) const; virtual ReferencePtr changeEncoding(Ice::EncodingVersion) const; virtual ReferencePtr changeCompress(bool) const; @@ -90,7 +90,7 @@ namespace IceInternal virtual ReferencePtr changeLocator(std::optional) const = 0; virtual ReferencePtr changeRouter(std::optional) const = 0; virtual ReferencePtr changeCollocationOptimized(bool) const = 0; - virtual ReferencePtr changeLocatorCacheTimeout(int) const = 0; + virtual ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const = 0; virtual ReferencePtr changeCacheConnection(bool) const = 0; virtual ReferencePtr changePreferSecure(bool) const = 0; virtual ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const = 0; @@ -150,7 +150,7 @@ namespace IceInternal std::optional, const Ice::ProtocolVersion&, const Ice::EncodingVersion&, - int, + std::chrono::milliseconds, const Ice::Context& ctx); Reference(const Reference&); @@ -167,7 +167,7 @@ namespace IceInternal std::string _facet; Ice::ProtocolVersion _protocol; Ice::EncodingVersion _encoding; - int _invocationTimeout; + std::chrono::milliseconds _invocationTimeout; }; class FixedReference final : public Reference @@ -184,7 +184,7 @@ namespace IceInternal const Ice::ProtocolVersion&, const Ice::EncodingVersion&, Ice::ConnectionIPtr, - int, + std::chrono::milliseconds, const Ice::Context&); FixedReference(const FixedReference&); @@ -195,7 +195,7 @@ namespace IceInternal bool getCacheConnection() const noexcept final; bool getPreferSecure() const noexcept final; Ice::EndpointSelectionType getEndpointSelection() const noexcept final; - int getLocatorCacheTimeout() const noexcept final; + std::chrono::milliseconds getLocatorCacheTimeout() const noexcept final; std::string getConnectionId() const final; ReferencePtr changeEndpoints(std::vector) const final; @@ -206,7 +206,7 @@ namespace IceInternal ReferencePtr changeCacheConnection(bool) const final; ReferencePtr changePreferSecure(bool) const final; ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const final; - ReferencePtr changeLocatorCacheTimeout(int) const final; + ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const final; ReferencePtr changeConnectionId(std::string) const final; ReferencePtr changeConnection(Ice::ConnectionIPtr) const final; @@ -252,8 +252,8 @@ namespace IceInternal bool, bool, Ice::EndpointSelectionType, - int, - int, + std::chrono::milliseconds, + std::chrono::milliseconds, const Ice::Context&); RoutableReference(const RoutableReference&); @@ -266,7 +266,7 @@ namespace IceInternal bool getCacheConnection() const noexcept final; bool getPreferSecure() const noexcept final; Ice::EndpointSelectionType getEndpointSelection() const noexcept final; - int getLocatorCacheTimeout() const noexcept final; + std::chrono::milliseconds getLocatorCacheTimeout() const noexcept final; std::string getConnectionId() const final; ReferencePtr changeEncoding(Ice::EncodingVersion) const final; @@ -280,7 +280,7 @@ namespace IceInternal ReferencePtr changeCacheConnection(bool) const final; ReferencePtr changePreferSecure(bool) const final; ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const final; - ReferencePtr changeLocatorCacheTimeout(int) const final; + ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const final; ReferencePtr changeConnectionId(std::string) const final; ReferencePtr changeConnection(Ice::ConnectionIPtr) const final; @@ -335,7 +335,7 @@ namespace IceInternal bool _cacheConnection; bool _preferSecure; Ice::EndpointSelectionType _endpointSelection; - int _locatorCacheTimeout; + std::chrono::milliseconds _locatorCacheTimeout; std::string _connectionId; }; diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 06031a2e689..9dc405137f2 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -21,6 +21,7 @@ #include "PropertyNames.h" #include "RouterInfo.h" +#include #include using namespace std; @@ -88,7 +89,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, const Ice::Connecti Ice::Protocol_1_0, _instance->defaultsAndOverrides()->defaultEncoding, connection, - -1, + -1ms, Ice::Context()); } @@ -774,8 +775,8 @@ IceInternal::ReferenceFactory::create( bool cacheConnection = true; bool preferSecure = defaultsAndOverrides->defaultPreferSecure; Ice::EndpointSelectionType endpointSelection = defaultsAndOverrides->defaultEndpointSelection; - int locatorCacheTimeout = defaultsAndOverrides->defaultLocatorCacheTimeout; - int invocationTimeout = defaultsAndOverrides->defaultInvocationTimeout; + chrono::seconds locatorCacheTimeout = defaultsAndOverrides->defaultLocatorCacheTimeout; + chrono::milliseconds invocationTimeout = defaultsAndOverrides->defaultInvocationTimeout; Ice::Context ctx; // @@ -852,34 +853,12 @@ IceInternal::ReferenceFactory::create( } property = propertyPrefix + ".LocatorCacheTimeout"; - string value = properties->getProperty(property); - if (!value.empty()) - { - locatorCacheTimeout = properties->getPropertyAsIntWithDefault(property, locatorCacheTimeout); - if (locatorCacheTimeout < -1) - { - locatorCacheTimeout = -1; - - Warning out(_instance->initializationData().logger); - out << "invalid value for " << property << "'" << properties->getProperty(property) << "'" - << ": defaulting to -1"; - } - } + locatorCacheTimeout = chrono::seconds( + properties->getPropertyAsIntWithDefault(property, static_cast(locatorCacheTimeout.count()))); property = propertyPrefix + ".InvocationTimeout"; - value = properties->getProperty(property); - if (!value.empty()) - { - invocationTimeout = properties->getPropertyAsIntWithDefault(property, invocationTimeout); - if (invocationTimeout < 1 && invocationTimeout != -1) - { - invocationTimeout = -1; - - Warning out(_instance->initializationData().logger); - out << "invalid value for " << property << "'" << properties->getProperty(property) << "'" - << ": defaulting to -1"; - } - } + invocationTimeout = chrono::milliseconds( + properties->getPropertyAsIntWithDefault(property, static_cast(invocationTimeout.count()))); property = propertyPrefix + ".Context."; PropertyDict contexts = properties->getPropertiesForPrefix(property); diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index b5dfc86333b..3937fc5e5fb 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -158,11 +158,8 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p _sizeMax(0), _sizeWarn(0), _serialize(_instance->initializationData().properties->getPropertyAsInt(_prefix + ".Serialize") > 0), - _hasPriority(false), - _priority(0), _serverIdleTime(timeout), _threadIdleTime(0), - _stackSize(0), _inUse(0), #if !defined(ICE_USE_IOCP) _inUseIO(0), @@ -254,32 +251,6 @@ IceInternal::ThreadPool::initialize() _selector.setup(_sizeIO); #endif -#if defined(__APPLE__) - // - // We use a default stack size of 1MB on macOS. The C++ mapping allows transmitting - // class graphs with a depth of 100 (maximum default), 512KB is not enough otherwise. - // - int defaultStackSize = 1024 * 1024; // 1MB -#else - int defaultStackSize = 0; -#endif - int stackSize = properties->getPropertyAsIntWithDefault(_prefix + ".StackSize", defaultStackSize); - if (stackSize < 0) - { - Warning out(_instance->initializationData().logger); - out << _prefix << ".StackSize < 0; Size adjusted to OS default"; - stackSize = 0; - } - const_cast(_stackSize) = static_cast(stackSize); - - const_cast(_hasPriority) = properties->getProperty(_prefix + ".ThreadPriority") != ""; - const_cast(_priority) = properties->getPropertyAsInt(_prefix + ".ThreadPriority"); - if (!_hasPriority) - { - const_cast(_hasPriority) = properties->getProperty("Ice.ThreadPriority") != ""; - const_cast(_priority) = properties->getPropertyAsInt("Ice.ThreadPriority"); - } - _workQueue = make_shared(*this); _selector.initialize(_workQueue.get()); diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h index f421ee07a92..82173eb7122 100644 --- a/cpp/src/Ice/ThreadPool.h +++ b/cpp/src/Ice/ThreadPool.h @@ -117,11 +117,8 @@ namespace IceInternal const int _sizeMax; // Maximum number of threads. const int _sizeWarn; // If _inUse reaches _sizeWarn, a "low on threads" warning will be printed. const bool _serialize; // True if requests need to be serialized over the connection. - const bool _hasPriority; - const int _priority; const int _serverIdleTime; const int _threadIdleTime; - const size_t _stackSize; std::set _threads; // All threads, running or not. int _inUse; // Number of threads that are currently in use. diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp index 52b367dab4d..d2ebd0a609a 100644 --- a/cpp/src/IceGrid/AdminI.cpp +++ b/cpp/src/IceGrid/AdminI.cpp @@ -93,17 +93,9 @@ namespace Ice::noExplicitContext); } - void useActivationTimeout() - { - auto timeout = secondsToInt(_activationTimeout) * 1000; - _proxy = _proxy->ice_invocationTimeout(timeout); - } + void useActivationTimeout() { _proxy = _proxy->ice_invocationTimeout(_activationTimeout); } - void useDeactivationTimeout() - { - auto timeout = secondsToInt(_deactivationTimeout) * 1000; - _proxy = _proxy->ice_invocationTimeout(timeout); - } + void useDeactivationTimeout() { _proxy = _proxy->ice_invocationTimeout(_deactivationTimeout); } ServerPrx* operator->() { return &_proxy; } diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index 587ffaa7077..99499eac4f8 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -464,7 +464,7 @@ NodeService::startImpl(int argc, char* argv[], int& status) { try { - communicator()->getDefaultLocator()->ice_invocationTimeout(1000)->ice_ping(); + communicator()->getDefaultLocator()->ice_invocationTimeout(1s)->ice_ping(); } catch (const Ice::Exception& ex) { diff --git a/cpp/src/IceGrid/LocatorI.cpp b/cpp/src/IceGrid/LocatorI.cpp index 7aaaa66dfb2..ec948c8e8cf 100644 --- a/cpp/src/IceGrid/LocatorI.cpp +++ b/cpp/src/IceGrid/LocatorI.cpp @@ -917,11 +917,11 @@ LocatorI::getDirectProxyException(const LocatorAdapterInfo& adapter, exception_p request->activating(adapter.id); } - int timeout = secondsToInt(adapter.activationTimeout + adapter.deactivationTimeout) * 1000; auto self = shared_from_this(); - adapter.proxy->ice_invocationTimeout(timeout)->activateAsync( - [self, adapter](auto obj) { self->getDirectProxyResponse(adapter, std::move(obj)); }, - [self, adapter](auto e) { self->getDirectProxyException(adapter, e); }); + adapter.proxy->ice_invocationTimeout(adapter.activationTimeout + adapter.deactivationTimeout) + ->activateAsync( + [self, adapter](auto obj) { self->getDirectProxyResponse(adapter, std::move(obj)); }, + [self, adapter](auto e) { self->getDirectProxyException(adapter, e); }); } else { diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp index f9dde9ad999..2efe8e259f4 100644 --- a/cpp/src/IceGrid/NodeCache.cpp +++ b/cpp/src/IceGrid/NodeCache.cpp @@ -334,8 +334,7 @@ NodeEntry::loadServer( // if (timeout > 0s) { - auto timeoutInMilliseconds = secondsToInt(timeout) * 1000; - node = node->ice_invocationTimeout(std::move(timeoutInMilliseconds)); + node = node->ice_invocationTimeout(timeout); } ServerInfo info = server; @@ -467,8 +466,7 @@ NodeEntry::destroyServer( // if (timeout > 0s) { - int timeoutInMilliseconds = secondsToInt(timeout) * 1000; - node = node->ice_invocationTimeout(timeoutInMilliseconds); + node = node->ice_invocationTimeout(timeout); } } diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index 0089293542f..10e3b8fc2a6 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -323,7 +323,7 @@ RegistryI::startImpl() { string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints"); string strPrx = _instanceName + "/Locator:" + endpoints; - _communicator->stringToProxy(strPrx)->ice_invocationTimeout(5000)->ice_ping(); + _communicator->stringToProxy(strPrx)->ice_invocationTimeout(5s)->ice_ping(); Error out(_communicator->getLogger()); out << "an IceGrid registry is already running and listening on the client endpoints `" << endpoints << "'"; diff --git a/cpp/src/IceGrid/ReplicaSessionI.cpp b/cpp/src/IceGrid/ReplicaSessionI.cpp index be36ebb1be4..f9d82836d0c 100644 --- a/cpp/src/IceGrid/ReplicaSessionI.cpp +++ b/cpp/src/IceGrid/ReplicaSessionI.cpp @@ -224,14 +224,13 @@ ReplicaSessionI::setAdapterDirectProxy( string adapterId, string replicaGroupId, optional proxy, - const Ice::Current& current) + const Ice::Current&) { - Ice::checkNotNull(proxy, __FILE__, __LINE__, current); if (_database->getCommunicator()->getProperties()->getPropertyAsInt("IceGrid.Registry.DynamicRegistration") <= 0) { throw AdapterNotExistException(); } - _database->setAdapterDirectProxy(adapterId, replicaGroupId, *std::move(proxy)); + _database->setAdapterDirectProxy(adapterId, replicaGroupId, proxy); } void diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp index 6ffcbec9698..1ae21618e8a 100644 --- a/cpp/src/IceGrid/Util.cpp +++ b/cpp/src/IceGrid/Util.cpp @@ -363,7 +363,7 @@ IceGrid::getMMVersion(const string& o) int IceGrid::secondsToInt(const std::chrono::seconds& sec) { - return chrono::duration_cast>(sec).count(); + return static_cast(sec.count()); } void diff --git a/cpp/src/IceStorm/Subscriber.cpp b/cpp/src/IceStorm/Subscriber.cpp index f0d5a5ef4a3..ca73a184b80 100644 --- a/cpp/src/IceStorm/Subscriber.cpp +++ b/cpp/src/IceStorm/Subscriber.cpp @@ -297,8 +297,8 @@ namespace { SubscriberLink::SubscriberLink(const shared_ptr& instance, const SubscriberRecord& rec) : Subscriber(instance, rec, nullopt, -1, 1), - _obj(Ice::uncheckedCast(rec.obj->ice_collocationOptimized(false)->ice_invocationTimeout( - static_cast(instance->sendTimeout().count())))) + _obj(Ice::uncheckedCast( + rec.obj->ice_collocationOptimized(false)->ice_invocationTimeout(instance->sendTimeout()))) { } @@ -414,7 +414,7 @@ Subscriber::create(const shared_ptr& instance, const SubscriberRecord& optional newObj; try { - newObj = rec.obj->ice_invocationTimeout(static_cast(instance->sendTimeout().count())); + newObj = rec.obj->ice_invocationTimeout(instance->sendTimeout()); } catch (const Ice::FixedProxyException&) { diff --git a/cpp/test/Ice/location/AllTests.cpp b/cpp/test/Ice/location/AllTests.cpp index 4160f2d1fc7..0a96e77d915 100644 --- a/cpp/test/Ice/location/AllTests.cpp +++ b/cpp/test/Ice/location/AllTests.cpp @@ -270,7 +270,7 @@ allTests(Test::TestHelper* helper, const string& ref) ObjectPrx(communicator, "test")->ice_ping(); test(count == locator->getRequestCount()); - test(ObjectPrx(communicator, "test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99); + test(ObjectPrx(communicator, "test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99s); cout << "ok" << endl; diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index d569975f78e..c041a2d774c 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -455,10 +455,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1->ice_getLocatorCacheTimeout() == -1); + test(b1->ice_getLocatorCacheTimeout() == -1s); prop->setProperty(property, "1"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getLocatorCacheTimeout() == 1); + test(b1->ice_getLocatorCacheTimeout() == 1s); prop->setProperty(property, ""); // Now retest with an indirect proxy. @@ -470,10 +470,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1->ice_getLocatorCacheTimeout() == -1); + test(b1->ice_getLocatorCacheTimeout() == -1s); prop->setProperty(property, "1"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getLocatorCacheTimeout() == 1); + test(b1->ice_getLocatorCacheTimeout() == 1s); prop->setProperty(property, ""); // This cannot be tested so easily because the property is cached @@ -508,10 +508,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".InvocationTimeout"; - test(b1->ice_getInvocationTimeout() == -1); + test(b1->ice_getInvocationTimeout() == -1ms); prop->setProperty(property, "1000"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getInvocationTimeout() == 1000); + test(b1->ice_getInvocationTimeout() == 1s); prop->setProperty(property, ""); property = propertyPrefix + ".EndpointSelection"; @@ -635,59 +635,27 @@ allTests(TestHelper* helper) test(base->ice_encodingVersion(Ice::Encoding_1_1)->ice_getEncodingVersion() == Ice::Encoding_1_1); test(base->ice_encodingVersion(Ice::Encoding_1_0)->ice_getEncodingVersion() != Ice::Encoding_1_1); - try - { - base->ice_invocationTimeout(0); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_invocationTimeout(10)->ice_getInvocationTimeout() == 10ms); - try - { - base->ice_invocationTimeout(-1); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_invocationTimeout(0)->ice_getInvocationTimeout() == 0ms); + test(base->ice_invocationTimeout(0ms)->ice_getInvocationTimeout() == 0ms); - try - { - base->ice_invocationTimeout(-2); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_invocationTimeout(-1)->ice_getInvocationTimeout() == -1ms); + test(base->ice_invocationTimeout(-1ms)->ice_getInvocationTimeout() == -1ms); - try - { - base->ice_locatorCacheTimeout(0); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_invocationTimeout(-2)->ice_getInvocationTimeout() == -2ms); + test(base->ice_invocationTimeout(-2ms)->ice_getInvocationTimeout() == -2ms); - try - { - base->ice_locatorCacheTimeout(-1); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_locatorCacheTimeout(10)->ice_getLocatorCacheTimeout() == 10s); - try - { - base->ice_locatorCacheTimeout(-2); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_locatorCacheTimeout(0)->ice_getLocatorCacheTimeout() == 0s); + test(base->ice_locatorCacheTimeout(0s)->ice_getLocatorCacheTimeout() == 0s); + + test(base->ice_locatorCacheTimeout(-1)->ice_getLocatorCacheTimeout() == -1s); + test(base->ice_locatorCacheTimeout(-1s)->ice_getLocatorCacheTimeout() == -1s); + + test(base->ice_locatorCacheTimeout(-2)->ice_getLocatorCacheTimeout() == -2s); + test(base->ice_locatorCacheTimeout(-2s)->ice_getLocatorCacheTimeout() == -2s); cout << "ok" << endl; @@ -922,8 +890,8 @@ allTests(TestHelper* helper) ctx["two"] = "world"; test(cl->ice_fixed(connection)->ice_getContext().empty()); test(cl->ice_context(ctx)->ice_fixed(connection)->ice_getContext().size() == 2); - test(cl->ice_fixed(connection)->ice_getInvocationTimeout() == -1); - test(cl->ice_invocationTimeout(10)->ice_fixed(connection)->ice_getInvocationTimeout() == 10); + test(cl->ice_fixed(connection)->ice_getInvocationTimeout() == -1ms); + test(cl->ice_invocationTimeout(10)->ice_fixed(connection)->ice_getInvocationTimeout() == 10ms); test(cl->ice_fixed(connection)->ice_getConnection() == connection); test(cl->ice_fixed(connection)->ice_fixed(connection)->ice_getConnection() == connection); test(*cl->ice_compress(true)->ice_fixed(connection)->ice_getCompress()); @@ -1234,7 +1202,6 @@ allTests(TestHelper* helper) // Test with WS endpoint p = communicator->stringToProxy("test -t -e 1.0:ws -h localhost -p 10001 -t 20000 -r /path"); pstr = communicator->proxyToString(p); - cerr << pstr << endl; test(pstr == "test -t -e 1.0:ws -h localhost -p 10001 -t 20000 -r /path"); } std::locale::global(currentLocale); diff --git a/csharp/src/Ice/Internal/CollocatedRequestHandler.cs b/csharp/src/Ice/Internal/CollocatedRequestHandler.cs index f8044b48aaf..631e7e1088c 100644 --- a/csharp/src/Ice/Internal/CollocatedRequestHandler.cs +++ b/csharp/src/Ice/Internal/CollocatedRequestHandler.cs @@ -97,7 +97,7 @@ internal int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestCoun } outAsync.attachCollocatedObserver(_adapter, requestId); - if (!synchronous || !_response || _reference.getInvocationTimeout() > 0) + if (!synchronous || !_response || _reference.getInvocationTimeout() > TimeSpan.Zero) { // Don't invoke from the user thread if async or invocation timeout is set _adapter.getThreadPool().execute( diff --git a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs index b58932b2ecf..095d654f194 100644 --- a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs +++ b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs @@ -80,25 +80,10 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) throw new ParseException($"illegal value '{val}' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); } - defaultLocatorCacheTimeout = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); - if (defaultLocatorCacheTimeout < -1) - { - defaultLocatorCacheTimeout = -1; - StringBuilder msg = new StringBuilder("invalid value for Ice.Default.LocatorCacheTimeout `"); - msg.Append(properties.getIceProperty("Ice.Default.LocatorCacheTimeout")); - msg.Append("': defaulting to -1"); - logger.warning(msg.ToString()); - } - - defaultInvocationTimeout = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); - if (defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1) - { - defaultInvocationTimeout = -1; - StringBuilder msg = new StringBuilder("invalid value for Ice.Default.InvocationTimeout `"); - msg.Append(properties.getIceProperty("Ice.Default.InvocationTimeout")); - msg.Append("': defaulting to -1"); - logger.warning(msg.ToString()); - } + defaultLocatorCacheTimeout = TimeSpan.FromSeconds( + properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); + defaultInvocationTimeout = TimeSpan.FromMilliseconds( + properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout")); defaultPreferSecure = properties.getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; @@ -117,8 +102,8 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) public string defaultProtocol; public bool defaultCollocationOptimization; public Ice.EndpointSelectionType defaultEndpointSelection; - public int defaultLocatorCacheTimeout; - public int defaultInvocationTimeout; + public TimeSpan defaultLocatorCacheTimeout; + public TimeSpan defaultInvocationTimeout; public bool defaultPreferSecure; public Ice.EncodingVersion defaultEncoding; public Ice.FormatType defaultFormat; diff --git a/csharp/src/Ice/Internal/LocatorInfo.cs b/csharp/src/Ice/Internal/LocatorInfo.cs index fd61aa8a5e6..5f2eee0eb05 100644 --- a/csharp/src/Ice/Internal/LocatorInfo.cs +++ b/csharp/src/Ice/Internal/LocatorInfo.cs @@ -80,7 +80,7 @@ public void } public - RequestCallback(Reference @ref, int ttl, GetEndpointsCallback cb) + RequestCallback(Reference @ref, TimeSpan ttl, GetEndpointsCallback cb) { _ref = @ref; _ttl = ttl; @@ -88,14 +88,14 @@ public void } private readonly Reference _ref; - private readonly int _ttl; + private readonly TimeSpan _ttl; private readonly GetEndpointsCallback _callback; } private abstract class Request { public void - addCallback(Reference @ref, Reference wellKnownRef, int ttl, GetEndpointsCallback cb) + addCallback(Reference @ref, Reference wellKnownRef, TimeSpan ttl, GetEndpointsCallback cb) { RequestCallback callback = new RequestCallback(@ref, ttl, cb); lock (_mutex) @@ -304,13 +304,13 @@ public Ice.LocatorRegistryPrx getLocatorRegistry() } public void - getEndpoints(Reference @ref, int ttl, GetEndpointsCallback callback) + getEndpoints(Reference @ref, TimeSpan ttl, GetEndpointsCallback callback) { getEndpoints(@ref, null, ttl, callback); } public void - getEndpoints(Reference @ref, Reference wellKnownRef, int ttl, GetEndpointsCallback callback) + getEndpoints(Reference @ref, Reference wellKnownRef, TimeSpan ttl, GetEndpointsCallback callback) { Debug.Assert(@ref.isIndirect()); EndpointI[] endpoints = null; @@ -803,9 +803,9 @@ internal void clear() } } - internal EndpointI[] getAdapterEndpoints(string adapter, int ttl, out bool cached) + internal EndpointI[] getAdapterEndpoints(string adapter, TimeSpan ttl, out bool cached) { - if (ttl == 0) // Locator cache disabled. + if (ttl == TimeSpan.Zero) // Locator cache disabled. { cached = false; return null; @@ -847,9 +847,9 @@ internal EndpointI[] removeAdapterEndpoints(string adapter) } } - internal Reference getObjectReference(Ice.Identity id, int ttl, out bool cached) + internal Reference getObjectReference(Ice.Identity id, TimeSpan ttl, out bool cached) { - if (ttl == 0) // Locator cache disabled. + if (ttl == TimeSpan.Zero) // Locator cache disabled. { cached = false; return null; @@ -890,16 +890,16 @@ internal Reference removeObjectReference(Ice.Identity id) } } - private bool checkTTL(long time, int ttl) + private bool checkTTL(long time, TimeSpan ttl) { - Debug.Assert(ttl != 0); - if (ttl < 0) // TTL = infinite + Debug.Assert(ttl != TimeSpan.Zero); + if (ttl < TimeSpan.Zero) // TTL = infinite { return true; } else { - return Time.currentMonotonicTimeMillis() - time <= ((long)ttl * 1000); + return Time.currentMonotonicTimeMillis() - time <= ttl.TotalMilliseconds; } } diff --git a/csharp/src/Ice/Internal/OutgoingAsync.cs b/csharp/src/Ice/Internal/OutgoingAsync.cs index 930746c39ac..df6d8ba95c5 100644 --- a/csharp/src/Ice/Internal/OutgoingAsync.cs +++ b/csharp/src/Ice/Internal/OutgoingAsync.cs @@ -520,10 +520,10 @@ protected void invokeImpl(bool userThread) { if (userThread) { - int invocationTimeout = proxy_.iceReference().getInvocationTimeout(); - if (invocationTimeout > 0) + TimeSpan invocationTimeout = proxy_.iceReference().getInvocationTimeout(); + if (invocationTimeout > TimeSpan.Zero) { - instance_.timer().schedule(this, invocationTimeout); + instance_.timer().schedule(this, (long)invocationTimeout.TotalMilliseconds); } } else if (observer_ != null) @@ -606,7 +606,7 @@ protected override bool sentImpl(bool done) _sent = true; if (done) { - if (proxy_.iceReference().getInvocationTimeout() != -1) + if (proxy_.iceReference().getInvocationTimeout() > TimeSpan.Zero) { instance_.timer().cancel(this); } @@ -616,7 +616,7 @@ protected override bool sentImpl(bool done) protected override bool exceptionImpl(Ice.Exception ex) { - if (proxy_.iceReference().getInvocationTimeout() != -1) + if (proxy_.iceReference().getInvocationTimeout() > TimeSpan.Zero) { instance_.timer().cancel(this); } @@ -625,7 +625,7 @@ protected override bool exceptionImpl(Ice.Exception ex) protected override bool responseImpl(bool userThread, bool ok, bool invoke) { - if (proxy_.iceReference().getInvocationTimeout() != -1) + if (proxy_.iceReference().getInvocationTimeout() > TimeSpan.Zero) { instance_.timer().cancel(this); } @@ -1040,7 +1040,7 @@ public override int invokeRemote(Ice.ConnectionI connection, bool compress, bool public override int invokeCollocated(CollocatedRequestHandler handler) { // The stream cannot be cached if the proxy is not a twoway or there is an invocation timeout set. - if (!proxy_.ice_isTwoway() || proxy_.iceReference().getInvocationTimeout() != -1) + if (!proxy_.ice_isTwoway() || proxy_.iceReference().getInvocationTimeout() > TimeSpan.Zero) { // Disable caching by marking the streams as cached! state_ |= StateCachedBuffers; diff --git a/csharp/src/Ice/Internal/PropertyNames.cs b/csharp/src/Ice/Internal/PropertyNames.cs index 8438cfb566f..5e8f31ac311 100644 --- a/csharp/src/Ice/Internal/PropertyNames.cs +++ b/csharp/src/Ice/Internal/PropertyNames.cs @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -// Generated by makeprops.py from PropertyNames.xml, Thu Sep 26 17:31:37 2024 +// Generated by makeprops.py from PropertyNames.xml, Fri Sep 27 14:21:19 2024 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/csharp/src/Ice/Internal/Reference.cs b/csharp/src/Ice/Internal/Reference.cs index f94b06a3aae..99a819bd76a 100644 --- a/csharp/src/Ice/Internal/Reference.cs +++ b/csharp/src/Ice/Internal/Reference.cs @@ -92,7 +92,7 @@ public Dictionary getContext() return _context; } - public int + public TimeSpan getInvocationTimeout() { return _invocationTimeout; @@ -125,7 +125,7 @@ public Ice.Communicator getCommunicator() public abstract Ice.EndpointSelectionType getEndpointSelection(); - public abstract int getLocatorCacheTimeout(); + public abstract TimeSpan getLocatorCacheTimeout(); public abstract string getConnectionId(); @@ -185,7 +185,7 @@ public Reference changeFacet(string newFacet) return r; } - public Reference changeInvocationTimeout(int newTimeout) + public Reference changeInvocationTimeout(TimeSpan newTimeout) { Reference r = _instance.referenceFactory().copy(this); r._invocationTimeout = newTimeout; @@ -222,7 +222,7 @@ public virtual Reference changeCompress(bool newCompress) public abstract Reference changeEndpointSelection(Ice.EndpointSelectionType newType); - public abstract Reference changeLocatorCacheTimeout(int newTimeout); + public abstract Reference changeLocatorCacheTimeout(TimeSpan newTimeout); public abstract Reference changeConnectionId(string connectionId); @@ -446,7 +446,7 @@ public virtual bool Equals(Reference other) protected bool secure_; private Ice.ProtocolVersion _protocol; private Ice.EncodingVersion _encoding; - private int _invocationTimeout; + private TimeSpan _invocationTimeout; private bool? _compress; protected Reference( @@ -459,7 +459,7 @@ protected Reference( bool? compress, Ice.ProtocolVersion protocol, Ice.EncodingVersion encoding, - int invocationTimeout, + TimeSpan invocationTimeout, Dictionary context) { // Validate string arguments. @@ -496,7 +496,7 @@ public FixedReference( Ice.ProtocolVersion protocol, Ice.EncodingVersion encoding, Ice.ConnectionI connection, - int invocationTimeout, + TimeSpan invocationTimeout, Dictionary context) : base(instance, communicator, identity, facet, mode, secure, compress, protocol, encoding, invocationTimeout, context) { @@ -543,9 +543,9 @@ public override Ice.EndpointSelectionType getEndpointSelection() return Ice.EndpointSelectionType.Random; } - public override int getLocatorCacheTimeout() + public override TimeSpan getLocatorCacheTimeout() { - return 0; + return TimeSpan.Zero; } public override string getConnectionId() @@ -603,7 +603,7 @@ public override Reference changeEndpointSelection(Ice.EndpointSelectionType newT throw new Ice.FixedProxyException(); } - public override Reference changeLocatorCacheTimeout(int newTimeout) + public override Reference changeLocatorCacheTimeout(TimeSpan newTimeout) { throw new Ice.FixedProxyException(); } @@ -756,7 +756,7 @@ public override Ice.EndpointSelectionType getEndpointSelection() return _endpointSelection; } - public override int getLocatorCacheTimeout() + public override TimeSpan getLocatorCacheTimeout() { return _locatorCacheTimeout; } @@ -872,7 +872,7 @@ public override Reference changeEndpointSelection(Ice.EndpointSelectionType newT return r; } - public override Reference changeLocatorCacheTimeout(int newTimeout) + public override Reference changeLocatorCacheTimeout(TimeSpan newTimeout) { RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); r._locatorCacheTimeout = newTimeout; @@ -1000,8 +1000,8 @@ public override Dictionary toProperty(string prefix) properties[prefix + ".PreferSecure"] = _preferSecure ? "1" : "0"; properties[prefix + ".EndpointSelection"] = _endpointSelection == Ice.EndpointSelectionType.Random ? "Random" : "Ordered"; - properties[prefix + ".LocatorCacheTimeout"] = _locatorCacheTimeout.ToString(CultureInfo.InvariantCulture); - properties[prefix + ".InvocationTimeout"] = getInvocationTimeout().ToString(CultureInfo.InvariantCulture); + properties[prefix + ".LocatorCacheTimeout"] = _locatorCacheTimeout.TotalSeconds.ToString(CultureInfo.InvariantCulture); + properties[prefix + ".InvocationTimeout"] = getInvocationTimeout().TotalMilliseconds.ToString(CultureInfo.InvariantCulture); if (_routerInfo != null) { @@ -1243,8 +1243,8 @@ public RoutableReference( bool cacheConnection, bool preferSecure, Ice.EndpointSelectionType endpointSelection, - int locatorCacheTimeout, - int invocationTimeout, + TimeSpan locatorCacheTimeout, + TimeSpan invocationTimeout, Dictionary context) : base( instance, @@ -1577,7 +1577,7 @@ public int Compare(EndpointI le, EndpointI re) private bool _cacheConnection; private bool _preferSecure; private Ice.EndpointSelectionType _endpointSelection; - private int _locatorCacheTimeout; + private TimeSpan _locatorCacheTimeout; private string _connectionId = ""; } diff --git a/csharp/src/Ice/Internal/ReferenceFactory.cs b/csharp/src/Ice/Internal/ReferenceFactory.cs index b43e3254261..79b0b69da4c 100644 --- a/csharp/src/Ice/Internal/ReferenceFactory.cs +++ b/csharp/src/Ice/Internal/ReferenceFactory.cs @@ -72,7 +72,7 @@ internal Reference create(Ice.Identity ident, Ice.ConnectionI connection) Ice.Util.Protocol_1_0, _instance.defaultsAndOverrides().defaultEncoding, connection, - -1, + TimeSpan.FromMilliseconds(-1), null); } @@ -725,8 +725,8 @@ private Reference create( bool cacheConnection = true; bool preferSecure = defaultsAndOverrides.defaultPreferSecure; Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection; - int locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; - int invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; + TimeSpan locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; + TimeSpan invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; Dictionary context = null; // @@ -805,40 +805,12 @@ private Reference create( } property = propertyPrefix + ".LocatorCacheTimeout"; - string val = properties.getProperty(property); - if (val.Length > 0) - { - locatorCacheTimeout = properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout); - if (locatorCacheTimeout < -1) - { - locatorCacheTimeout = -1; - - StringBuilder msg = new StringBuilder("invalid value for "); - msg.Append(property); - msg.Append(" `"); - msg.Append(properties.getProperty(property)); - msg.Append("': defaulting to -1"); - _instance.initializationData().logger.warning(msg.ToString()); - } - } + locatorCacheTimeout = TimeSpan.FromSeconds( + properties.getPropertyAsIntWithDefault(property, (int)locatorCacheTimeout.TotalSeconds)); property = propertyPrefix + ".InvocationTimeout"; - val = properties.getProperty(property); - if (val.Length > 0) - { - invocationTimeout = properties.getPropertyAsIntWithDefault(property, invocationTimeout); - if (invocationTimeout < 1 && invocationTimeout != -1) - { - invocationTimeout = -1; - - StringBuilder msg = new StringBuilder("invalid value for "); - msg.Append(property); - msg.Append(" `"); - msg.Append(properties.getProperty(property)); - msg.Append("': defaulting to -1"); - _instance.initializationData().logger.warning(msg.ToString()); - } - } + invocationTimeout = TimeSpan.FromMilliseconds( + properties.getPropertyAsIntWithDefault(property, (int)invocationTimeout.TotalMilliseconds)); property = propertyPrefix + ".Context."; Dictionary contexts = properties.getPropertiesForPrefix(property); diff --git a/csharp/src/Ice/Proxy.cs b/csharp/src/Ice/Proxy.cs index 71a984588cf..c1f4f59015e 100644 --- a/csharp/src/Ice/Proxy.cs +++ b/csharp/src/Ice/Proxy.cs @@ -210,8 +210,8 @@ bool ice_invoke( /// /// Returns the locator cache timeout of this proxy. /// - /// The locator cache timeout value (in seconds). - int ice_getLocatorCacheTimeout(); + /// The locator cache timeout value. + TimeSpan ice_getLocatorCacheTimeout(); /// /// Creates a new proxy that is identical to this proxy, except for the locator cache timeout. @@ -219,17 +219,29 @@ bool ice_invoke( /// The new locator cache timeout (in seconds). ObjectPrx ice_locatorCacheTimeout(int newTimeout); + /// + /// Creates a new proxy that is identical to this proxy, except for the locator cache timeout. + /// + /// The new locator cache timeout. + ObjectPrx ice_locatorCacheTimeout(TimeSpan newTimeout); + /// /// Creates a new proxy that is identical to this proxy, except for the invocation timeout. /// - /// The new invocation timeout (in seconds). + /// The new invocation timeout (in milliseconds). ObjectPrx ice_invocationTimeout(int newTimeout); + /// + /// Creates a new proxy that is identical to this proxy, except for the invocation timeout. + /// + /// The new invocation timeout. + ObjectPrx ice_invocationTimeout(TimeSpan newTimeout); + /// /// Returns the invocation timeout of this proxy. /// - /// The invocation timeout value (in seconds). - int ice_getInvocationTimeout(); + /// The invocation timeout value. + TimeSpan ice_getInvocationTimeout(); /// /// Returns whether this proxy caches connections. @@ -1033,8 +1045,8 @@ public ObjectPrx ice_endpoints(Endpoint[] newEndpoints) /// /// Returns the locator cache timeout of this proxy. /// - /// The locator cache timeout value (in seconds). - public int ice_getLocatorCacheTimeout() + /// The locator cache timeout value. + public TimeSpan ice_getLocatorCacheTimeout() { return _reference.getLocatorCacheTimeout(); } @@ -1046,10 +1058,16 @@ public int ice_getLocatorCacheTimeout() /// The new proxy with the specified locator cache timeout. public ObjectPrx ice_locatorCacheTimeout(int newTimeout) { - if (newTimeout < -1) - { - throw new ArgumentException("invalid value passed to ice_locatorCacheTimeout: " + newTimeout); - } + return ice_locatorCacheTimeout(TimeSpan.FromSeconds(newTimeout)); + } + + /// + /// Creates a new proxy that is identical to this proxy, except for the locator cache timeout. + /// + /// The new locator cache timeout. + /// The new proxy with the specified locator cache timeout. + public ObjectPrx ice_locatorCacheTimeout(TimeSpan newTimeout) + { if (newTimeout == _reference.getLocatorCacheTimeout()) { return this; @@ -1063,8 +1081,8 @@ public ObjectPrx ice_locatorCacheTimeout(int newTimeout) /// /// Returns the invocation timeout of this proxy. /// - /// The invocation timeout value (in seconds). - public int ice_getInvocationTimeout() + /// The invocation timeout value. + public TimeSpan ice_getInvocationTimeout() { return _reference.getInvocationTimeout(); } @@ -1072,14 +1090,20 @@ public int ice_getInvocationTimeout() /// /// Creates a new proxy that is identical to this proxy, except for the invocation timeout. /// - /// The new invocation timeout (in seconds). + /// The new invocation timeout (in milliseconds). /// The new proxy with the specified invocation timeout. public ObjectPrx ice_invocationTimeout(int newTimeout) { - if (newTimeout < 1 && newTimeout != -1) - { - throw new ArgumentException("invalid value passed to ice_invocationTimeout: " + newTimeout); - } + return ice_invocationTimeout(TimeSpan.FromMilliseconds(newTimeout)); + } + + /// + /// Creates a new proxy that is identical to this proxy, except for the invocation timeout. + /// + /// The new invocation timeout. + /// The new proxy with the specified invocation timeout. + public ObjectPrx ice_invocationTimeout(TimeSpan newTimeout) + { if (newTimeout == _reference.getInvocationTimeout()) { return this; diff --git a/csharp/test/Ice/location/AllTests.cs b/csharp/test/Ice/location/AllTests.cs index 754b28d6927..68f10a8c308 100644 --- a/csharp/test/Ice/location/AllTests.cs +++ b/csharp/test/Ice/location/AllTests.cs @@ -245,7 +245,7 @@ public static async Task allTests(global::Test.TestHelper helper) communicator.stringToProxy("test").ice_ping(); test(count == locator.getRequestCount()); - test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99); + test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); diff --git a/csharp/test/Ice/proxy/AllTests.cs b/csharp/test/Ice/proxy/AllTests.cs index c0238e5da4a..486d3f3dc51 100644 --- a/csharp/test/Ice/proxy/AllTests.cs +++ b/csharp/test/Ice/proxy/AllTests.cs @@ -403,10 +403,10 @@ public class AllTests : global::Test.AllTests test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name == "locator"); prop.setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1.ice_getLocatorCacheTimeout() == -1); + test(b1.ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(-1)); prop.setProperty(property, "1"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getLocatorCacheTimeout() == 1); + test(b1.ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(1)); prop.setProperty(property, ""); // Now retest with an indirect proxy. @@ -418,10 +418,10 @@ public class AllTests : global::Test.AllTests prop.setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1.ice_getLocatorCacheTimeout() == -1); + test(b1.ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(-1)); prop.setProperty(property, "1"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getLocatorCacheTimeout() == 1); + test(b1.ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(1)); prop.setProperty(property, ""); // This cannot be tested so easily because the property is cached @@ -456,10 +456,10 @@ public class AllTests : global::Test.AllTests prop.setProperty(property, ""); property = propertyPrefix + ".InvocationTimeout"; - test(b1.ice_getInvocationTimeout() == -1); + test(b1.ice_getInvocationTimeout() == TimeSpan.FromMilliseconds(-1)); prop.setProperty(property, "1000"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getInvocationTimeout() == 1000); + test(b1.ice_getInvocationTimeout() == TimeSpan.FromSeconds(1)); prop.setProperty(property, ""); property = propertyPrefix + ".EndpointSelection"; @@ -582,59 +582,13 @@ public class AllTests : global::Test.AllTests test(baseProxy.ice_preferSecure(true).ice_isPreferSecure()); test(!baseProxy.ice_preferSecure(false).ice_isPreferSecure()); - try - { - baseProxy.ice_invocationTimeout(0); - test(false); - } - catch (ArgumentException) - { - } - - try - { - baseProxy.ice_invocationTimeout(-1); - } - catch (ArgumentException) - { - test(false); - } - - try - { - baseProxy.ice_invocationTimeout(-2); - test(false); - } - catch (ArgumentException) - { - } + test(baseProxy.ice_invocationTimeout(0).ice_getInvocationTimeout() == TimeSpan.Zero); + test(baseProxy.ice_invocationTimeout(-1).ice_getInvocationTimeout() == TimeSpan.FromMilliseconds(-1)); + test(baseProxy.ice_invocationTimeout(-2).ice_getInvocationTimeout() == TimeSpan.FromMilliseconds(-2)); - try - { - baseProxy.ice_locatorCacheTimeout(0); - } - catch (ArgumentException) - { - test(false); - } - - try - { - baseProxy.ice_locatorCacheTimeout(-1); - } - catch (ArgumentException) - { - test(false); - } - - try - { - baseProxy.ice_locatorCacheTimeout(-2); - test(false); - } - catch (ArgumentException) - { - } + test(baseProxy.ice_locatorCacheTimeout(0).ice_getLocatorCacheTimeout() == TimeSpan.Zero); + test(baseProxy.ice_locatorCacheTimeout(-1).ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(-1)); + test(baseProxy.ice_locatorCacheTimeout(-2).ice_getLocatorCacheTimeout() == TimeSpan.FromSeconds(-2)); output.WriteLine("ok"); @@ -792,8 +746,8 @@ public class AllTests : global::Test.AllTests ctx["two"] = "world"; test(cl.ice_fixed(connection).ice_getContext().Count == 0); test(cl.ice_context(ctx).ice_fixed(connection).ice_getContext().Count == 2); - test(cl.ice_fixed(connection).ice_getInvocationTimeout() == -1); - test(cl.ice_invocationTimeout(10).ice_fixed(connection).ice_getInvocationTimeout() == 10); + test(cl.ice_fixed(connection).ice_getInvocationTimeout() == TimeSpan.FromMilliseconds(-1)); + test(cl.ice_invocationTimeout(10).ice_fixed(connection).ice_getInvocationTimeout() == TimeSpan.FromMilliseconds(10)); test(cl.ice_fixed(connection).ice_getConnection() == connection); test(cl.ice_fixed(connection).ice_fixed(connection).ice_getConnection() == connection); test(cl.ice_compress(true).ice_fixed(connection).ice_getCompress().Value); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java b/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java index 55b6c85af1c..dbbad293643 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java @@ -4,6 +4,7 @@ package com.zeroc.Ice; +import java.time.Duration; import java.util.concurrent.CompletionStage; final class CollocatedRequestHandler implements RequestHandler { @@ -110,7 +111,7 @@ int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, boolean if (!sync || !_response || _reference.getInstance().queueRequests() - || _reference.getInvocationTimeout() > 0) { + || _reference.getInvocationTimeout().compareTo(Duration.ZERO) > 0) { _adapter.getThreadPool() .dispatch( new InvokeAllAsync( diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java index 026e909ac05..a835051b0a5 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/DefaultsAndOverrides.java @@ -4,8 +4,10 @@ package com.zeroc.Ice; +import java.time.Duration; + final class DefaultsAndOverrides { - DefaultsAndOverrides(Properties properties, Logger logger) { + DefaultsAndOverrides(Properties properties) { String value; int intValue; @@ -65,29 +67,12 @@ final class DefaultsAndOverrides { + "' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); } - intValue = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); - if (intValue < -1) { - defaultLocatorCacheTimeout = -1; - StringBuffer msg = - new StringBuffer("invalid value for Ice.Default.LocatorCacheTimeout `"); - msg.append(properties.getIceProperty("Ice.Default.LocatorCacheTimeout")); - msg.append("': defaulting to -1"); - logger.warning(msg.toString()); - } else { - defaultLocatorCacheTimeout = intValue; - } + defaultLocatorCacheTimeout = + Duration.ofSeconds( + properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); - intValue = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout"); - if (intValue < 1 && intValue != -1) { - defaultInvocationTimeout = -1; - StringBuffer msg = - new StringBuffer("invalid value for Ice.Default.InvocationTimeout `"); - msg.append(properties.getIceProperty("Ice.Default.InvocationTimeout")); - msg.append("': defaulting to -1"); - logger.warning(msg.toString()); - } else { - defaultInvocationTimeout = intValue; - } + defaultInvocationTimeout = + Duration.ofMillis(properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout")); defaultPreferSecure = properties.getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; @@ -107,8 +92,8 @@ final class DefaultsAndOverrides { public final String defaultProtocol; public final boolean defaultCollocationOptimization; public final EndpointSelectionType defaultEndpointSelection; - public final int defaultLocatorCacheTimeout; - public final int defaultInvocationTimeout; + public final Duration defaultLocatorCacheTimeout; + public final Duration defaultInvocationTimeout; public final boolean defaultPreferSecure; public final EncodingVersion defaultEncoding; public final FormatType defaultFormat; diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/FixedReference.java b/java/src/Ice/src/main/java/com/zeroc/Ice/FixedReference.java index 61698e2909f..c96f64c48ed 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/FixedReference.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/FixedReference.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + public class FixedReference extends Reference { public FixedReference( Instance instance, @@ -16,7 +18,7 @@ public FixedReference( ProtocolVersion protocol, EncodingVersion encoding, ConnectionI connection, - int invocationTimeout, + Duration invocationTimeout, java.util.Map context) { super( instance, @@ -74,8 +76,8 @@ public final EndpointSelectionType getEndpointSelection() { } @Override - public int getLocatorCacheTimeout() { - return 0; + public Duration getLocatorCacheTimeout() { + return Duration.ZERO; } @Override @@ -134,7 +136,7 @@ public final Reference changeEndpointSelection(EndpointSelectionType newType) { } @Override - public Reference changeLocatorCacheTimeout(int newTimeout) { + public Reference changeLocatorCacheTimeout(Duration newTimeout) { throw new FixedProxyException(); } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Instance.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Instance.java index 368822314c7..6664393e2e8 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Instance.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Instance.java @@ -772,7 +772,7 @@ public void initialize(Communicator communicator, InitializationData initData) { _traceLevels = new TraceLevels(properties); - _defaultsAndOverrides = new DefaultsAndOverrides(properties, _initData.logger); + _defaultsAndOverrides = new DefaultsAndOverrides(properties); _clientConnectionOptions = readConnectionOptions("Ice.Connection.Client"); _serverConnectionOptions = readConnectionOptions("Ice.Connection.Server"); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorInfo.java b/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorInfo.java index 8983b1c922a..b46d9e6bf8c 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorInfo.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorInfo.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + final class LocatorInfo { interface GetEndpointsCallback { void setEndpoints(EndpointI[] endpoints, boolean cached); @@ -61,20 +63,20 @@ public void exception(LocatorInfo locatorInfo, Exception exc) { } } - RequestCallback(Reference ref, int ttl, GetEndpointsCallback cb) { + RequestCallback(Reference ref, Duration ttl, GetEndpointsCallback cb) { _ref = ref; _ttl = ttl; _callback = cb; } final Reference _ref; - final int _ttl; + final Duration _ttl; final GetEndpointsCallback _callback; } private abstract class Request { public void addCallback( - Reference ref, Reference wellKnownRef, int ttl, GetEndpointsCallback cb) { + Reference ref, Reference wellKnownRef, Duration ttl, GetEndpointsCallback cb) { RequestCallback callback = new RequestCallback(ref, ttl, cb); synchronized (this) { if (!_response && _exception == null) { @@ -273,12 +275,12 @@ public LocatorRegistryPrx getLocatorRegistry() { } } - public void getEndpoints(Reference ref, int ttl, GetEndpointsCallback callback) { + public void getEndpoints(Reference ref, Duration ttl, GetEndpointsCallback callback) { getEndpoints(ref, null, ttl, callback); } public void getEndpoints( - Reference ref, Reference wellKnownRef, int ttl, GetEndpointsCallback callback) { + Reference ref, Reference wellKnownRef, Duration ttl, GetEndpointsCallback callback) { assert (ref.isIndirect()); EndpointI[] endpoints = null; Holder cached = new Holder<>(); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorTable.java b/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorTable.java index 2522971398d..a90d2c0c5f3 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorTable.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/LocatorTable.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + final class LocatorTable { LocatorTable() {} @@ -12,8 +14,9 @@ synchronized void clear() { _objectTable.clear(); } - synchronized EndpointI[] getAdapterEndpoints(String adapter, int ttl, Holder cached) { - if (ttl == 0) // Locator cache disabled. + synchronized EndpointI[] getAdapterEndpoints( + String adapter, Duration ttl, Holder cached) { + if (ttl.isZero()) // Locator cache disabled. { cached.value = false; return null; @@ -38,8 +41,8 @@ synchronized EndpointI[] removeAdapterEndpoints(String adapter) { return entry != null ? entry.endpoints : null; } - synchronized Reference getObjectReference(Identity id, int ttl, Holder cached) { - if (ttl == 0) // Locator cache disabled. + synchronized Reference getObjectReference(Identity id, Duration ttl, Holder cached) { + if (ttl.isZero()) // Locator cache disabled. { cached.value = false; return null; @@ -63,13 +66,13 @@ synchronized Reference removeObjectReference(Identity id) { return entry != null ? entry.reference : null; } - private boolean checkTTL(long time, int ttl) { - assert (ttl != 0); - if (ttl < 0) // TTL = infinite + private boolean checkTTL(long time, Duration ttl) { + assert (!ttl.isZero()); + if (ttl.compareTo(Duration.ZERO) < 0) // TTL = infinite { return true; } else { - return Time.currentMonotonicTimeMillis() - time <= ((long) ttl * 1000); + return Time.currentMonotonicTimeMillis() - time <= ttl.toMillis(); } } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectPrx.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectPrx.java index f498459bd85..1bd75ac96ed 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectPrx.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectPrx.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + /** Base interface of all object proxies. */ public interface ObjectPrx { /** @@ -287,17 +289,17 @@ java.util.concurrent.CompletableFuture ic /** * Returns the locator cache timeout of this proxy. * - * @return The locator cache timeout value (in seconds). + * @return The locator cache timeout value. * @see Locator */ - int ice_getLocatorCacheTimeout(); + Duration ice_getLocatorCacheTimeout(); /** * Returns the invocation timeout of this proxy. * - * @return The invocation timeout value (in milliseconds). + * @return The invocation timeout value. */ - int ice_getInvocationTimeout(); + Duration ice_getInvocationTimeout(); /** * Returns the connection id of this proxy. @@ -331,6 +333,15 @@ java.util.concurrent.CompletableFuture ic */ ObjectPrx ice_locatorCacheTimeout(int newTimeout); + /** + * Returns a proxy that is identical to this proxy, except for the locator cache timeout. + * + * @param newTimeout The new locator cache timeout. + * @return The proxy with the new timeout. + * @see Locator + */ + ObjectPrx ice_locatorCacheTimeout(Duration newTimeout); + /** * Returns a proxy that is identical to this proxy, except for the invocation timeout. * @@ -339,6 +350,14 @@ java.util.concurrent.CompletableFuture ic */ ObjectPrx ice_invocationTimeout(int newTimeout); + /** + * Returns a proxy that is identical to this proxy, except for the invocation timeout. + * + * @param newTimeout The new invocation timeout. + * @return The proxy with the new timeout. + */ + ObjectPrx ice_invocationTimeout(Duration newTimeout); + /** * Returns whether this proxy caches connections. * diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingAsync.java b/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingAsync.java index 425bbfffd82..6409e9ac36b 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingAsync.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingAsync.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + /** * @hidden Public because it's used by the generated code. */ @@ -129,9 +131,9 @@ public int invokeRemote(ConnectionI connection, boolean compress, boolean respon @Override public int invokeCollocated(CollocatedRequestHandler handler) { // The stream cannot be cached if the proxy is not a twoway or there is an invocation - // timeout - // set. - if (!_proxy.ice_isTwoway() || _proxy._getReference().getInvocationTimeout() > 0) { + // timeout set. + if (!_proxy.ice_isTwoway() + || _proxy._getReference().getInvocationTimeout().compareTo(Duration.ZERO) > 0) { // Disable caching by marking the streams as cached! _state |= StateCachedBuffers; } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java index 79eabf01494..3d66bee8f10 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -// Generated by makeprops.py from PropertyNames.xml, Thu Sep 26 17:31:37 2024 +// Generated by makeprops.py from PropertyNames.xml, Fri Sep 27 14:21:19 2024 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyIceInvoke.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyIceInvoke.java index adc0c2374df..f1b8774dfaa 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyIceInvoke.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyIceInvoke.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + class ProxyIceInvoke extends ProxyOutgoingAsyncBase { public ProxyIceInvoke( ObjectPrx prx, String operation, OperationMode mode, boolean synchronous) { @@ -69,7 +71,8 @@ public int invokeCollocated(CollocatedRequestHandler handler) { // The stream cannot be cached if the proxy is not a twoway or there is an invocation // timeout // set. - if (!_proxy.ice_isTwoway() || _proxy._getReference().getInvocationTimeout() > 0) { + if (!_proxy.ice_isTwoway() + || _proxy._getReference().getInvocationTimeout().compareTo(Duration.ZERO) > 0) { // Disable caching by marking the streams as cached! _state |= StateCachedBuffers; } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java index d4f083e21c8..8ca63c0f9ce 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + // // Base class for proxy based invocations. This class handles the // retry for proxy invocations. It also ensures the child observer is @@ -189,8 +191,8 @@ protected ProxyOutgoingAsyncBase(_ObjectPrxI prx, String op, OutputStream os) { protected void invokeImpl(boolean userThread) { try { if (userThread) { - int invocationTimeout = _proxy._getReference().getInvocationTimeout(); - if (invocationTimeout > 0) { + Duration invocationTimeout = _proxy._getReference().getInvocationTimeout(); + if (invocationTimeout.compareTo(Duration.ZERO) > 0) { _timerFuture = _instance .timer() @@ -198,7 +200,7 @@ protected void invokeImpl(boolean userThread) { () -> { cancel(new InvocationTimeoutException()); }, - invocationTimeout, + invocationTimeout.toMillis(), java.util.concurrent.TimeUnit.MILLISECONDS); } } else // If not called from the user thread, it's called from the retry queue diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Reference.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Reference.java index 8cb1828bb11..77d3e0236bc 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Reference.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Reference.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + /** * @hidden Public because it's used by the generated code. */ @@ -61,7 +63,7 @@ public final java.util.Map getContext() { return _context; } - public int getInvocationTimeout() { + public Duration getInvocationTimeout() { return _invocationTimeout; } @@ -89,7 +91,7 @@ public final Communicator getCommunicator() { public abstract EndpointSelectionType getEndpointSelection(); - public abstract int getLocatorCacheTimeout(); + public abstract Duration getLocatorCacheTimeout(); public abstract String getConnectionId(); @@ -139,7 +141,7 @@ public final Reference changeFacet(String newFacet) { return r; } - public final Reference changeInvocationTimeout(int newTimeout) { + public final Reference changeInvocationTimeout(Duration newTimeout) { Reference r = _instance.referenceFactory().copy(this); r._invocationTimeout = newTimeout; return r; @@ -173,7 +175,7 @@ public Reference changeCompress(boolean newCompress) { public abstract Reference changeEndpointSelection(EndpointSelectionType newType); - public abstract Reference changeLocatorCacheTimeout(int newTimeout); + public abstract Reference changeLocatorCacheTimeout(Duration newTimeout); public abstract Reference changeConnectionId(String connectionId); @@ -192,7 +194,7 @@ public int hashCode() { } // We don't include protocol and encoding in the hash; they are using 1.0 and 1.1, // respectively. - h = HashUtil.hashAdd(h, _invocationTimeout); + h = HashUtil.hashAdd(h, _invocationTimeout.toMillis()); return h; } @@ -403,7 +405,7 @@ public boolean equals(java.lang.Object obj) { return false; } - if (_invocationTimeout != r._invocationTimeout) { + if (!_invocationTimeout.equals(r._invocationTimeout)) { return false; } @@ -434,7 +436,7 @@ public Reference clone() { private String _facet; private final ProtocolVersion _protocol; private EncodingVersion _encoding; - private int _invocationTimeout; + private Duration _invocationTimeout; protected Reference( Instance instance, @@ -446,7 +448,7 @@ protected Reference( java.util.Optional compress, ProtocolVersion protocol, EncodingVersion encoding, - int invocationTimeout, + Duration invocationTimeout, java.util.Map context) { // // Validate string arguments. diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ReferenceFactory.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ReferenceFactory.java index 26b0f28195c..3b989b0372f 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ReferenceFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ReferenceFactory.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + final class ReferenceFactory { public Reference create(Identity ident, String facet, Reference tmpl, EndpointI[] endpoints) { if (ident.name.isEmpty() && ident.category.isEmpty()) { @@ -62,7 +64,7 @@ public Reference create(Identity ident, ConnectionI fixedConnection) { Util.Protocol_1_0, _instance.defaultsAndOverrides().defaultEncoding, fixedConnection, - -1, + Duration.ofMillis(-1), null); } @@ -714,8 +716,8 @@ private Reference create( boolean cacheConnection = true; boolean preferSecure = defaultsAndOverrides.defaultPreferSecure; EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection; - int locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; - int invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; + Duration locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; + Duration invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; java.util.Map context = null; // @@ -791,38 +793,16 @@ private Reference create( } property = propertyPrefix + ".LocatorCacheTimeout"; - String value = properties.getProperty(property); - if (!value.isEmpty()) { - locatorCacheTimeout = - properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout); - if (locatorCacheTimeout < -1) { - locatorCacheTimeout = -1; - - StringBuffer msg = new StringBuffer("invalid value for "); - msg.append(property); - msg.append(" '"); - msg.append(properties.getProperty(property)); - msg.append("': defaulting to -1"); - _instance.initializationData().logger.warning(msg.toString()); - } - } + locatorCacheTimeout = + Duration.ofSeconds( + properties.getPropertyAsIntWithDefault( + property, (int) locatorCacheTimeout.toSeconds())); property = propertyPrefix + ".InvocationTimeout"; - value = properties.getProperty(property); - if (!value.isEmpty()) { - invocationTimeout = - properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout); - if (invocationTimeout < 1 && invocationTimeout != -1) { - invocationTimeout = -1; - - StringBuffer msg = new StringBuffer("invalid value for "); - msg.append(property); - msg.append(" '"); - msg.append(properties.getProperty(property)); - msg.append("': defaulting to -1"); - _instance.initializationData().logger.warning(msg.toString()); - } - } + invocationTimeout = + Duration.ofMillis( + properties.getPropertyAsIntWithDefault( + property, (int) invocationTimeout.toMillis())); property = propertyPrefix + ".Context."; java.util.Map contexts = properties.getPropertiesForPrefix(property); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/RoutableReference.java b/java/src/Ice/src/main/java/com/zeroc/Ice/RoutableReference.java index 29ef7ce3f32..c8b7955c329 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/RoutableReference.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/RoutableReference.java @@ -4,6 +4,8 @@ package com.zeroc.Ice; +import java.time.Duration; + class RoutableReference extends Reference { @Override public final EndpointI[] getEndpoints() { @@ -46,7 +48,7 @@ public final EndpointSelectionType getEndpointSelection() { } @Override - public final int getLocatorCacheTimeout() { + public final Duration getLocatorCacheTimeout() { return _locatorCacheTimeout; } @@ -164,7 +166,7 @@ public final Reference changeEndpointSelection(EndpointSelectionType newType) { } @Override - public Reference changeLocatorCacheTimeout(int newTimeout) { + public Reference changeLocatorCacheTimeout(Duration newTimeout) { RoutableReference r = (RoutableReference) getInstance().referenceFactory().copy(this); r._locatorCacheTimeout = newTimeout; return r; @@ -281,12 +283,12 @@ public java.util.Map toProperty(String prefix) { { StringBuffer s = new StringBuffer(); - s.append(getInvocationTimeout()); + s.append(getInvocationTimeout().toMillis()); properties.put(prefix + ".InvocationTimeout", s.toString()); } { StringBuffer s = new StringBuffer(); - s.append(_locatorCacheTimeout); + s.append(_locatorCacheTimeout.toSeconds()); properties.put(prefix + ".LocatorCacheTimeout", s.toString()); } @@ -360,7 +362,7 @@ public boolean equals(java.lang.Object obj) { if (_endpointSelection != rhs._endpointSelection) { return false; } - if (_locatorCacheTimeout != rhs._locatorCacheTimeout) { + if (!_locatorCacheTimeout.equals(rhs._locatorCacheTimeout)) { return false; } if (!_connectionId.equals(rhs._connectionId)) { @@ -524,8 +526,8 @@ protected RoutableReference( boolean cacheConnection, boolean preferSecure, EndpointSelectionType endpointSelection, - int locatorCacheTimeout, - int invocationTimeout, + Duration locatorCacheTimeout, + Duration invocationTimeout, java.util.Map context) { super( instance, @@ -810,6 +812,6 @@ public int compare(EndpointI le, EndpointI re) { private boolean _cacheConnection; private boolean _preferSecure; private EndpointSelectionType _endpointSelection; - private int _locatorCacheTimeout; + private Duration _locatorCacheTimeout; private String _connectionId = ""; } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/_ObjectPrxI.java b/java/src/Ice/src/main/java/com/zeroc/Ice/_ObjectPrxI.java index 13606972dd4..694b71403f2 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/_ObjectPrxI.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/_ObjectPrxI.java @@ -4,6 +4,7 @@ package com.zeroc.Ice; +import java.time.Duration; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -194,11 +195,11 @@ public Endpoint[] ice_getEndpoints() { return _reference.getEndpoints().clone(); } - public int ice_getLocatorCacheTimeout() { + public Duration ice_getLocatorCacheTimeout() { return _reference.getLocatorCacheTimeout(); } - public int ice_getInvocationTimeout() { + public Duration ice_getInvocationTimeout() { return _reference.getInvocationTimeout(); } @@ -385,11 +386,12 @@ public ObjectPrx ice_fixed(com.zeroc.Ice.Connection connection) { @Override public ObjectPrx ice_locatorCacheTimeout(int newTimeout) { - if (newTimeout < -1) { - throw new IllegalArgumentException( - "invalid value passed to ice_locatorCacheTimeout: " + newTimeout); - } - if (newTimeout == _reference.getLocatorCacheTimeout()) { + return this.ice_locatorCacheTimeout(Duration.ofSeconds(newTimeout)); + } + + @Override + public ObjectPrx ice_locatorCacheTimeout(Duration newTimeout) { + if (newTimeout.equals(_reference.getLocatorCacheTimeout())) { return this; } else { return _newInstance(_reference.changeLocatorCacheTimeout(newTimeout)); @@ -398,11 +400,12 @@ public ObjectPrx ice_locatorCacheTimeout(int newTimeout) { @Override public ObjectPrx ice_invocationTimeout(int newTimeout) { - if (newTimeout < 1 && newTimeout != -1) { - throw new IllegalArgumentException( - "invalid value passed to ice_invocationTimeout: " + newTimeout); - } - if (newTimeout == _reference.getInvocationTimeout()) { + return this.ice_invocationTimeout(Duration.ofMillis(newTimeout)); + } + + @Override + public ObjectPrx ice_invocationTimeout(Duration newTimeout) { + if (newTimeout.equals(_reference.getInvocationTimeout())) { return this; } else { return _newInstance(_reference.changeInvocationTimeout(newTimeout)); diff --git a/java/test/src/main/java/test/Ice/location/AllTests.java b/java/test/src/main/java/test/Ice/location/AllTests.java index ad8292e4681..58c3510b992 100644 --- a/java/test/src/main/java/test/Ice/location/AllTests.java +++ b/java/test/src/main/java/test/Ice/location/AllTests.java @@ -7,6 +7,7 @@ import com.zeroc.Ice.ObjectPrx; import com.zeroc.Ice.Util; import java.io.PrintWriter; +import java.time.Duration; import java.util.concurrent.CompletableFuture; import test.Ice.location.Test.HelloPrx; import test.Ice.location.Test.ServerManagerPrx; @@ -258,10 +259,10 @@ public static void allTests(test.TestHelper helper) test( communicator - .stringToProxy("test") - .ice_locatorCacheTimeout(99) - .ice_getLocatorCacheTimeout() - == 99); + .stringToProxy("test") + .ice_locatorCacheTimeout(Duration.ofSeconds(99)) + .ice_getLocatorCacheTimeout() + .equals(Duration.ofSeconds(99))); out.println("ok"); diff --git a/java/test/src/main/java/test/Ice/proxy/AllTests.java b/java/test/src/main/java/test/Ice/proxy/AllTests.java index 8ba7f921c80..5a690cd5987 100644 --- a/java/test/src/main/java/test/Ice/proxy/AllTests.java +++ b/java/test/src/main/java/test/Ice/proxy/AllTests.java @@ -11,6 +11,7 @@ import com.zeroc.Ice.ParseException; import com.zeroc.Ice.Util; import java.io.PrintWriter; +import java.time.Duration; import test.Ice.proxy.Test.DiamondClassPrx; import test.Ice.proxy.Test.MyClassPrx; import test.Ice.proxy.Test.MyDerivedClassPrx; @@ -449,10 +450,10 @@ public static MyClassPrx allTests(test.TestHelper helper) { prop.setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1.ice_getLocatorCacheTimeout() == -1); + test(b1.ice_getLocatorCacheTimeout().equals(Duration.ofSeconds(-1))); prop.setProperty(property, "1"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getLocatorCacheTimeout() == 1); + test(b1.ice_getLocatorCacheTimeout().equals(Duration.ofSeconds(1))); prop.setProperty(property, ""); // Now retest with an indirect proxy. @@ -466,10 +467,10 @@ public static MyClassPrx allTests(test.TestHelper helper) { prop.setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1.ice_getLocatorCacheTimeout() == -1); + test(b1.ice_getLocatorCacheTimeout().equals(Duration.ofSeconds(-1))); prop.setProperty(property, "1"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getLocatorCacheTimeout() == 1); + test(b1.ice_getLocatorCacheTimeout().equals(Duration.ofSeconds(1))); prop.setProperty(property, ""); // This cannot be tested so easily because the property is cached @@ -506,10 +507,10 @@ public static MyClassPrx allTests(test.TestHelper helper) { prop.setProperty(property, ""); property = propertyPrefix + ".InvocationTimeout"; - test(b1.ice_getInvocationTimeout() == -1); + test(b1.ice_getInvocationTimeout().equals(Duration.ofMillis(-1))); prop.setProperty(property, "1000"); b1 = communicator.propertyToProxy(propertyPrefix); - test(b1.ice_getInvocationTimeout() == 1000); + test(b1.ice_getInvocationTimeout().equals(Duration.ofSeconds(1))); prop.setProperty(property, ""); property = propertyPrefix + ".EndpointSelection"; @@ -650,41 +651,33 @@ public static MyClassPrx allTests(test.TestHelper helper) { .ice_getEncodingVersion() .equals(Util.Encoding_1_1)); - try { - base.ice_invocationTimeout(0); - test(false); - } catch (IllegalArgumentException e) { - } - - try { - base.ice_invocationTimeout(-1); - } catch (IllegalArgumentException e) { - test(false); - } - - try { - base.ice_invocationTimeout(-2); - test(false); - } catch (IllegalArgumentException e) { - } - - try { - base.ice_locatorCacheTimeout(0); - } catch (IllegalArgumentException e) { - test(false); - } - - try { - base.ice_locatorCacheTimeout(-1); - } catch (IllegalArgumentException e) { - test(false); - } + test( + base.ice_invocationTimeout(10) + .ice_getInvocationTimeout() + .equals(Duration.ofMillis(10))); + test(base.ice_invocationTimeout(0).ice_getInvocationTimeout().equals(Duration.ZERO)); + test( + base.ice_invocationTimeout(-1) + .ice_getInvocationTimeout() + .equals(Duration.ofMillis(-1))); + test( + base.ice_invocationTimeout(-2) + .ice_getInvocationTimeout() + .equals(Duration.ofMillis(-2))); - try { - base.ice_locatorCacheTimeout(-2); - test(false); - } catch (IllegalArgumentException e) { - } + test( + base.ice_locatorCacheTimeout(10) + .ice_getLocatorCacheTimeout() + .equals(Duration.ofSeconds(10))); + test(base.ice_locatorCacheTimeout(0).ice_getLocatorCacheTimeout().equals(Duration.ZERO)); + test( + base.ice_locatorCacheTimeout(-1) + .ice_getLocatorCacheTimeout() + .equals(Duration.ofSeconds(-1))); + test( + base.ice_locatorCacheTimeout(-2) + .ice_getLocatorCacheTimeout() + .equals(Duration.ofSeconds(-2))); // Ensure that the proxy methods can be called unambiguously with the correct return type. var diamondClass = DiamondClassPrx.uncheckedCast(base); @@ -866,12 +859,15 @@ public static MyClassPrx allTests(test.TestHelper helper) { ctx.put("two", "world"); test(cl.ice_fixed(connection).ice_getContext().isEmpty()); test(cl.ice_context(ctx).ice_fixed(connection).ice_getContext().size() == 2); - test(cl.ice_fixed(connection).ice_getInvocationTimeout() == -1); + test( + cl.ice_fixed(connection) + .ice_getInvocationTimeout() + .equals(Duration.ofMillis(-1))); test( cl.ice_invocationTimeout(10) - .ice_fixed(connection) - .ice_getInvocationTimeout() - == 10); + .ice_fixed(connection) + .ice_getInvocationTimeout() + .equals(Duration.ofMillis(10))); test(cl.ice_fixed(connection).ice_getConnection() == connection); test( cl.ice_fixed(connection).ice_fixed(connection).ice_getConnection() diff --git a/js/src/Ice/PropertyNames.js b/js/src/Ice/PropertyNames.js index 1bb5100978c..5d80a2131ab 100644 --- a/js/src/Ice/PropertyNames.js +++ b/js/src/Ice/PropertyNames.js @@ -1,6 +1,6 @@ // Copyright (c) ZeroC, Inc. -// Generated by makeprops.py from PropertyNames.xml, Thu Sep 26 17:31:37 2024 +// Generated by makeprops.py from PropertyNames.xml, Fri Sep 27 14:21:19 2024 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/matlab/src/ObjectPrx.cpp b/matlab/src/ObjectPrx.cpp index 45e3cad7292..b908234b785 100644 --- a/matlab/src/ObjectPrx.cpp +++ b/matlab/src/ObjectPrx.cpp @@ -542,7 +542,9 @@ extern "C" mxArray* Ice_ObjectPrx_ice_getLocatorCacheTimeout(void* self) { - return createResultValue(createInt(restoreProxy(self)->ice_getLocatorCacheTimeout())); + chrono::seconds timeout = + chrono::duration_cast(restoreProxy(self)->ice_getLocatorCacheTimeout()); + return createResultValue(createInt(static_cast(timeout.count()))); } mxArray* Ice_ObjectPrx_ice_locatorCacheTimeout(void* self, void** r, int t) @@ -562,7 +564,8 @@ extern "C" mxArray* Ice_ObjectPrx_ice_getInvocationTimeout(void* self) { - return createResultValue(createInt(restoreProxy(self)->ice_getInvocationTimeout())); + chrono::milliseconds timeout = restoreProxy(self)->ice_getInvocationTimeout(); + return createResultValue(createInt(static_cast(timeout.count()))); } mxArray* Ice_ObjectPrx_ice_invocationTimeout(void* self, void** r, int t) diff --git a/php/src/Proxy.cpp b/php/src/Proxy.cpp index 1d0f8815656..f1381101b70 100644 --- a/php/src/Proxy.cpp +++ b/php/src/Proxy.cpp @@ -420,8 +420,8 @@ ZEND_METHOD(Ice_ObjectPrx, ice_getLocatorCacheTimeout) try { - int32_t timeout = _this->proxy->ice_getLocatorCacheTimeout(); - ZVAL_LONG(return_value, static_cast(timeout)); + chrono::seconds timeout = chrono::duration_cast(_this->proxy->ice_getLocatorCacheTimeout()); + ZVAL_LONG(return_value, static_cast(timeout.count())); } catch (...) { @@ -1253,7 +1253,8 @@ ZEND_METHOD(Ice_ObjectPrx, ice_getInvocationTimeout) try { - ZVAL_LONG(return_value, static_cast(_this->proxy->ice_getInvocationTimeout())); + chrono::milliseconds timeout = _this->proxy->ice_getInvocationTimeout(); + ZVAL_LONG(return_value, static_cast(timeout.count())); } catch (...) { diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp index 3705829d991..f463524c185 100644 --- a/python/modules/IcePy/Proxy.cpp +++ b/python/modules/IcePy/Proxy.cpp @@ -611,8 +611,8 @@ proxyIceGetLocatorCacheTimeout(ProxyObject* self, PyObject* /*args*/) try { - int32_t timeout = (*self->proxy)->ice_getLocatorCacheTimeout(); - return PyLong_FromLong(timeout); + chrono::seconds timeout = chrono::duration_cast((*self->proxy)->ice_getLocatorCacheTimeout()); + return PyLong_FromLong(static_cast(timeout.count())); } catch (...) { @@ -628,8 +628,8 @@ proxyIceGetInvocationTimeout(ProxyObject* self, PyObject* /*args*/) try { - int32_t timeout = (*self->proxy)->ice_getInvocationTimeout(); - return PyLong_FromLong(timeout); + chrono::milliseconds timeout = (*self->proxy)->ice_getInvocationTimeout(); + return PyLong_FromLong(static_cast(timeout.count())); } catch (...) { diff --git a/ruby/src/IceRuby/Proxy.cpp b/ruby/src/IceRuby/Proxy.cpp index b7b8caf5810..cf64b259330 100644 --- a/ruby/src/IceRuby/Proxy.cpp +++ b/ruby/src/IceRuby/Proxy.cpp @@ -366,8 +366,8 @@ IceRuby_ObjectPrx_ice_getLocatorCacheTimeout(VALUE self) ICE_RUBY_TRY { Ice::ObjectPrx p = getProxy(self); - int32_t t = p->ice_getLocatorCacheTimeout(); - return INT2FIX(t); + chrono::seconds timeout = chrono::duration_cast(p->ice_getLocatorCacheTimeout()); + return INT2FIX(static_cast(timeout.count())); } ICE_RUBY_CATCH return Qnil; @@ -379,8 +379,8 @@ IceRuby_ObjectPrx_ice_getInvocationTimeout(VALUE self) ICE_RUBY_TRY { Ice::ObjectPrx p = getProxy(self); - int32_t t = p->ice_getInvocationTimeout(); - return INT2FIX(t); + chrono::milliseconds timeout = p->ice_getInvocationTimeout(); + return INT2FIX(static_cast(timeout.count())); } ICE_RUBY_CATCH return Qnil; diff --git a/swift/src/IceImpl/ObjectPrx.mm b/swift/src/IceImpl/ObjectPrx.mm index 182b80cee82..cb43caf5636 100644 --- a/swift/src/IceImpl/ObjectPrx.mm +++ b/swift/src/IceImpl/ObjectPrx.mm @@ -5,6 +5,7 @@ #import "include/Communicator.h" #import "include/Connection.h" #import "include/OutputStream.h" +#include @implementation ICEObjectPrx @@ -125,7 +126,8 @@ - (instancetype)ice_endpoints:(NSArray*)endpoints error:(NSError** - (int32_t)ice_getLocatorCacheTimeout { - return _prx->ice_getLocatorCacheTimeout(); + std::chrono::seconds timeout = std::chrono::duration_cast(_prx->ice_getLocatorCacheTimeout()); + return static_cast(timeout.count()); } - (instancetype)ice_locatorCacheTimeout:(int32_t)timeout error:(NSError**)error @@ -144,7 +146,7 @@ - (instancetype)ice_locatorCacheTimeout:(int32_t)timeout error:(NSError**)error - (int32_t)ice_getInvocationTimeout { - return _prx->ice_getInvocationTimeout(); + return static_cast(_prx->ice_getInvocationTimeout().count()); } - (instancetype)ice_invocationTimeout:(int32_t)timeout error:(NSError**)error