diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
commit | abada90e3f84dc703b8ddc9efcbed8a946fadead (patch) | |
tree | 2c6f9dccd510ea97cb927a7bd635422efaae547a /cpp/src/IceGrid/SessionManager.h | |
parent | removing trace message (diff) | |
download | ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.bz2 ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.xz ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.zip |
Expanded tabs into spaces
Diffstat (limited to 'cpp/src/IceGrid/SessionManager.h')
-rw-r--r-- | cpp/src/IceGrid/SessionManager.h | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/cpp/src/IceGrid/SessionManager.h b/cpp/src/IceGrid/SessionManager.h index c72924dbc53..7ce8ba23b0b 100644 --- a/cpp/src/IceGrid/SessionManager.h +++ b/cpp/src/IceGrid/SessionManager.h @@ -26,245 +26,245 @@ class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<I { enum State { - Disconnected, - Connected, - InProgress, - Destroyed + Disconnected, + Connected, + InProgress, + Destroyed }; enum Action { - Connect, - Disconnect, - KeepAlive, - None + Connect, + Disconnect, + KeepAlive, + None }; public: SessionKeepAliveThread(const InternalRegistryPrx& registry) : - _registry(registry), - _state(InProgress), - _nextAction(None) + _registry(registry), + _state(InProgress), + _nextAction(None) { } virtual void run() { - TPrx session; - InternalRegistryPrx registry; - IceUtil::Time timeout = IceUtil::Time::seconds(15); - Action action = Connect; + TPrx session; + InternalRegistryPrx registry; + IceUtil::Time timeout = IceUtil::Time::seconds(15); + Action action = Connect; - while(true) - { - { - Lock sync(*this); - if(_state == Destroyed) - { - break; - } + while(true) + { + { + 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) - { - IceUtil::Time wakeTime = IceUtil::Time::now() + timeout; - while(_state != Destroyed && _nextAction == None) - { - if(!timedWait(wakeTime - IceUtil::Time::now())) - { - break; - } - } - } - if(_nextAction == None) - { - _nextAction = session ? KeepAlive : Connect; - } - } + // + // 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) + { + IceUtil::Time wakeTime = IceUtil::Time::now() + timeout; + while(_state != Destroyed && _nextAction == None) + { + if(!timedWait(wakeTime - IceUtil::Time::now())) + { + break; + } + } + } + if(_nextAction == None) + { + _nextAction = session ? KeepAlive : Connect; + } + } - if(_state == Destroyed) - { - 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) + { + break; + } + + assert(_nextAction != None); + + action = _nextAction; + registry = InternalRegistryPrx::uncheckedCast( + _registry->ice_timeout(static_cast<int>(timeout.toMilliSeconds()))); + _nextAction = None; + _state = InProgress; + notifyAll(); + } - 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); - } - } - - // - // Destroy the session. - // - if(_nextAction == Disconnect && session) - { - destroySession(session); - } + 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); + } + } + + // + // Destroy the session. + // + if(_nextAction == Disconnect && session) + { + destroySession(session); + } } virtual bool waitForCreate() { - Lock sync(*this); - while(_state != Destroyed && _state != Connected) - { - wait(); - } - return _state != Destroyed; + Lock sync(*this); + while(_state != Destroyed && _state != Connected) + { + wait(); + } + return _state != Destroyed; } virtual void tryCreateSession(bool waitForTry = true) { - { - Lock sync(*this); - if(_state == Destroyed) - { - return; - } + { + Lock sync(*this); + if(_state == Destroyed) + { + return; + } - if(_state == Connected) - { - _nextAction = KeepAlive; - } - else - { - _nextAction = Connect; - } - notifyAll(); - } + if(_state == Connected) + { + _nextAction = KeepAlive; + } + else + { + _nextAction = Connect; + } + notifyAll(); + } - if(waitForTry) - { - Lock sync(*this); - // Wait until the action is executed and the state changes. - while(_nextAction == Connect || _nextAction == KeepAlive || _state == InProgress) - { - wait(); - } - } + if(waitForTry) + { + Lock sync(*this); + // Wait until the action is executed and the state changes. + while(_nextAction == Connect || _nextAction == KeepAlive || _state == InProgress) + { + wait(); + } + } } void destroyActiveSession() { - Lock sync(*this); - if(_state == Destroyed || _state == Disconnected) - { - return; - } - _nextAction = Disconnect; - notifyAll(); + Lock sync(*this); + if(_state == Destroyed || _state == Disconnected) + { + return; + } + _nextAction = Disconnect; + notifyAll(); } bool terminateIfDisconnected() { - Lock sync(*this); - if(_state != Disconnected) - { - return false; // Nothing we can do for now. - } - assert(_state != Destroyed); - _state = Destroyed; - _nextAction = None; - notifyAll(); - return true; + Lock sync(*this); + if(_state != Disconnected) + { + return false; // Nothing we can do for now. + } + assert(_state != Destroyed); + _state = Destroyed; + _nextAction = None; + notifyAll(); + return true; } void terminate(bool destroySession = true) { - Lock sync(*this); - if(_state == Destroyed) - { - return; - } - assert(_state != Destroyed); - _state = Destroyed; - _nextAction = destroySession ? Disconnect : None; - notifyAll(); + Lock sync(*this); + if(_state == Destroyed) + { + return; + } + assert(_state != Destroyed); + _state = Destroyed; + _nextAction = destroySession ? Disconnect : None; + notifyAll(); } TPrx getSession() { - Lock sync(*this); - return _session; + Lock sync(*this); + return _session; } void setRegistry(const InternalRegistryPrx& registry) { - Lock sync(*this); - _registry = registry; + Lock sync(*this); + _registry = registry; } InternalRegistryPrx getRegistry() const { - Lock sync(*this); - return _registry; + Lock sync(*this); + return _registry; } virtual TPrx createSession(InternalRegistryPrx&, IceUtil::Time&) = 0; |