// ********************************************************************** // // Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace Ice; using namespace IceInternal; void IceInternal::incRef(ProxyFactory* p) { p->__incRef(); } void IceInternal::decRef(ProxyFactory* p) { p->__decRef(); } ObjectPrx IceInternal::ProxyFactory::stringToProxy(const string& str) const { ReferencePtr ref = _instance->referenceFactory()->create(str); return referenceToProxy(ref); } string IceInternal::ProxyFactory::proxyToString(const ObjectPrx& proxy) const { if(proxy) { return proxy->__reference()->toString(); } else { return ""; } } ObjectPrx IceInternal::ProxyFactory::streamToProxy(BasicStream* s) const { Identity ident; ident.__read(s); ReferencePtr ref = _instance->referenceFactory()->create(ident, s); return referenceToProxy(ref); } void IceInternal::ProxyFactory::proxyToStream(const ObjectPrx& proxy, BasicStream* s) const { if(proxy) { proxy->__reference()->identity.__write(s); proxy->__reference()->streamWrite(s); } else { Identity ident; ident.__write(s); } } ObjectPrx IceInternal::ProxyFactory::referenceToProxy(const ReferencePtr& ref) const { if(ref) { ObjectPrx proxy = new ::IceProxy::Ice::Object; proxy->setup(ref); return proxy; } else { return 0; } } void IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, int& cnt) const { // // We don't retry *NotExistException, which are all derived from // RequestFailedException. // if(dynamic_cast(&ex)) { ex.ice_throw(); } ++cnt; TraceLevelsPtr traceLevels = _instance->traceLevels(); LoggerPtr logger = _instance->logger(); // // Instance components may be null if the communicator has been // destroyed. // if(traceLevels && logger) { if(cnt > static_cast(_retryIntervals.size())) { if(traceLevels->retry >= 1) { Trace out(logger, traceLevels->retryCat); out << "cannot retry operation call because retry limit has been exceeded\n" << ex; } ex.ice_throw(); } if(traceLevels->retry >= 1) { Trace out(logger, traceLevels->retryCat); out << "re-trying operation call"; if(cnt > 0 && _retryIntervals[cnt - 1] > 0) { out << " in " << _retryIntervals[cnt - 1] << "ms"; } out << " because of exception\n" << ex; } if(cnt > 0) { // // Sleep before retrying. // IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(_retryIntervals[cnt - 1])); } } else { // // Impossible to retry after the communicator has been // destroyed. // ex.ice_throw(); } } IceInternal::ProxyFactory::ProxyFactory(const InstancePtr& instance) : _instance(instance) { string str = _instance->properties()->getPropertyWithDefault("Ice.RetryIntervals", "0"); string::size_type beg; string::size_type end = 0; while(true) { const string delim = " \t"; beg = str.find_first_not_of(delim, end); if(beg == string::npos) { if(_retryIntervals.empty()) { _retryIntervals.push_back(0); } break; } end = str.find_first_of(delim, beg); if(end == string::npos) { end = str.length(); } if(beg == end) { break; } istringstream value(str.substr(beg, end - beg)); int v; if(!(value >> v) || !value.eof()) { v = 0; } // // If -1 is the first value, no retry and wait intervals. // if(v == -1 && _retryIntervals.empty()) { break; } _retryIntervals.push_back(v > 0 ? v : 0); } } IceInternal::ProxyFactory::~ProxyFactory() { }