summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/SessionManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/SessionManager.h')
-rw-r--r--cpp/src/IceGrid/SessionManager.h172
1 files changed, 94 insertions, 78 deletions
diff --git a/cpp/src/IceGrid/SessionManager.h b/cpp/src/IceGrid/SessionManager.h
index 9340699dab5..7760241e865 100644
--- a/cpp/src/IceGrid/SessionManager.h
+++ b/cpp/src/IceGrid/SessionManager.h
@@ -42,8 +42,9 @@ class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<I
public:
- SessionKeepAliveThread(const InternalRegistryPrx& registry) :
+ SessionKeepAliveThread(const InternalRegistryPrx& registry, const Ice::LoggerPtr& logger) :
_registry(registry),
+ _logger(logger),
_state(InProgress),
_nextAction(None)
{
@@ -57,108 +58,122 @@ public:
IceUtil::Time timeout = IceUtil::Time::seconds(15);
Action action = Connect;
- while(true)
+ try
{
+ while(true)
{
- Lock sync(*this);
- if(_state == Destroyed)
{
- break;
- }
+ Lock sync(*this);
+ if(_state == Destroyed)
+ {
+ break;
+ }
- //
- // Update the current state.
- //
- assert(_state == InProgress);
- _state = session ? Connected : Disconnected;
- _session = session;
- if(_session)
- {
- _registry = registry;
- }
+ //
+ // Update the current state.
+ //
+ assert(_state == InProgress);
+ _state = session ? Connected : Disconnected;
+ _session = session;
+ if(_session)
+ {
+ _registry = registry;
+ }
- if(_nextAction == Connect && _state == Connected)
- {
- _nextAction = KeepAlive;
- }
- else if(_nextAction == Disconnect && _state == Disconnected)
- {
- _nextAction = None;
- }
- else if(_nextAction == KeepAlive && _state == Disconnected)
- {
- _nextAction = Connect;
- }
- notifyAll();
+ if(_nextAction == Connect && _state == Connected)
+ {
+ _nextAction = KeepAlive;
+ }
+ else if(_nextAction == Disconnect && _state == Disconnected)
+ {
+ _nextAction = None;
+ }
+ else if(_nextAction == KeepAlive && _state == Disconnected)
+ {
+ _nextAction = Connect;
+ }
+ notifyAll();
- //
- // Wait if there's nothing to do and if we are
- // connected or if we've just tried to connect.
- //
- if(_nextAction == None)
- {
- if(_state == Connected || action == Connect || action == KeepAlive)
+ //
+ // Wait if there's nothing to do and if we are
+ // connected or if we've just tried to connect.
+ //
+ if(_nextAction == None)
{
- IceUtil::Time wakeTime = IceUtil::Time::now() + timeout;
- while(_state != Destroyed && _nextAction == None)
+ if(_state == Connected || action == Connect || action == KeepAlive)
{
- if(!timedWait(wakeTime - IceUtil::Time::now()))
+ IceUtil::Time now = IceUtil::Time::now();
+ IceUtil::Time wakeTime = now + timeout;
+ while(_state != Destroyed && _nextAction == None && wakeTime > now)
{
- break;
+ timedWait(wakeTime - now);
+ now = IceUtil::Time::now();
}
}
+ if(_nextAction == None)
+ {
+ _nextAction = session ? KeepAlive : Connect;
+ }
}
- if(_nextAction == None)
+
+ if(_state == Destroyed)
{
- _nextAction = session ? KeepAlive : Connect;
+ break;
}
+
+ assert(_nextAction != None);
+
+ action = _nextAction;
+ registry = InternalRegistryPrx::uncheckedCast(
+ _registry->ice_timeout(static_cast<int>(timeout.toMilliSeconds())));
+ _nextAction = None;
+ _state = InProgress;
+ notifyAll();
}
- if(_state == Destroyed)
+ switch(action)
{
+ case Connect:
+ assert(!session);
+ session = createSession(registry, timeout);
+ break;
+ case Disconnect:
+ assert(session);
+ destroySession(session);
+ session = 0;
+ break;
+ case KeepAlive:
+ assert(session);
+ if(!keepAlive(session))
+ {
+ session = createSession(registry, timeout);
+ }
break;
+ case None:
+ default:
+ assert(false);
}
-
- assert(_nextAction != None);
-
- action = _nextAction;
- registry = InternalRegistryPrx::uncheckedCast(
- _registry->ice_timeout(static_cast<int>(timeout.toMilliSeconds())));
- _nextAction = None;
- _state = InProgress;
- notifyAll();
}
-
- switch(action)
+
+ //
+ // Destroy the session.
+ //
+ if(_nextAction == Disconnect && session)
{
- case Connect:
- assert(!session);
- session = createSession(registry, timeout);
- break;
- case Disconnect:
- assert(session);
destroySession(session);
- session = 0;
- break;
- case KeepAlive:
- assert(session);
- if(!keepAlive(session))
- {
- session = createSession(registry, timeout);
- }
- break;
- case None:
- default:
- assert(false);
}
}
-
- //
- // Destroy the session.
- //
- if(_nextAction == Disconnect && session)
+ catch(const std::exception& ex)
+ {
+ Ice::Error out(_logger);
+ out << "unknown exception in session manager keep alive thread:\n" << ex.what();
+ throw;
+ }
+ catch(...)
{
- destroySession(session);
+ Ice::Error out(_logger);
+ out << "unknown exception in session manager keep alive thread";
+ throw;
}
}
@@ -274,6 +289,7 @@ public:
protected:
InternalRegistryPrx _registry;
+ Ice::LoggerPtr _logger;
TPrx _session;
State _state;
Action _nextAction;