diff options
author | Matthew Newhook <matthew@zeroc.com> | 2014-07-23 15:06:02 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2014-07-23 15:06:02 -0230 |
commit | 866f9ff17391176b836f9bb49f6da40c2c938441 (patch) | |
tree | 7366963294ef3356c7b887cd89af753988c21beb /cpp/src/Freeze | |
parent | adding ACM tests for Python/Ruby/PHP (diff) | |
download | ice-866f9ff17391176b836f9bb49f6da40c2c938441.tar.bz2 ice-866f9ff17391176b836f9bb49f6da40c2c938441.tar.xz ice-866f9ff17391176b836f9bb49f6da40c2c938441.zip |
ICE-4234 - Update Ice to use current Java threading constructs
- Use ScheduledThreadPoolDispatcher not IceUtilInternal.Timer.
- Use Ice timer in glacier2, Freeze impl.
- Align C++, C# with java changes.
- Database demo now supports mariadb.
Diffstat (limited to 'cpp/src/Freeze')
-rw-r--r-- | cpp/src/Freeze/BackgroundSaveEvictorI.cpp | 157 | ||||
-rw-r--r-- | cpp/src/Freeze/BackgroundSaveEvictorI.h | 31 |
2 files changed, 60 insertions, 128 deletions
diff --git a/cpp/src/Freeze/BackgroundSaveEvictorI.cpp b/cpp/src/Freeze/BackgroundSaveEvictorI.cpp index 1da527561e3..f37d44bad7e 100644 --- a/cpp/src/Freeze/BackgroundSaveEvictorI.cpp +++ b/cpp/src/Freeze/BackgroundSaveEvictorI.cpp @@ -24,34 +24,6 @@ using namespace std; using namespace Freeze; using namespace Ice; - -// -// createEvictor functions -// - -Freeze::BackgroundSaveEvictorPtr -Freeze::createBackgroundSaveEvictor(const ObjectAdapterPtr& adapter, - const string& envName, - const string& filename, - const ServantInitializerPtr& initializer, - const vector<IndexPtr>& indices, - bool createDb) -{ - return new BackgroundSaveEvictorI(adapter, envName, 0, filename, initializer, indices, createDb); -} - -BackgroundSaveEvictorPtr -Freeze::createBackgroundSaveEvictor(const ObjectAdapterPtr& adapter, - const string& envName, - DbEnv& dbEnv, - const string& filename, - const ServantInitializerPtr& initializer, - const vector<IndexPtr>& indices, - bool createDb) -{ - return new BackgroundSaveEvictorI(adapter, envName, &dbEnv, filename, initializer, indices, createDb); -} - namespace { @@ -79,18 +51,7 @@ public: }; Init init; -} - -FatalErrorCallback -Freeze::registerFatalErrorCallback(FatalErrorCallback cb) -{ - IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(fatalErrorCallbackMutex); - FatalErrorCallback result = fatalErrorCallback; - fatalErrorCallback = cb; - return result; -} - -static void +void handleFatalError(const Freeze::BackgroundSaveEvictorPtr& evictor, const Ice::CommunicatorPtr& communicator) { IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(fatalErrorCallbackMutex); @@ -104,68 +65,70 @@ handleFatalError(const Freeze::BackgroundSaveEvictorPtr& evictor, const Ice::Com } } - // -// WatchDogThread +// The timer is used to ensure the streaming of some object does not take more than +// timeout ms. We only measure the time necessary to acquire the lock on the object +// (servant), not the streaming itself. // - -Freeze::WatchDogThread::WatchDogThread(long timeout, BackgroundSaveEvictorI& evictor) : - IceUtil::Thread("Freeze background save evictor watchdog thread"), - _timeout(IceUtil::Time::milliSeconds(timeout)), - _evictor(evictor), - _done(false), - _active(false) +class WatchDogTask : public IceUtil::TimerTask { -} +public: + WatchDogTask(BackgroundSaveEvictorI& evictor) : _evictor(evictor) + { + } -void -Freeze::WatchDogThread::run() -{ - Lock sync(*this); - - while(!_done) + virtual void runTimerTask() { - if(_active) - { - if(timedWait(_timeout) == false && _active && !_done) - { - Error out(_evictor.communicator()->getLogger()); - out << "Fatal error: streaming watch dog thread timed out."; - out.flush(); - handleFatalError(&_evictor, _evictor.communicator()); - } - } - else - { - wait(); - } + Error out(_evictor.communicator()->getLogger()); + out << "Fatal error: streaming watch dog timed out."; + out.flush(); + handleFatalError(&_evictor, _evictor.communicator()); } + +private: + + BackgroundSaveEvictorI& _evictor; +}; + } -void Freeze::WatchDogThread::activate() +// +// createEvictor functions +// + +Freeze::BackgroundSaveEvictorPtr +Freeze::createBackgroundSaveEvictor(const ObjectAdapterPtr& adapter, + const string& envName, + const string& filename, + const ServantInitializerPtr& initializer, + const vector<IndexPtr>& indices, + bool createDb) { - Lock sync(*this); - _active = true; - notify(); + return new BackgroundSaveEvictorI(adapter, envName, 0, filename, initializer, indices, createDb); } -void Freeze::WatchDogThread::deactivate() +BackgroundSaveEvictorPtr +Freeze::createBackgroundSaveEvictor(const ObjectAdapterPtr& adapter, + const string& envName, + DbEnv& dbEnv, + const string& filename, + const ServantInitializerPtr& initializer, + const vector<IndexPtr>& indices, + bool createDb) { - Lock sync(*this); - _active = false; - notify(); + return new BackgroundSaveEvictorI(adapter, envName, &dbEnv, filename, initializer, indices, createDb); } - -void -Freeze::WatchDogThread::terminate() + +FatalErrorCallback +Freeze::registerFatalErrorCallback(FatalErrorCallback cb) { - Lock sync(*this); - _done = true; - notify(); + IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(fatalErrorCallbackMutex); + FatalErrorCallback result = fatalErrorCallback; + fatalErrorCallback = cb; + return result; } - // // BackgroundSaveEvictorI // @@ -211,13 +174,12 @@ Freeze::BackgroundSaveEvictorI::BackgroundSaveEvictorI(const ObjectAdapterPtr& a // // By default, no stream timeout // - long streamTimeout = _communicator->getProperties()-> + _streamTimeout = _communicator->getProperties()-> getPropertyAsIntWithDefault(propertyPrefix+ ".StreamTimeout", 0) * 1000; - if(streamTimeout > 0) + if(_streamTimeout > 0) { - _watchDogThread = new WatchDogThread(streamTimeout, *this); - _watchDogThread->start(); + _timer = IceInternal::getInstanceTimer(_communicator); } // @@ -847,12 +809,6 @@ Freeze::BackgroundSaveEvictorI::deactivate(const string&) sync.release(); getThreadControl().join(); - if(_watchDogThread != 0) - { - _watchDogThread->terminate(); - _watchDogThread->getThreadControl().join(); - } - closeDbEnv(); } catch(...) @@ -1011,14 +967,17 @@ Freeze::BackgroundSaveEvictorI::run() { lockElement.release(); - if(_watchDogThread != 0) + IceUtil::TimerTaskPtr watchDogTask; + if(_timer) { - _watchDogThread->activate(); + watchDogTask = new WatchDogTask(*this); + _timer->schedule(watchDogTask, IceUtil::Time::milliSeconds(_streamTimeout)); } lockServant.acquire(); - if(_watchDogThread != 0) + if(watchDogTask) { - _watchDogThread->deactivate(); + _timer->cancel(watchDogTask); + watchDogTask = 0; } lockElement.acquire(); diff --git a/cpp/src/Freeze/BackgroundSaveEvictorI.h b/cpp/src/Freeze/BackgroundSaveEvictorI.h index a5afff853ff..12037c53275 100644 --- a/cpp/src/Freeze/BackgroundSaveEvictorI.h +++ b/cpp/src/Freeze/BackgroundSaveEvictorI.h @@ -60,34 +60,6 @@ namespace Freeze class BackgroundSaveEvictorI; -// -// The WatchDogThread is used by the saving thread to ensure the -// streaming of some object does not take more than timeout ms. -// We only measure the time necessary to acquire the lock on the -// object (servant), not the streaming itself. -// - -class WatchDogThread : public IceUtil::Thread, private IceUtil::Monitor<IceUtil::Mutex> -{ -public: - - WatchDogThread(long, BackgroundSaveEvictorI&); - - void run(); - - void activate(); - void deactivate(); - void terminate(); - -private: - const IceUtil::Time _timeout; - BackgroundSaveEvictorI& _evictor; - bool _done; - bool _active; -}; - -typedef IceUtil::Handle<WatchDogThread> WatchDogThreadPtr; - struct BackgroundSaveEvictorElement; typedef IceUtil::Handle<BackgroundSaveEvictorElement> BackgroundSaveEvictorElementPtr; @@ -199,7 +171,8 @@ private: std::deque<BackgroundSaveEvictorElementPtr> _modifiedQueue; bool _savingThreadDone; - WatchDogThreadPtr _watchDogThread; + long _streamTimeout; + IceUtil::TimerPtr _timer; // // Threads that have requested a "saveNow" and are waiting for |