summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/session/SessionI.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-04-19 00:24:08 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-04-19 00:24:08 +0000
commit985f18404d3b00ef445ea44619fad548da549ff0 (patch)
tree383f58b121b52227cd05cfb0851205656acc5443 /cpp/demo/Ice/session/SessionI.cpp
parentfix for bug 243: python demos lack mutex protection (diff)
downloadice-985f18404d3b00ef445ea44619fad548da549ff0.tar.bz2
ice-985f18404d3b00ef445ea44619fad548da549ff0.tar.xz
ice-985f18404d3b00ef445ea44619fad548da549ff0.zip
addressed comments added by Marc.
Diffstat (limited to 'cpp/demo/Ice/session/SessionI.cpp')
-rwxr-xr-xcpp/demo/Ice/session/SessionI.cpp86
1 files changed, 34 insertions, 52 deletions
diff --git a/cpp/demo/Ice/session/SessionI.cpp b/cpp/demo/Ice/session/SessionI.cpp
index 75569accf48..add61597ff2 100755
--- a/cpp/demo/Ice/session/SessionI.cpp
+++ b/cpp/demo/Ice/session/SessionI.cpp
@@ -14,6 +14,7 @@ using namespace std;
using namespace Demo;
// XXX Add using namespace Ice.
+// Style: the other demos do not use namespace Ice.
class HelloI : public Hello
{
@@ -26,15 +27,13 @@ public:
~HelloI()
{
- // XXX Use real output, something like "`Hello' object #xxx
- // destroyed.", not programming language style output.
- cout << _id << ": ~Hello" << endl;
+ cout << "Hello object #" << _id << " destroyed" << endl;
}
void
sayHello(const Ice::Current&) const
{
- cout << _id << ": Hello World!" << endl;
+ cout << "Hello object #" << _id << " says 'Hello World!'" << endl;
}
private:
@@ -42,27 +41,11 @@ private:
const int _id;
};
-SessionI::SessionI(const Ice::ObjectAdapterPtr& adapter, const IceUtil::Time& timeout) :
- _adapter(adapter),
- _timeout(timeout),
- _destroy(false),
- _refreshTime(IceUtil::Time::now()),
- _nextId(0)
-{
-}
-
-SessionI::~SessionI()
-{
- // XXX Remove, or add user-readable comment.
- cout << "~SessionI" << endl;
-}
-
HelloPrx
-SessionI::createHello(const Ice::Current&)
+SessionI::createHello(const Ice::Current& c)
{
Lock sync(*this);
- // XXX Check for destruction w/ ObjectNotExistException?
- HelloPrx hello = HelloPrx::uncheckedCast(_adapter->addWithUUID(new HelloI(_nextId++)));
+ HelloPrx hello = HelloPrx::uncheckedCast(c.adapter->addWithUUID(new HelloI(_nextId++)));
_objs.push_back(hello);
return hello;
}
@@ -71,48 +54,47 @@ void
SessionI::refresh(const Ice::Current& c)
{
Lock sync(*this);
- // XXX Check for destruction w/ ObjectNotExistException?
- _refreshTime = IceUtil::Time::now();
+ _timestamp = IceUtil::Time::now();
}
void
SessionI::destroy(const Ice::Current& c)
{
Lock sync(*this);
- // XXX Check for destruction w/ ObjectNotExistException?
_destroy = true;
- // XXX Add cleanup from the so-called "destroyCallback" here.
-}
-bool
-SessionI::destroyed() const
-{
- // XXX This should only check for _destroy. A reaper thread should
- // call destroy() if there was a timeout.
- Lock sync(*this);
- return _destroy || (IceUtil::Time::now() - _refreshTime) > _timeout;
+ cout << "The session #" << Ice::identityToString(c.id) << " is now destroyed." << endl;
+ try
+ {
+ c.adapter->remove(c.id);
+ for(list<HelloPrx>::const_iterator p = _objs.begin(); p != _objs.end(); ++p)
+ {
+ c.adapter->remove((*p)->ice_getIdentity());
+ }
+ }
+ catch(const Ice::ObjectAdapterDeactivatedException&)
+ {
+ // This method is called on shutdown of the server, in which
+ // case this exception is expected.
+ }
+
+ _objs.clear();
}
-// XXX Get rid of this function, remove the hello objects from the
-// object adapter in destroy().
-void
-SessionI::destroyCallback()
+IceUtil::Time
+SessionI::timestamp() const
{
Lock sync(*this);
- // XXX Real output please, that is appropriate for a demo.
- cout << "SessionI::destroyCallback: _destroy=" << _destroy << " timeout="
- << ((IceUtil::Time::now()-_refreshTime) > _timeout) << endl;
- for(list<HelloPrx>::const_iterator p = _objs.begin(); p != _objs.end(); ++p)
+ if(_destroy)
{
- try
- {
- _adapter->remove((*p)->ice_getIdentity());
- }
- catch(const Ice::ObjectAdapterDeactivatedException&)
- {
- // This method is called on shutdown of the server, in
- // which case this exception is expected.
- }
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
- _objs.clear();
+ return _timestamp;
+}
+
+SessionI::SessionI() :
+ _timestamp(IceUtil::Time::now()),
+ _nextId(0),
+ _destroy(false)
+{
}