summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/BackgroundSaveEvictorI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Freeze/BackgroundSaveEvictorI.cpp')
-rw-r--r--cpp/src/Freeze/BackgroundSaveEvictorI.cpp157
1 files changed, 58 insertions, 99 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();