diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-04-24 09:46:12 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-04-24 09:46:12 +0000 |
commit | a5fdbf7412b96cecd45314f9d9eb37aaf77a2bf1 (patch) | |
tree | a2f26b3e3207ac925239385101f18a5459da1664 /cpp | |
parent | Unix Fix. (diff) | |
download | ice-a5fdbf7412b96cecd45314f9d9eb37aaf77a2bf1.tar.bz2 ice-a5fdbf7412b96cecd45314f9d9eb37aaf77a2bf1.tar.xz ice-a5fdbf7412b96cecd45314f9d9eb37aaf77a2bf1.zip |
Added first cut of the allocation mechanism.
Diffstat (limited to 'cpp')
37 files changed, 1523 insertions, 81 deletions
diff --git a/cpp/slice/IceGrid/Admin.ice b/cpp/slice/IceGrid/Admin.ice index a8428d96fd8..98a246cf2b1 100644 --- a/cpp/slice/IceGrid/Admin.ice +++ b/cpp/slice/IceGrid/Admin.ice @@ -97,6 +97,13 @@ struct ObjectInfo * **/ string type; + + /** + * + * Specifies if the object can be allocated. + * + **/ + bool allocatable; }; /** diff --git a/cpp/slice/IceGrid/Descriptor.ice b/cpp/slice/IceGrid/Descriptor.ice index 36cfc1bf48d..3c82fb09c6b 100644 --- a/cpp/slice/IceGrid/Descriptor.ice +++ b/cpp/slice/IceGrid/Descriptor.ice @@ -73,6 +73,13 @@ struct ObjectDescriptor * **/ string type; + + /** + * + * Specifies if the object is allocatable. + * + **/ + bool allocatable; }; /** diff --git a/cpp/slice/IceGrid/Query.ice b/cpp/slice/IceGrid/Query.ice index 939145263ad..487e9761aeb 100644 --- a/cpp/slice/IceGrid/Query.ice +++ b/cpp/slice/IceGrid/Query.ice @@ -38,7 +38,7 @@ enum LoadSample * &Ice; clients who wish to lookup objects. * **/ -interface Query +["ami", "amd"] interface Query { /** * diff --git a/cpp/slice/IceGrid/Session.ice b/cpp/slice/IceGrid/Session.ice index 82f5e720a44..50bf5be57e2 100644 --- a/cpp/slice/IceGrid/Session.ice +++ b/cpp/slice/IceGrid/Session.ice @@ -24,7 +24,7 @@ exception AllocationTimeoutException { }; -exception AllocationFailedException +exception AllocationException { string reason; }; @@ -67,8 +67,8 @@ interface Session extends Glacier2::Session * timeout is reached. * **/ - void allocateObject(Object* prx) - throws AllocationTimeoutException, AllocationFailedException; + ["ami", "amd"] void allocateObject(Object* prx) + throws ObjectNotRegisteredException, AllocationTimeoutException, AllocationException; /** * @@ -76,7 +76,7 @@ interface Session extends Glacier2::Session * **/ void releaseObject(Object* prx) - throws AllocationFailedException; + throws ObjectNotRegisteredException, AllocationException; /** * diff --git a/cpp/src/IceBox/Makefile b/cpp/src/IceBox/Makefile index 3d616795891..be838688b9f 100644 --- a/cpp/src/IceBox/Makefile +++ b/cpp/src/IceBox/Makefile @@ -57,7 +57,7 @@ $(libdir)/$(LIBNAME): $(libdir)/$(SONAME) $(SERVER): $(SOBJS) $(LIBTARGETS) rm -f $@ - $(CXX) $(LDFLAGS) -o $@ $(SOBJS) -lIceBox $(LIBS) + $(CXX) $(LDFLAGS) -o $@ $(SOBJS) -lIceStorm -lIceBox $(LIBS) $(ADMIN): $(AOBJS) $(LIBTARGETS) rm -f $@ diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp index a07ee5b4b67..243ce14a8f4 100644 --- a/cpp/src/IceGrid/AdminSessionI.cpp +++ b/cpp/src/IceGrid/AdminSessionI.cpp @@ -16,10 +16,11 @@ using namespace IceGrid; AdminSessionI::AdminSessionI(const string& userId, const DatabasePtr& database, + const Ice::ObjectAdapterPtr& adapter, RegistryObserverTopic& registryObserverTopic, NodeObserverTopic& nodeObserverTopic, int timeout) : - SessionI(userId, "admin", database, timeout), + SessionI(userId, "admin", database, adapter, timeout), _updating(false), _registryObserverTopic(registryObserverTopic), _nodeObserverTopic(nodeObserverTopic) @@ -267,16 +268,16 @@ AdminSessionManagerI::create(const string& userId, const Glacier2::SessionContro // We don't add the session to the reaper thread, Glacier2 takes // care of reaping the session. // - SessionIPtr session = - new AdminSessionI(userId, _database, _registryObserverTopic, _nodeObserverTopic, _sessionTimeout); + SessionIPtr session = new AdminSessionI(userId, _database, current.adapter, _registryObserverTopic, + _nodeObserverTopic, _sessionTimeout); return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session)); } SessionPrx AdminSessionManagerI::createLocalSession(const string& userId, const Ice::Current& current) { - SessionIPtr session = - new AdminSessionI(userId, _database, _registryObserverTopic, _nodeObserverTopic, _sessionTimeout); + SessionIPtr session = new AdminSessionI(userId, _database, current.adapter, _registryObserverTopic, + _nodeObserverTopic, _sessionTimeout); SessionPrx proxy = SessionPrx::uncheckedCast(current.adapter->addWithUUID(session)); _reaper->add(new SessionReapable(session, proxy)); return proxy; diff --git a/cpp/src/IceGrid/AdminSessionI.h b/cpp/src/IceGrid/AdminSessionI.h index 3b3c4e831dd..38eb00653b9 100644 --- a/cpp/src/IceGrid/AdminSessionI.h +++ b/cpp/src/IceGrid/AdminSessionI.h @@ -20,7 +20,8 @@ class AdminSessionI : public SessionI, public AdminSession { public: - AdminSessionI(const std::string&, const DatabasePtr&, RegistryObserverTopic&, NodeObserverTopic&, int); + AdminSessionI(const std::string&, const DatabasePtr&, const Ice::ObjectAdapterPtr&, RegistryObserverTopic&, + NodeObserverTopic&, int); virtual ~AdminSessionI(); virtual AdminPrx getAdmin(const Ice::Current&) const; diff --git a/cpp/src/IceGrid/Allocatable.cpp b/cpp/src/IceGrid/Allocatable.cpp new file mode 100644 index 00000000000..4760bafe09b --- /dev/null +++ b/cpp/src/IceGrid/Allocatable.cpp @@ -0,0 +1,187 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <IceGrid/Allocatable.h> +#include <IceGrid/SessionI.h> + +using namespace std; +using namespace IceGrid; + +AllocationRequest::~AllocationRequest() +{ +} + +bool +AllocationRequest::setAllocatable(const AllocatablePtr& allocatable) +{ + Lock sync(*this); + assert(!_allocatable); + if(_canceled) + { + return false; + } + _allocatable = allocatable; + allocated(_allocatable); + return true; +} + +void +AllocationRequest::cancel() +{ + Lock sync(*this); + if(_canceled) + { + return; + } + _canceled = true; + canceled(); +} + +bool +AllocationRequest::checkTimeout(const IceUtil::Time& now) +{ + assert(_timeout > 0); + { + Lock sync(*this); + if(_canceled) + { + return true; + } + _canceled = _expiration < now; + if(!_canceled) + { + return false; + } + timeout(); + } + _session->removeAllocationRequest(this); + return true; +} + +void +AllocationRequest::allocate() +{ + _session->addAllocationRequest(this); +} + +void +AllocationRequest::release(const SessionIPtr& session) +{ + // + // Check if the session releasing the object is indeed the session + // which initiated the allocation request. + // + if(_session != session) + { + throw AllocationException("can't release object which is not allocated"); + } + _session->removeAllocationRequest(this); +} + +bool +AllocationRequest::operator<(const AllocationRequest& r) const +{ + return this < &r; +} + +AllocationRequest::AllocationRequest(const SessionIPtr& session) : + _session(session), + _timeout(_session->getAllocationTimeout()), + _expiration(_timeout > 0 ? (IceUtil::Time::now() + IceUtil::Time::milliSeconds(_timeout)) : IceUtil::Time()), + _canceled(false) +{ +} + +Allocatable::Allocatable(bool allocatable) : _allocatable(allocatable), _allocated(false) +{ +} + +Allocatable::~Allocatable() +{ +} + +void +Allocatable::allocate(const AllocationRequestPtr& request, bool allocateOnce) +{ + IceUtil::Mutex::Lock sync(_allocateMutex); + if(_allocatable) + { + if(_allocated) + { + if(_allocated->getSession() == request->getSession()) + { + if(allocateOnce) + { + throw AllocationException("object already allocated by the session"); + } + request->setAllocatable(this); + } + else if(request->getTimeout()) + { + request->allocate(); + _requests.push_back(request); // TODO: XXX: monitor request timeout if timeout != -1 + } + else + { + request->timeout(); + } + } + else if(request->setAllocatable(this)) + { + _allocated = request; + _allocated->allocate(); + } + } + else + { + if(allocateOnce) + { + throw AllocationException("can't allocate non allocatable object"); + } + bool rc = request->setAllocatable(this); + assert(rc); + } +} + +bool +Allocatable::tryAllocate(const AllocationRequestPtr& request) +{ + IceUtil::Mutex::Lock sync(_allocateMutex); + if(_allocatable && _allocated) + { + return false; + } + else if(request->setAllocatable(this)) + { + _allocated = request; + _allocated->allocate(); + } + return true; +} + +void +Allocatable::release(const SessionIPtr& session) +{ + IceUtil::Mutex::Lock sync(_allocateMutex); + if(!_allocated) + { + throw AllocationException("object not allocated"); + } + _allocated->release(session); + while(!_requests.empty()) + { + _allocated = _requests.front(); + _requests.pop_front(); + if(_allocated->setAllocatable(this)) + { + return; + } + } + _allocated = 0; +} diff --git a/cpp/src/IceGrid/Allocatable.h b/cpp/src/IceGrid/Allocatable.h new file mode 100644 index 00000000000..0e315036223 --- /dev/null +++ b/cpp/src/IceGrid/Allocatable.h @@ -0,0 +1,86 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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. +// +// ********************************************************************** + +#ifndef ICE_GRID_ALLOCATABLE_H +#define ICE_GRID_ALLOCATABLE_H + +#include <IceUtil/Handle.h> +#include <IceUtil/Mutex.h> +#include <IceUtil/Shared.h> +#include <IceUtil/Time.h> +#include <list> + +namespace IceGrid +{ + +class SessionI; +typedef IceUtil::Handle<SessionI> SessionIPtr; + +class Allocatable; +typedef IceUtil::Handle<Allocatable> AllocatablePtr; + +class AllocationRequest : public IceUtil::Mutex, public IceUtil::Shared +{ +public: + + virtual ~AllocationRequest(); + + virtual void timeout() = 0; + virtual void allocated(const AllocatablePtr&) = 0; + virtual void canceled() = 0; + + bool setAllocatable(const AllocatablePtr&); + bool checkTimeout(const IceUtil::Time&); + void cancel(); + void allocate(); + void release(const SessionIPtr&); + + int getTimeout() const { return _timeout; } + const SessionIPtr& getSession() const { return _session; } + + bool operator<(const AllocationRequest&) const; + +protected: + + AllocationRequest(const SessionIPtr&); + +private: + + const SessionIPtr _session; + const int _timeout; + const IceUtil::Time _expiration; + bool _canceled; + AllocatablePtr _allocatable; +}; +typedef IceUtil::Handle<AllocationRequest> AllocationRequestPtr; + +class Allocatable : public IceUtil::Shared +{ +public: + + Allocatable(bool); + virtual ~Allocatable(); + + void allocate(const AllocationRequestPtr&, bool); + bool tryAllocate(const AllocationRequestPtr&); + void release(const SessionIPtr&); + + bool allocatable() const { return _allocatable; } + +protected: + + bool _allocatable; + IceUtil::Mutex _allocateMutex; + std::list<AllocationRequestPtr> _requests; + AllocationRequestPtr _allocated; +}; + +}; + +#endif diff --git a/cpp/src/IceGrid/Cache.h b/cpp/src/IceGrid/Cache.h index ab50cfdce44..2fe35ff48ef 100644 --- a/cpp/src/IceGrid/Cache.h +++ b/cpp/src/IceGrid/Cache.h @@ -18,7 +18,6 @@ namespace IceGrid { - template<typename Key, typename Value> class Cache : public IceUtil::Mutex { diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index f0b9dcb3dfe..a81250ce712 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -950,12 +950,53 @@ Database::updateObject(const Ice::ObjectPrx& proxy) } } +void +Database::allocateObject(const Ice::Identity& id, const ObjectAllocationRequestPtr& request, bool allocateOnce) +{ + try + { + _objectCache.get(id)->allocate(request, allocateOnce); + return; + } + catch(ObjectNotRegisteredException&) + { + } + + Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); + IdentityObjectInfoDict objects(connection, _objectDbName); + IdentityObjectInfoDict::const_iterator p = objects.find(id); + if(p == objects.end()) + { + ObjectNotRegisteredException ex; + ex.id = id; + throw ex; + } + request->response(p->second.proxy); +} + +void +Database::releaseObject(const Ice::Identity& id, const SessionIPtr& session) +{ + try + { + _objectCache.get(id)->release(session); + return; + } + catch(ObjectNotRegisteredException&) + { + } +} + Ice::ObjectPrx Database::getObjectProxy(const Ice::Identity& id) { try { - return _objectCache.get(id)->getProxy(); + // + // Only return proxies for non allocatable objects. + // + ObjectEntryPtr entry = _objectCache.get(id); + return entry->allocatable() ? Ice::ObjectPrx() : entry->getProxy(); } catch(ObjectNotRegisteredException&) { diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h index ee0dc448650..791268fd8d4 100644 --- a/cpp/src/IceGrid/Database.h +++ b/cpp/src/IceGrid/Database.h @@ -87,6 +87,10 @@ public: void addObject(const ObjectInfo&); void removeObject(const Ice::Identity&); void updateObject(const Ice::ObjectPrx&); + + void allocateObject(const Ice::Identity&, const ObjectAllocationRequestPtr&, bool); + void releaseObject(const Ice::Identity&, const SessionIPtr&); + Ice::ObjectPrx getObjectProxy(const Ice::Identity&); Ice::ObjectPrx getObjectByType(const std::string&); Ice::ObjectPrx getObjectByTypeOnLeastLoadedNode(const std::string&, LoadSample); diff --git a/cpp/src/IceGrid/DescriptorBuilder.cpp b/cpp/src/IceGrid/DescriptorBuilder.cpp index 87482df7a8c..6f46b9f8bd1 100644 --- a/cpp/src/IceGrid/DescriptorBuilder.cpp +++ b/cpp/src/IceGrid/DescriptorBuilder.cpp @@ -293,6 +293,7 @@ ApplicationDescriptorBuilder::addObject(const XmlAttributesHelper& attrs) ObjectDescriptor object; object.type = attrs("type", ""); object.id = Ice::stringToIdentity(attrs("identity")); + object.allocatable = attrs.asBool("allocatable", false); _descriptor.replicaGroups.back().objects.push_back(object); } @@ -611,6 +612,7 @@ CommunicatorDescriptorBuilder::addObject(const XmlAttributesHelper& attrs) ObjectDescriptor object; object.type = attrs("type", ""); object.id = Ice::stringToIdentity(attrs("identity")); + object.allocatable = attrs.asBool("allocatable", false); _descriptor->adapters.back().objects.push_back(object); } diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index c1c93f30e9b..c50e54667d6 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -735,6 +735,7 @@ CommunicatorHelper::instantiateImpl(const CommunicatorDescriptorPtr& instance, c ObjectDescriptor obj; obj.type = resolve(q->type, "object type"); obj.id = Ice::stringToIdentity(resolve(Ice::identityToString(q->id), "object identity", false)); + obj.allocatable = q->allocatable; if(obj.id.name.empty()) { resolve.exception("invalid object identity `" + Ice::identityToString(q->id) + "': name empty"); diff --git a/cpp/src/IceGrid/LocatorI.cpp b/cpp/src/IceGrid/LocatorI.cpp index ee19b2c19f1..bcc2a893df7 100644 --- a/cpp/src/IceGrid/LocatorI.cpp +++ b/cpp/src/IceGrid/LocatorI.cpp @@ -310,6 +310,15 @@ LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr& cb, } // + // If the proxy is 0, this means that the object is allocatable. + // + if(!proxy) + { + cb->ice_response(0); + return; + } + + // // OPTIMIZATION: If the object is registered with an adapter id, // try to get the adapter direct proxy (which might caused the // server activation). This will avoid the client to lookup for diff --git a/cpp/src/IceGrid/Makefile b/cpp/src/IceGrid/Makefile index 7de85c965f9..cfb3f845ef8 100644 --- a/cpp/src/IceGrid/Makefile +++ b/cpp/src/IceGrid/Makefile @@ -56,6 +56,7 @@ REGISTRY_OBJS = RegistryI.o \ IdentityObjectInfoDict.o \ StringAdapterInfoDict.o \ Database.o \ + Allocatable.o \ AdapterCache.o \ ObjectCache.o \ ServerCache.o \ diff --git a/cpp/src/IceGrid/ObjectCache.cpp b/cpp/src/IceGrid/ObjectCache.cpp index a14e2b46928..d8d89d8583f 100644 --- a/cpp/src/IceGrid/ObjectCache.cpp +++ b/cpp/src/IceGrid/ObjectCache.cpp @@ -33,6 +33,7 @@ ObjectCache::add(const string& app, const string& adapterId, const string& endpo ObjectInfo info; info.type = desc.type; + info.allocatable = desc.allocatable; if(adapterId.empty()) { info.proxy = _communicator->stringToProxy(Ice::identityToString(desc.id) + ":" + endpoints); @@ -106,7 +107,11 @@ ObjectCache::getObjectsByType(const string& type) } for(set<Ice::Identity>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) { - proxies.push_back(getImpl(*q)->getProxy()); + ObjectEntryPtr entry = getImpl(*q); + if(!entry->allocatable()) + { + proxies.push_back(entry->getProxy()); + } } return proxies; } @@ -126,7 +131,8 @@ ObjectCache::getAll(const string& expression) return infos; } -ObjectEntry::ObjectEntry(Cache<Ice::Identity, ObjectEntry>&, const Ice::Identity&) +ObjectEntry::ObjectEntry(Cache<Ice::Identity, ObjectEntry>&, const Ice::Identity&) : + Allocatable(false) { } @@ -135,6 +141,7 @@ ObjectEntry::set(const string& app, const ObjectInfo& info) { _application = app; _info = info; + _allocatable = info.allocatable; } Ice::ObjectPrx diff --git a/cpp/src/IceGrid/ObjectCache.h b/cpp/src/IceGrid/ObjectCache.h index d89cd5858b8..cbc31e9405d 100644 --- a/cpp/src/IceGrid/ObjectCache.h +++ b/cpp/src/IceGrid/ObjectCache.h @@ -15,6 +15,7 @@ #include <Ice/CommunicatorF.h> #include <IceGrid/Cache.h> #include <IceGrid/Internal.h> +#include <IceGrid/Allocatable.h> namespace IceGrid { @@ -24,10 +25,7 @@ class ObjectCache; class ServerEntry; typedef IceUtil::Handle<ServerEntry> ServerEntryPtr; -class ObjectEntry; -typedef IceUtil::Handle<ObjectEntry> ObjectEntryPtr; - -class ObjectEntry : public IceUtil::Shared +class ObjectEntry : public Allocatable { public: @@ -67,6 +65,33 @@ private: std::map<std::string, std::set<Ice::Identity> > _types; }; +class ObjectAllocationRequest : public AllocationRequest +{ +public: + + ObjectAllocationRequest(const SessionIPtr& session) : AllocationRequest(session) { } + + virtual void response(const Ice::ObjectPrx&) = 0; + +private: + + virtual void allocated(const AllocatablePtr& allocatable) + { + response(ObjectEntryPtr::dynamicCast(allocatable)->getProxy()); + } + + virtual void timeout() + { + response(0); + } + + virtual void canceled() + { + response(0); + } +}; +typedef IceUtil::Handle<ObjectAllocationRequest> ObjectAllocationRequestPtr; + }; #endif diff --git a/cpp/src/IceGrid/QueryI.cpp b/cpp/src/IceGrid/QueryI.cpp index 74133e0a64d..e317bc4eee4 100644 --- a/cpp/src/IceGrid/QueryI.cpp +++ b/cpp/src/IceGrid/QueryI.cpp @@ -10,14 +10,39 @@ #include <IceGrid/Internal.h> #include <IceGrid/QueryI.h> #include <IceGrid/Database.h> +#include <IceGrid/ObjectCache.h> +#include <IceGrid/SessionI.h> using namespace std; using namespace Ice; using namespace IceGrid; -QueryI::QueryI(const CommunicatorPtr& communicator, const DatabasePtr& database) : +class GetObjectProxy : public ObjectAllocationRequest +{ +public: + + GetObjectProxy(const SessionIPtr& session, const AMD_Query_findObjectByIdPtr& cb) : + ObjectAllocationRequest(session), _cb(cb) + { + } + + virtual void + response(const Ice::ObjectPrx& proxy) + { + assert(_cb); + _cb->ice_response(proxy); + _cb = 0; + } + +private: + + AMD_Query_findObjectByIdPtr _cb; +}; + +QueryI::QueryI(const CommunicatorPtr& communicator, const DatabasePtr& database, const SessionIPtr& session) : _communicator(communicator), - _database(database) + _database(database), + _session(session) { } @@ -25,55 +50,67 @@ QueryI::~QueryI() { } -Ice::ObjectPrx -QueryI::findObjectById(const Ice::Identity& id, const Ice::Current&) const +void +QueryI::findObjectById_async(const AMD_Query_findObjectByIdPtr& cb, const Ice::Identity& id, const Ice::Current&) const { try { - return _database->getObjectProxy(id); + if(_session) + { + _database->allocateObject(id, new GetObjectProxy(_session, cb), false); + } + else + { + cb->ice_response(_database->getObjectProxy(id)); + } } catch(const ObjectNotRegisteredException&) { - return 0; + cb->ice_response(0); } } -Ice::ObjectPrx -QueryI::findObjectByType(const string& type, const Ice::Current&) const +void +QueryI::findObjectByType_async(const AMD_Query_findObjectByTypePtr& cb, const string& type, const Ice::Current&) const { try { - return _database->getObjectByType(type); + cb->ice_response(_database->getObjectByType(type)); } catch(const ObjectNotRegisteredException&) { - return 0; + cb->ice_response(0); } } -Ice::ObjectPrx -QueryI::findObjectByTypeOnLeastLoadedNode(const string& type, LoadSample sample, const Ice::Current&) const +void +QueryI::findObjectByTypeOnLeastLoadedNode_async(const AMD_Query_findObjectByTypeOnLeastLoadedNodePtr& cb, + const string& type, + LoadSample sample, + const Ice::Current&) const { try { - return _database->getObjectByTypeOnLeastLoadedNode(type, sample); + cb->ice_response(_database->getObjectByTypeOnLeastLoadedNode(type, sample)); } catch(const ObjectNotRegisteredException&) { - return 0; + cb->ice_response(0); } } -Ice::ObjectProxySeq -QueryI::findAllObjectsByType(const string& type, const Ice::Current&) const +void +QueryI::findAllObjectsByType_async(const AMD_Query_findAllObjectsByTypePtr& cb, + const string& type, + const Ice::Current&) const { try { - return _database->getObjectsByType(type); + cb->ice_response(_database->getObjectsByType(type)); } catch(const ObjectNotRegisteredException&) { - return Ice::ObjectProxySeq(); + cb->ice_response(Ice::ObjectProxySeq()); } } diff --git a/cpp/src/IceGrid/QueryI.h b/cpp/src/IceGrid/QueryI.h index 423dcd23c64..072345eda1a 100644 --- a/cpp/src/IceGrid/QueryI.h +++ b/cpp/src/IceGrid/QueryI.h @@ -19,23 +19,34 @@ namespace IceGrid class Database; typedef IceUtil::Handle<Database> DatabasePtr; +class SessionI; +typedef IceUtil::Handle<SessionI> SessionIPtr; + class QueryI : public Query, public IceUtil::Mutex { public: - QueryI(const Ice::CommunicatorPtr&, const DatabasePtr&); + QueryI(const Ice::CommunicatorPtr&, const DatabasePtr&, const SessionIPtr&); virtual ~QueryI(); - virtual ::Ice::ObjectPrx findObjectById(const ::Ice::Identity&, const ::Ice::Current&) const; - virtual ::Ice::ObjectPrx findObjectByType(const ::std::string&, const ::Ice::Current&) const; - virtual ::Ice::ObjectPrx findObjectByTypeOnLeastLoadedNode(const ::std::string&, LoadSample, - const ::Ice::Current&) const; - virtual ::Ice::ObjectProxySeq findAllObjectsByType(const ::std::string&, const ::Ice::Current&) const; + virtual void findObjectById_async(const AMD_Query_findObjectByIdPtr&, const ::Ice::Identity&, + const ::Ice::Current&) const; + + virtual void findObjectByType_async(const AMD_Query_findObjectByTypePtr&, const ::std::string&, + const ::Ice::Current&) const; + + virtual void findObjectByTypeOnLeastLoadedNode_async(const AMD_Query_findObjectByTypeOnLeastLoadedNodePtr&, + const ::std::string&, LoadSample, + const ::Ice::Current&) const; + + virtual void findAllObjectsByType_async(const AMD_Query_findAllObjectsByTypePtr&, const ::std::string&, + const ::Ice::Current&) const; private: - Ice::CommunicatorPtr _communicator; - DatabasePtr _database; + const Ice::CommunicatorPtr _communicator; + const DatabasePtr _database; + const SessionIPtr _session; }; } diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index bb8ef76e42d..6691fd1d1f3 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -234,23 +234,29 @@ RegistryI::start(bool nowarn) // Create the query, admin, session manager interfaces // Identity queryId = stringToIdentity(instanceName + "/Query"); - clientAdapter->add(new QueryI(_communicator, _database), queryId); + clientAdapter->add(new QueryI(_communicator, _database, 0), queryId); + + ReapThreadPtr reaper = _adminReaper ? _adminReaper : _reaper; // TODO: XXX + + Identity sessionMgrId = stringToIdentity(instanceName + "/SessionManager"); + ObjectPtr sessionMgr = new ClientSessionManagerI(_database, reaper, adminSessionTimeout); // TODO: XXX + clientAdapter->add(sessionMgr, sessionMgrId); Identity adminId = stringToIdentity(instanceName + "/Admin"); adminAdapter->add(new AdminI(_database, this, traceLevels), adminId); - Identity sessionManagerId = stringToIdentity(instanceName + "/SessionManager"); - ReapThreadPtr reaper = _adminReaper ? _adminReaper : _reaper; - ObjectPtr sessionMgr = new AdminSessionManagerI(*regTopic, *nodeTopic, _database, reaper, adminSessionTimeout); - adminAdapter->add(sessionMgr, sessionManagerId); + Identity admSessionMgrId = stringToIdentity(instanceName + "/AdminSessionManager"); + ObjectPtr admSessionMgr = new AdminSessionManagerI(*regTopic, *nodeTopic, _database, reaper, adminSessionTimeout); + adminAdapter->add(admSessionMgr, admSessionMgrId); // // Register well known objects with the object registry. // addWellKnownObject(registryAdapter->createProxy(registryId), Registry::ice_staticId()); addWellKnownObject(clientAdapter->createProxy(queryId), Query::ice_staticId()); + addWellKnownObject(clientAdapter->createProxy(sessionMgrId), SessionManager::ice_staticId()); addWellKnownObject(adminAdapter->createProxy(adminId), Admin::ice_staticId()); - addWellKnownObject(adminAdapter->createProxy(sessionManagerId), SessionManager::ice_staticId()); + addWellKnownObject(adminAdapter->createProxy(admSessionMgrId), SessionManager::ice_staticId()); // // We are ready to go! diff --git a/cpp/src/IceGrid/SessionI.cpp b/cpp/src/IceGrid/SessionI.cpp index 75210a23b22..fd4c003978f 100644 --- a/cpp/src/IceGrid/SessionI.cpp +++ b/cpp/src/IceGrid/SessionI.cpp @@ -9,11 +9,44 @@ #include <Ice/Ice.h> #include <IceGrid/SessionI.h> +#include <IceGrid/QueryI.h> #include <IceGrid/Database.h> using namespace std; using namespace IceGrid; +class AllocateObject : public ObjectAllocationRequest +{ +public: + + AllocateObject(const SessionIPtr& session, const AMD_Session_allocateObjectPtr& cb) : + ObjectAllocationRequest(session), _cb(cb) + { + } + + virtual void response(const Ice::ObjectPrx& proxy) + { + assert(_cb); + if(proxy) + { + _cb->ice_response(); + } + else + { + // + // TODO: The request might also have been canceled! + // + + _cb->ice_exception(AllocationTimeoutException()); + } + _cb = 0; + } + +private: + + AMD_Session_allocateObjectPtr _cb; +}; + SessionReapable::SessionReapable(const SessionIPtr& session, const SessionPrx& proxy) : _session(session), _proxy(proxy) @@ -36,19 +69,30 @@ SessionReapable::destroy() _proxy->destroy(); } -SessionI::SessionI(const string& userId, const string& prefix, const DatabasePtr& database, int timeout) : +SessionI::SessionI(const string& userId, + const string& prefix, + const DatabasePtr& database, + const Ice::ObjectAdapterPtr& adapter, + int timeout) : _userId(userId), _prefix(prefix), _timeout(timeout), _traceLevels(database->getTraceLevels()), _database(database), - _destroyed(false) + _destroyed(false), + _allocationTimeout(-1) { if(_traceLevels && _traceLevels->session > 0) { Ice::Trace out(_traceLevels->logger, _traceLevels->sessionCat); out << _prefix << " session `" << _userId << "' created"; } + + // + // Register session based query and locator interfaces + // + _query = QueryPrx::uncheckedCast(adapter->addWithUUID(new QueryI(adapter->getCommunicator(), _database, this))); + //_locator = adapter->addWithUUID(new LocatorI()); } SessionI::~SessionI() @@ -84,45 +128,46 @@ SessionI::getTimeout(const Ice::Current&) const QueryPrx SessionI::getQuery(const Ice::Current& current) const { - // - // TODO: XXX - // - return QueryPrx::uncheckedCast( - current.adapter->getCommunicator()->stringToProxy(_database->getInstanceName() + "/Query")); + return _query; } Ice::LocatorPrx SessionI::getLocator(const Ice::Current& current) const { - // - // TODO: XXX - // - return Ice::LocatorPrx::uncheckedCast( - current.adapter->getCommunicator()->stringToProxy(_database->getInstanceName() + "/Locator")); + return _locator; } void -SessionI::allocateObject(const Ice::ObjectPrx& proxy, const Ice::Current&) +SessionI::allocateObject_async(const AMD_Session_allocateObjectPtr& cb, const Ice::ObjectPrx& prx, const Ice::Current&) { // - // TODO: XXX + // TODO: Check if the proxy points to a replicated object and eventually throw if that's the case. // + if(!prx) + { + throw AllocationException("proxy is null"); + } + _database->allocateObject(prx->ice_getIdentity(), new AllocateObject(this, cb), true); } void -SessionI::releaseObject(const Ice::ObjectPrx& proxy, const Ice::Current&) +SessionI::releaseObject(const Ice::ObjectPrx& prx, const Ice::Current&) { // - // TODO: XXX + // TODO: Check if the proxy points to a replicated object and eventually throw if that's the case. // + if(!prx) + { + throw AllocationException("proxy is null"); + } + _database->releaseObject(prx->ice_getIdentity(), this); } void SessionI::setAllocationTimeout(int timeout, const Ice::Current&) { - // - // TODO: XXX - // + Lock sync(*this); + _allocationTimeout = timeout; } void @@ -152,8 +197,30 @@ SessionI::timestamp() const return _timestamp; } -ClientSessionI::ClientSessionI(const string& userId, const DatabasePtr& database, int timeout) : - SessionI(userId, "client", database, timeout) +int +SessionI::getAllocationTimeout() const +{ + Lock sync(*this); + return _allocationTimeout; +} + +void +SessionI::addAllocationRequest(const AllocationRequestPtr& request) +{ + Lock sync(*this); + _allocations.insert(request); +} + +void +SessionI::removeAllocationRequest(const AllocationRequestPtr& request) +{ + Lock sync(*this); + _allocations.erase(request); +} + +ClientSessionI::ClientSessionI(const string& userId, const DatabasePtr& database, const Ice::ObjectAdapterPtr& adapter, + int timeout) : + SessionI(userId, "client", database, adapter, timeout) { } @@ -173,14 +240,14 @@ ClientSessionManagerI::create(const string& userId, const Glacier2::SessionContr // We don't add the session to the reaper thread, Glacier2 takes // care of reaping the session. // - SessionIPtr session = new ClientSessionI(userId, _database, _sessionTimeout); - return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session)); + SessionIPtr session = new ClientSessionI(userId, _database, current.adapter, _sessionTimeout); + return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session)); // TODO: XXX: category = userid? } SessionPrx ClientSessionManagerI::createLocalSession(const string& userId, const Ice::Current& current) { - SessionIPtr session = new ClientSessionI(userId, _database, _sessionTimeout); + SessionIPtr session = new ClientSessionI(userId, _database, current.adapter, _sessionTimeout); SessionPrx proxy = SessionPrx::uncheckedCast(current.adapter->addWithUUID(session)); _reaper->add(new SessionReapable(session, proxy)); return proxy; diff --git a/cpp/src/IceGrid/SessionI.h b/cpp/src/IceGrid/SessionI.h index 8e72d5b9cf5..2d8216e23b9 100644 --- a/cpp/src/IceGrid/SessionI.h +++ b/cpp/src/IceGrid/SessionI.h @@ -24,6 +24,9 @@ typedef IceUtil::Handle<Database> DatabasePtr; class TraceLevels; typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr; +class AllocationRequest; +typedef IceUtil::Handle<AllocationRequest> AllocationRequestPtr; + class SessionI; typedef IceUtil::Handle<SessionI> SessionIPtr; @@ -53,31 +56,39 @@ public: virtual int getTimeout(const Ice::Current&) const; virtual QueryPrx getQuery(const Ice::Current&) const; virtual Ice::LocatorPrx getLocator(const Ice::Current&) const; - virtual void allocateObject(const Ice::ObjectPrx&, const Ice::Current&); + virtual void allocateObject_async(const AMD_Session_allocateObjectPtr&, const Ice::ObjectPrx&,const Ice::Current&); virtual void releaseObject(const Ice::ObjectPrx&, const Ice::Current&); virtual void setAllocationTimeout(int, const Ice::Current&); virtual void destroy(const Ice::Current&); virtual IceUtil::Time timestamp() const; + virtual int getAllocationTimeout() const; + + void addAllocationRequest(const AllocationRequestPtr&); + void removeAllocationRequest(const AllocationRequestPtr&); protected: - SessionI(const std::string&, const std::string&, const DatabasePtr&, int); + SessionI(const std::string&, const std::string&, const DatabasePtr&, const Ice::ObjectAdapterPtr&, int); const std::string _userId; const std::string _prefix; const int _timeout; const TraceLevelsPtr _traceLevels; const DatabasePtr _database; + IceGrid::QueryPrx _query; + Ice::LocatorPrx _locator; bool _destroyed; IceUtil::Time _timestamp; + int _allocationTimeout; + std::set<AllocationRequestPtr> _allocations; }; class ClientSessionI : public SessionI { public: - ClientSessionI(const std::string&, const DatabasePtr&, int); + ClientSessionI(const std::string&, const DatabasePtr&, const Ice::ObjectAdapterPtr&, int); }; class ClientSessionManagerI : virtual public SessionManager diff --git a/cpp/test/IceGrid/Makefile b/cpp/test/IceGrid/Makefile index 07f49ab5f91..45af11a4680 100644 --- a/cpp/test/IceGrid/Makefile +++ b/cpp/test/IceGrid/Makefile @@ -12,7 +12,7 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules -SUBDIRS = simple deployer session update activation replication +SUBDIRS = simple deployer session update activation replication allocation $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cpp/test/IceGrid/allocation/.depend b/cpp/test/IceGrid/allocation/.depend new file mode 100644 index 00000000000..b82dd0db1ad --- /dev/null +++ b/cpp/test/IceGrid/allocation/.depend @@ -0,0 +1,4 @@ +Test.o: Test.cpp Test.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Config.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/StreamF.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/Object.h ../../../include/Ice/GCShared.h ../../../include/Ice/GCRecMutex.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/Ice/BasicStream.h ../../../include/Ice/InstanceF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/AutoArray.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/Direct.h ../../../include/Ice/LocalException.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/ObjectFactory.h ../../../include/IceUtil/Iterator.h +Client.o: Client.cpp ../../../include/Ice/Ice.h ../../../include/Ice/GCRecMutex.h ../../../include/IceUtil/RecMutex.h ../../../include/IceUtil/Config.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/GCShared.h ../../../include/Ice/GC.h ../../../include/IceUtil/Thread.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/Outgoing.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/AutoArray.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Direct.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/Locator.h ../../../include/Ice/ProcessF.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/IdentityUtil.h ../../../include/Ice/OutgoingAsync.h ../../../include/Ice/Process.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../include/TestCommon.h Test.h +AllTests.o: AllTests.cpp ../../../include/IceUtil/Thread.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/Ice.h ../../../include/Ice/GCRecMutex.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/Config.h ../../../include/Ice/GCShared.h ../../../include/Ice/GC.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/Outgoing.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/AutoArray.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Direct.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/Locator.h ../../../include/Ice/ProcessF.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/IdentityUtil.h ../../../include/Ice/OutgoingAsync.h ../../../include/Ice/Process.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/IceGrid/Observer.h ../../../include/Glacier2/Session.h ../../../include/IceGrid/Exception.h ../../../include/IceGrid/Descriptor.h ../../../include/IceGrid/Admin.h ../../../include/Ice/SliceChecksumDict.h ../../include/TestCommon.h Test.h +Test.cpp: Test.ice diff --git a/cpp/test/IceGrid/allocation/AllTests.cpp b/cpp/test/IceGrid/allocation/AllTests.cpp new file mode 100644 index 00000000000..dccd6334449 --- /dev/null +++ b/cpp/test/IceGrid/allocation/AllTests.cpp @@ -0,0 +1,304 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <IceUtil/Thread.h> +#include <Ice/Ice.h> +#include <IceGrid/Session.h> +#include <IceGrid/Admin.h> +#include <IceGrid/Query.h> +#include <TestCommon.h> +#include <Test.h> + +using namespace std; +using namespace Test; +using namespace IceGrid; + +class AllocateObjectCallback : public AMI_Session_allocateObject, public IceUtil::Monitor<IceUtil::Mutex> +{ +public: + + AllocateObjectCallback() : _response(false) + { + } + + void + ice_response() + { + Lock sync(*this); + _response = true; + notify(); + } + + void + ice_exception(const Ice::Exception&) + { + } + + void + wait() + { + Lock sync(*this); + while(!_response) + { + wait(); + } + } + + bool + response() + { + Lock sync(*this); + return _response; + } + +private: + + bool _response; +}; +typedef IceUtil::Handle<AllocateObjectCallback> AllocateObjectCallbackPtr; + +class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> +{ +public: + + SessionKeepAliveThread(const Ice::LoggerPtr& logger, const IceUtil::Time& timeout) : + _logger(logger), + _timeout(timeout), + _terminated(false) + { + } + + virtual void + run() + { + Lock sync(*this); + while(!_terminated) + { + timedWait(_timeout); + if(!_terminated) + { + vector<SessionPrx>::iterator p = _sessions.begin(); + while(p != _sessions.end()) + { + try + { + (*p)->keepAlive(); + ++p; + } + catch(const Ice::Exception&) + { + p = _sessions.erase(p); + } + } + } + } + } + + void + add(const SessionPrx& session) + { + Lock sync(*this); + _sessions.push_back(session); + } + + void + terminate() + { + Lock sync(*this); + _terminated = true; + notify(); + } + +private: + + const Ice::LoggerPtr _logger; + vector<SessionPrx> _sessions; + const IceUtil::Time _timeout; + bool _terminated; +}; +typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr; + +void +allTests(const Ice::CommunicatorPtr& communicator) +{ + AdminPrx admin = AdminPrx::checkedCast(communicator->stringToProxy("IceGrid/Admin")); + test(admin); + + SessionManagerPrx manager = SessionManagerPrx::checkedCast(communicator->stringToProxy("IceGrid/SessionManager")); + test(manager); + + SessionKeepAliveThreadPtr keepAlive; + keepAlive = new SessionKeepAliveThread(communicator->getLogger(), IceUtil::Time::seconds(5)); + keepAlive->start(); + + cout << "testing create session... " << flush; + SessionPrx session1 = SessionPrx::uncheckedCast(manager->createLocalSession("Client1")); + SessionPrx session2 = SessionPrx::uncheckedCast(manager->createLocalSession("Client2")); + + keepAlive->add(session1); + keepAlive->add(session2); + + cout << "ok" << endl; + + cout << "testing allocate object... " << flush; + try + { + session1->allocateObject(communicator->stringToProxy("nonallocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + try + { + session2->allocateObject(communicator->stringToProxy("nonallocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + try + { + session1->releaseObject(communicator->stringToProxy("nonallocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + try + { + session2->releaseObject(communicator->stringToProxy("nonallocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + + session1->allocateObject(communicator->stringToProxy("allocatable")); + try + { + session1->allocateObject(communicator->stringToProxy("allocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + session2->setAllocationTimeout(0); + try + { + session2->allocateObject(communicator->stringToProxy("allocatable")); + test(false); + } + catch(const AllocationTimeoutException& ex) + { + } + try + { + session2->releaseObject(communicator->stringToProxy("allocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + + session2->setAllocationTimeout(-1); + AllocateObjectCallbackPtr cb = new AllocateObjectCallback(); + session2->allocateObject_async(cb, communicator->stringToProxy("allocatable")); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); + test(!cb->response()); + session1->releaseObject(communicator->stringToProxy("allocatable")); + cb->wait(); + test(cb->response()); + + session1->setAllocationTimeout(0); + try + { + session1->allocateObject(communicator->stringToProxy("allocatable")); + test(false); + } + catch(const AllocationTimeoutException& ex) + { + } + try + { + session1->releaseObject(communicator->stringToProxy("allocatable")); + test(false); + } + catch(const AllocationException& ex) + { + } + + session1->setAllocationTimeout(-1); + cb = new AllocateObjectCallback(); + session1->allocateObject_async(cb, communicator->stringToProxy("allocatable")); + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500)); + test(!cb->response()); + session2->releaseObject(communicator->stringToProxy("allocatable")); + cb->wait(); + test(cb->response()); + + session1->releaseObject(communicator->stringToProxy("allocatable")); + // + // TODO: XXX test replicated proxy + // + + cout << "ok" << endl; + + cout << "testing allocation with query interface... " << flush; + + IceGrid::QueryPrx query1 = session1->getQuery(); + IceGrid::QueryPrx query2 = session2->getQuery(); + + session1->setAllocationTimeout(0); + session2->setAllocationTimeout(0); + + Ice::ObjectPrx obj; + + obj = query1->findObjectById(Ice::stringToIdentity("nonallocatable")); + test(obj); + obj = query2->findObjectById(Ice::stringToIdentity("nonallocatable")); + test(obj); + + obj = query1->findObjectById(Ice::stringToIdentity("allocatable")); // Allocate the object + test(obj); + obj = query2->findObjectById(Ice::stringToIdentity("allocatable")); + test(!obj); // Object already allocated + + obj = query1->findObjectById(Ice::stringToIdentity("allocatable")); // Get the allocated object one more time + test(obj); + try + { + session2->releaseObject(obj); + } + catch(const AllocationException&) + { + } + + session1->releaseObject(obj); + try + { + session1->releaseObject(obj); + } + catch(const AllocationException&) + { + } + + obj = query2->findObjectById(Ice::stringToIdentity("allocatable")); // Allocate the object + test(obj); + obj = query1->findObjectById(Ice::stringToIdentity("allocatable")); + test(!obj); // Object already allocated + obj = query2->findObjectById(Ice::stringToIdentity("allocatable")); + session2->releaseObject(obj); + + // + // TODO: XXX test other methods. + // + + cout << "ok" << endl; +} diff --git a/cpp/test/IceGrid/allocation/Client.cpp b/cpp/test/IceGrid/allocation/Client.cpp new file mode 100644 index 00000000000..83746f6a471 --- /dev/null +++ b/cpp/test/IceGrid/allocation/Client.cpp @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <TestCommon.h> +#include <Test.h> + +using namespace std; + +int +run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +{ + void allTests(const Ice::CommunicatorPtr&); + allTests(communicator); + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + try + { + communicator = Ice::initialize(argc, argv); + communicator->getProperties()->parseCommandLineOptions("", Ice::argsToStringSeq(argc, argv)); + status = run(argc, argv, communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/test/IceGrid/allocation/Makefile b/cpp/test/IceGrid/allocation/Makefile new file mode 100644 index 00000000000..a821b57fb1d --- /dev/null +++ b/cpp/test/IceGrid/allocation/Makefile @@ -0,0 +1,47 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2006 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +OBJS = Test.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + +SLICE_SRCS = Test.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) +LINKWITH := $(BZIP2_RPATH_LINK) -lIce -lIceUtil + +$(CLIENT): $(OBJS) $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) -lIceGrid -lGlacier2 $(LIBS) + +$(SERVER): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(SOBJS) $(LIBS) + +clean:: + rm -rf db/node db/registry db/node-1 db/node-2 + +include .depend diff --git a/cpp/test/IceGrid/allocation/Server.cpp b/cpp/test/IceGrid/allocation/Server.cpp new file mode 100644 index 00000000000..070ffdee6a2 --- /dev/null +++ b/cpp/test/IceGrid/allocation/Server.cpp @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <TestI.h> +#include <TestCommon.h> + +using namespace std; + +class Server : public Ice::Application +{ +public: + + virtual int run(int argc, char* argv[]); +}; + +int +Server::run(int argc, char* argv[]) +{ + Ice::PropertiesPtr properties = communicator()->getProperties(); + + Ice::StringSeq args = Ice::argsToStringSeq(argc, argv); + args = properties->parseCommandLineOptions("Test", args); + Ice::stringSeqToArgs(args, argc, argv); + + string name = properties->getProperty("Ice.ProgramName"); + + Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Server"); + Ice::ObjectPtr object = new TestI(adapter, properties); + adapter->add(object, Ice::stringToIdentity(name)); + + shutdownOnInterrupt(); + try + { + adapter->activate(); + } + catch(const Ice::ObjectAdapterDeactivatedException&) + { + } + communicator()->waitForShutdown(); + ignoreInterrupt(); + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + Server app; + int rc = app.main(argc, argv); + return rc; +} diff --git a/cpp/test/IceGrid/allocation/TestI.cpp b/cpp/test/IceGrid/allocation/TestI.cpp new file mode 100644 index 00000000000..48e7693f8d2 --- /dev/null +++ b/cpp/test/IceGrid/allocation/TestI.cpp @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <TestI.h> + +TestI::TestI(const Ice::ObjectAdapterPtr& adapter, const Ice::PropertiesPtr& properties) : + _adapter(adapter), + _properties(properties) +{ +} + +void +TestI::shutdown(const Ice::Current&) +{ + _adapter->getCommunicator()->shutdown(); +} + +std::string +TestI::getProperty(const std::string& name, const Ice::Current&) +{ + return _properties->getProperty(name); +} diff --git a/cpp/test/IceGrid/allocation/TestI.h b/cpp/test/IceGrid/allocation/TestI.h new file mode 100644 index 00000000000..494a250041d --- /dev/null +++ b/cpp/test/IceGrid/allocation/TestI.h @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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. +// +// ********************************************************************** + +#ifndef TEST_I_H +#define TEST_I_H + +#include <Test.h> + +class TestI : public ::Test::TestIntf +{ +public: + + TestI(const Ice::ObjectAdapterPtr&, const Ice::PropertiesPtr&); + + virtual void shutdown(const Ice::Current&); + virtual std::string getProperty(const std::string&, const Ice::Current&); + +private: + + Ice::ObjectAdapterPtr _adapter; + Ice::PropertiesPtr _properties; +}; + +#endif diff --git a/cpp/test/IceGrid/allocation/application.xml b/cpp/test/IceGrid/allocation/application.xml new file mode 100644 index 00000000000..31766f5a487 --- /dev/null +++ b/cpp/test/IceGrid/allocation/application.xml @@ -0,0 +1,18 @@ +<icegrid> + + <application name="test" import-default-templates="true"> + + <node name="localnode"> + + <server id="SimpleServer" exe="${test.dir}/server" activation="on-demand" pwd="."> + <adapter name="Server" endpoints="default"> + <object identity="nonallocatable" type="::Test" allocatable="false"/> + <object identity="allocatable" type="::Test" allocatable="true"/> + </adapter> + </server> + + </node> + + </application> + +</icegrid> diff --git a/cpp/test/IceGrid/allocation/db/.dummy b/cpp/test/IceGrid/allocation/db/.dummy new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/test/IceGrid/allocation/db/.dummy diff --git a/cpp/test/IceGrid/allocation/icegridallocationC.dsp b/cpp/test/IceGrid/allocation/icegridallocationC.dsp new file mode 100644 index 00000000000..407e055d4c2 --- /dev/null +++ b/cpp/test/IceGrid/allocation/icegridallocationC.dsp @@ -0,0 +1,157 @@ +# Microsoft Developer Studio Project File - Name="icegridallocationC" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=icegridallocationC - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "icegridallocationC.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "icegridallocationC.mak" CFG="icegridallocationC - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "icegridallocationC - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "icegridallocationC - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "icegridallocationC - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../../include" /I "../../include" /D "_CONSOLE" /D "NDEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /c
+# SUBTRACT CPP /Z<none> /Fr /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"client.exe" /libpath:"../../../lib" /FIXED:no
+# SUBTRACT LINK32 /debug /nodefaultlib
+
+!ELSEIF "$(CFG)" == "icegridallocationC - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../../include" /I "../../include" /D "_CONSOLE" /D "_DEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /GZ /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /out:"client.exe" /pdbtype:sept /libpath:"../../../lib" /FIXED:no
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "icegridallocationC - Win32 Release"
+# Name "icegridallocationC - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\AllTests.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Client.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Test.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Test.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\Test.ice
+
+!IF "$(CFG)" == "icegridallocationC - Win32 Release"
+
+USERDEP__TEST_="..\..\..\bin\slice2cpp.exe" "..\..\..\lib\slice.lib"
+# Begin Custom Build
+InputPath=.\Test.ice
+
+BuildCmds= \
+ ..\..\..\bin\slice2cpp.exe Test.ice
+
+"Test.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Test.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "icegridallocationC - Win32 Debug"
+
+USERDEP__TEST_="..\..\..\bin\slice2cpp.exe" "..\..\..\lib\sliced.lib"
+# Begin Custom Build
+InputPath=.\Test.ice
+
+BuildCmds= \
+ ..\..\..\bin\slice2cpp.exe Test.ice
+
+"Test.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Test.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/cpp/test/IceGrid/allocation/icegridallocationS.dsp b/cpp/test/IceGrid/allocation/icegridallocationS.dsp new file mode 100644 index 00000000000..322c6f0c872 --- /dev/null +++ b/cpp/test/IceGrid/allocation/icegridallocationS.dsp @@ -0,0 +1,161 @@ +# Microsoft Developer Studio Project File - Name="icegridallocationS" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=icegridallocationS - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "icegridallocationS.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "icegridallocationS.mak" CFG="icegridallocationS - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "icegridallocationS - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "icegridallocationS - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "icegridallocationS - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../../include" /I "../../include" /D "_CONSOLE" /D "NDEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /c
+# SUBTRACT CPP /Z<none> /Fr /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"server.exe" /libpath:"../../../lib" /FIXED:no
+# SUBTRACT LINK32 /debug /nodefaultlib
+
+!ELSEIF "$(CFG)" == "icegridallocationS - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../../include" /I "../../include" /D "_CONSOLE" /D "_DEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /GZ /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /out:"server.exe" /pdbtype:sept /libpath:"../../../lib" /FIXED:no
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "icegridallocationS - Win32 Release"
+# Name "icegridallocationS - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Server.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Test.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestI.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Test.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestI.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\Test.ice
+
+!IF "$(CFG)" == "icegridallocationS - Win32 Release"
+
+USERDEP__TEST_="..\..\..\bin\slice2cpp.exe" "..\..\..\lib\slice.lib"
+# Begin Custom Build
+InputPath=.\Test.ice
+
+BuildCmds= \
+ ..\..\..\bin\slice2cpp.exe Test.ice
+
+"Test.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Test.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "icegridallocationS - Win32 Debug"
+
+USERDEP__TEST_="..\..\..\bin\slice2cpp.exe" "..\..\..\lib\sliced.lib"
+# Begin Custom Build
+InputPath=.\Test.ice
+
+BuildCmds= \
+ ..\..\..\bin\slice2cpp.exe Test.ice
+
+"Test.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Test.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/cpp/test/IceGrid/allocation/run.py b/cpp/test/IceGrid/allocation/run.py new file mode 100755 index 00000000000..62306eb7763 --- /dev/null +++ b/cpp/test/IceGrid/allocation/run.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2006 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil +import IceGridAdmin + +name = os.path.join("IceGrid", "allocation") +testdir = os.path.join(toplevel, "test", name) +client = os.path.join(testdir, "client") + +# +# Add locator options for the client and server. Since the server +# invokes on the locator it's also considered to be a client. +# +additionalOptions = " --Ice.Default.Locator=\"IceGrid/Locator:default -p 12010\" " + \ + "--Ice.PrintAdapterReady=0 --Ice.PrintProcessId=0 --IceDir=\"" + toplevel + "\" --TestDir=\"" + testdir + "\"" + +IceGridAdmin.cleanDbDir(os.path.join(testdir, "db")) +iceGridRegistryThread = IceGridAdmin.startIceGridRegistry("12010", testdir, 0) +iceGridNodeThread = IceGridAdmin.startIceGridNode(testdir) + +# +# Deploy the application, run the client and remove the application. +# +print "deploying application...", +IceGridAdmin.addApplication(os.path.join(testdir, "application.xml"), "ice.dir=" + toplevel + " test.dir=" + testdir) +print "ok" + +print "starting client...", +clientPipe = os.popen(client + TestUtil.clientServerOptions + additionalOptions + " 2>&1") +print "ok" + +try: + TestUtil.printOutputFromPipe(clientPipe) +except: + pass + +clientStatus = TestUtil.closePipe(clientPipe) + +print "removing application...", +IceGridAdmin.removeApplication("test") +print "ok" + +IceGridAdmin.shutdownIceGridNode() +iceGridNodeThread.join() +IceGridAdmin.shutdownIceGridRegistry() +iceGridRegistryThread.join() + +if clientStatus: + sys.exit(1) +else: + sys.exit(0) diff --git a/cpp/test/IceGrid/session/AllTests.cpp b/cpp/test/IceGrid/session/AllTests.cpp index 617808ef0ee..39e19d687a6 100644 --- a/cpp/test/IceGrid/session/AllTests.cpp +++ b/cpp/test/IceGrid/session/AllTests.cpp @@ -357,7 +357,8 @@ private: void allTests(const Ice::CommunicatorPtr& communicator) { - SessionManagerPrx manager = SessionManagerPrx::checkedCast(communicator->stringToProxy("IceGrid/SessionManager")); + SessionManagerPrx manager = + SessionManagerPrx::checkedCast(communicator->stringToProxy("IceGrid/AdminSessionManager")); test(manager); AdminPrx admin = AdminPrx::checkedCast(communicator->stringToProxy("IceGrid/Admin")); |