diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-12-05 22:31:29 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-12-05 22:31:29 +0000 |
commit | 7abe0bb2e951d22f67f34d38bd4892f30ad901bb (patch) | |
tree | 4844d8f0ed9c4988f5ec8988aa313b1f47f15162 /cpp/demo/IcePack/hello/HelloI.cpp | |
parent | Added support for object lookup by identity (diff) | |
download | ice-7abe0bb2e951d22f67f34d38bd4892f30ad901bb.tar.bz2 ice-7abe0bb2e951d22f67f34d38bd4892f30ad901bb.tar.xz ice-7abe0bb2e951d22f67f34d38bd4892f30ad901bb.zip |
Added IcePack object registry.
Added support for locator object lookup by identity.
Added Query interface to lookup objects by type.
Changed the IcePack.Registry.Locator properties to IcePack.Registry.Client
Changed the IcePack.Registry.LocatorRegistry properties to
IcePack.Registry.Se rver
Added IcePack demo
Minor fixes and clean-up
Diffstat (limited to 'cpp/demo/IcePack/hello/HelloI.cpp')
-rw-r--r-- | cpp/demo/IcePack/hello/HelloI.cpp | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/cpp/demo/IcePack/hello/HelloI.cpp b/cpp/demo/IcePack/hello/HelloI.cpp new file mode 100644 index 00000000000..bb93e45421d --- /dev/null +++ b/cpp/demo/IcePack/hello/HelloI.cpp @@ -0,0 +1,137 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// ZeroC, Inc. +// Billerica, MA, USA +// +// All Rights Reserved. +// +// Ice is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IcePack/Admin.h> +#include <HelloI.h> + +using namespace std; + +HelloFactoryI::HelloFactoryI() +{ +} + +HelloPrx +HelloFactoryI::create(const string& name, const Ice::Current& current) +{ + Ice::ObjectAdapterPtr adapter = current.adapter; + Ice::CommunicatorPtr communicator = adapter->getCommunicator(); + + // + // Create the servant and add it to the object adapter using the + // given name as the identity. + // + Ice::ObjectPtr hello = new HelloI(name); + Ice::ObjectPrx object = adapter->add(hello, Ice::stringToIdentity(name)); + + // + // Get the IcePack Admin interface and register the newly created + // Hello object with the IcePack object registry. + // + try + { + IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(communicator->stringToProxy("IcePack/Admin")); + admin->addObject(object); + } + catch(const IcePack::ObjectExistsException&) + { + // + // An object with the same identity is already registered with + // the registry. Remove the object from the object adapter and + // throw. + // + adapter->remove(object->ice_getIdentity()); + throw NameExistsException(); + } + + string id = communicator->getProperties()->getProperty("Identity"); + + cout << "HelloFactory-" << id << ": created Hello object named '" << name << "'" << endl; + + return HelloPrx::uncheckedCast(object); +} + +HelloPrx +HelloFactoryI::find(const string& name, const Ice::Current& current) const +{ + Ice::CommunicatorPtr communicator = current.adapter->getCommunicator(); + + // + // The object is registered with the IcePack object registry so we + // just return a proxy containing the identity. + // + try + { + return HelloPrx::checkedCast(communicator->stringToProxy(name)); + } + catch(const Ice::NoEndpointException&) + { + // + // The object couldn't be activated. Ignore. + // + return HelloPrx::uncheckedCast(communicator->stringToProxy(name)); + } + catch(const Ice::NotRegisteredException&) + { + // + // The object is not registered. + // + throw NameNotExistException(); + } + catch(const Ice::ObjectNotExistException&) + { + // + // The object doesn't exist anymore. This can occur if the + // server has been restarted and the server objects haven't + // been removed from the object registry. + // + IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(communicator->stringToProxy("IcePack/Admin")); + admin->removeObject(communicator->stringToProxy(name)); + throw NameNotExistException(); + } +} + +HelloI::HelloI(const string& n) +{ + name = n; +} + +void +HelloI::sayHello(const Ice::Current&) const +{ + cout << name << " say Hello World!" << endl; +} + +void +HelloI::destroy(const Ice::Current& current) +{ + Ice::ObjectAdapterPtr adapter = current.adapter; + Ice::CommunicatorPtr communicator = adapter->getCommunicator(); + + // + // Get the IcePack Admin interface and remove the Hello object + // from the IcePack object registry. + // + IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(communicator->stringToProxy("IcePack/Admin")); + admin->removeObject(adapter->createProxy(current.id)); + + // + // Remove the Hello object from the object adapter. + // + adapter->remove(current.id); + + string id = communicator->getProperties()->getProperty("Identity"); + + cout << "HelloFactory-" << id << ": destroyed Hello object named '" << name << "'" << endl; +} |