summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/ObserverSessionI.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2005-06-09 14:33:56 +0000
committerBenoit Foucher <benoit@zeroc.com>2005-06-09 14:33:56 +0000
commitdd4155ec2f0c543061e3a08d0938c5f8aff227c7 (patch)
tree5feac0309fb01f2da479179ddc23d93a407ceae9 /cpp/src/IceGrid/ObserverSessionI.cpp
parentadding support classes for CLDC support (diff)
downloadice-dd4155ec2f0c543061e3a08d0938c5f8aff227c7.tar.bz2
ice-dd4155ec2f0c543061e3a08d0938c5f8aff227c7.tar.xz
ice-dd4155ec2f0c543061e3a08d0938c5f8aff227c7.zip
Added support for sessions and node/registry observers
Diffstat (limited to 'cpp/src/IceGrid/ObserverSessionI.cpp')
-rw-r--r--cpp/src/IceGrid/ObserverSessionI.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/ObserverSessionI.cpp b/cpp/src/IceGrid/ObserverSessionI.cpp
new file mode 100644
index 00000000000..fc25b51f87b
--- /dev/null
+++ b/cpp/src/IceGrid/ObserverSessionI.cpp
@@ -0,0 +1,106 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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 <Ice/Ice.h>
+#include <IceGrid/ObserverSessionI.h>
+
+using namespace std;
+using namespace IceGrid;
+
+ObserverSessionI::ObserverSessionI(const string& userId,
+ const IceStorm::TopicPrx& registryObserverTopic,
+ const IceStorm::TopicPrx& nodeObserverTopic) :
+ _userId(userId),
+ _destroyed(false),
+ _registryObserverTopic(registryObserverTopic),
+ _nodeObserverTopic(nodeObserverTopic)
+{
+}
+
+void
+ObserverSessionI::setObservers(const RegistryObserverPrx& registryObserver,
+ const NodeObserverPrx& nodeObserver,
+ const Ice::Current& current)
+{
+ Lock sync(*this);
+ if(_destroyed)
+ {
+ Ice::ObjectNotExistException ex(__FILE__, __LINE__);
+ ex.id = current.id;
+ throw ex;
+ }
+
+ _registryObserver = registryObserver;
+ _nodeObserver = nodeObserver;
+
+ //
+ // Subscribe to the topics.
+ //
+ IceStorm::QoS qos;
+ qos["reliability"] = "twoway ordered";
+ _registryObserverTopic->subscribe(qos, registryObserver);
+ _nodeObserverTopic->subscribe(qos, nodeObserver);
+}
+
+void
+ObserverSessionI::destroy(const Ice::Current&)
+{
+ //
+ // Unsubscribe from the topics.
+ //
+ _registryObserverTopic->unsubscribe(_registryObserver);
+ _nodeObserverTopic->unsubscribe(_nodeObserver);
+}
+
+LocalObserverSessionI::LocalObserverSessionI(const string& userId,
+ const IceStorm::TopicPrx& registryObserverTopic,
+ const IceStorm::TopicPrx& nodeObserverTopic) :
+ ObserverSessionI(userId, registryObserverTopic, nodeObserverTopic),
+ _timestamp(IceUtil::Time::now())
+{
+}
+
+void
+LocalObserverSessionI::keepAlive(const Ice::Current& current)
+{
+ Lock sync(*this);
+ if(_destroyed)
+ {
+ Ice::ObjectNotExistException ex(__FILE__, __LINE__);
+ ex.id = current.id;
+ throw ex;
+ }
+
+ _timestamp = IceUtil::Time::now();
+}
+
+IceUtil::Time
+LocalObserverSessionI::timestamp() const
+{
+ Lock sync(*this);
+ return _timestamp;
+}
+
+Glacier2ObserverSessionI::Glacier2ObserverSessionI(const string& userId,
+ const IceStorm::TopicPrx& registryObserverTopic,
+ const IceStorm::TopicPrx& nodeObserverTopic) :
+ ObserverSessionI(userId, registryObserverTopic, nodeObserverTopic)
+{
+}
+
+void
+Glacier2ObserverSessionI::keepAlive(const Ice::Current&)
+{
+}
+
+IceUtil::Time
+Glacier2ObserverSessionI::timestamp() const
+{
+ return IceUtil::Time();
+}