summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/ObjectCache.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/ObjectCache.h')
-rw-r--r--cpp/src/IceGrid/ObjectCache.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/ObjectCache.h b/cpp/src/IceGrid/ObjectCache.h
new file mode 100644
index 00000000000..a8ef9df8f2b
--- /dev/null
+++ b/cpp/src/IceGrid/ObjectCache.h
@@ -0,0 +1,85 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 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_OBJECTCACHE_H
+#define ICE_GRID_OBJECTCACHE_H
+
+#include <IceUtil/Mutex.h>
+#include <Ice/CommunicatorF.h>
+#include <IceGrid/Cache.h>
+#include <IceGrid/Internal.h>
+
+namespace IceGrid
+{
+
+class ObjectCache;
+
+class ObjectEntry : public IceUtil::Shared
+{
+public:
+
+ ObjectEntry(ObjectCache&, const ObjectInfo&, const std::string&);
+ Ice::ObjectPrx getProxy() const;
+ std::string getType() const;
+ std::string getApplication() const;
+ const ObjectInfo& getObjectInfo() const;
+
+ bool canRemove();
+
+private:
+
+ ObjectCache& _cache;
+ const ObjectInfo _info;
+ const std::string _application;
+};
+typedef IceUtil::Handle<ObjectEntry> ObjectEntryPtr;
+
+class ObjectCache : public Cache<Ice::Identity, ObjectEntry>
+{
+public:
+
+ ObjectCache(const Ice::CommunicatorPtr&);
+
+ void add(const ObjectInfo&, const std::string&);
+ ObjectEntryPtr get(const Ice::Identity&) const;
+ void remove(const Ice::Identity&);
+
+ Ice::ObjectProxySeq getObjectsByType(const std::string&);
+ ObjectInfoSeq getAll(const std::string&);
+ ObjectInfoSeq getAllByType(const std::string&);
+
+ const Ice::CommunicatorPtr& getCommunicator() const { return _communicator; }
+
+private:
+
+ class TypeEntry
+ {
+ public:
+
+ TypeEntry();
+
+ void add(const ObjectEntryPtr&);
+ bool remove(const ObjectEntryPtr&);
+
+ const std::vector<ObjectEntryPtr>& getObjects() const { return _objects; }
+
+ private:
+
+ std::vector<ObjectEntryPtr> _objects;
+ };
+
+ const Ice::CommunicatorPtr _communicator;
+ std::map<std::string, TypeEntry> _types;
+
+ static std::pointer_to_unary_function<int, unsigned int> _rand;
+};
+
+};
+
+#endif