summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/ObjectStore.h
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2004-04-09 23:21:15 +0000
committerBernard Normier <bernard@zeroc.com>2004-04-09 23:21:15 +0000
commit0dcad3e212de5e8560e57c1a3d2f04909ebe7513 (patch)
tree412366d59303c0c4a90d281e50f78c39775db31d /cpp/src/Freeze/ObjectStore.h
parentEach request now has its own set of object factories. (diff)
downloadice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.tar.bz2
ice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.tar.xz
ice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.zip
Updated Freeze Evictor with new facets
Diffstat (limited to 'cpp/src/Freeze/ObjectStore.h')
-rw-r--r--cpp/src/Freeze/ObjectStore.h187
1 files changed, 187 insertions, 0 deletions
diff --git a/cpp/src/Freeze/ObjectStore.h b/cpp/src/Freeze/ObjectStore.h
new file mode 100644
index 00000000000..cd16c2e8f37
--- /dev/null
+++ b/cpp/src/Freeze/ObjectStore.h
@@ -0,0 +1,187 @@
+// **********************************************************************
+//
+// Copyright (c) 2004
+// 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.
+//
+// **********************************************************************
+
+#ifndef FREEZE_OBJECT_STORE_H
+#define FREEZE_OBJECT_STORE_H
+
+#include <Ice/Ice.h>
+#include <Ice/Identity.h>
+#include <Freeze/DB.h>
+#include <Freeze/EvictorStorage.h>
+#include <Freeze/Index.h>
+#include <IceUtil/Cache.h>
+
+#include <vector>
+#include <list>
+#include <db_cxx.h>
+
+namespace Freeze
+{
+
+class EvictorI;
+
+struct EvictorElement;
+typedef IceUtil::Handle<EvictorElement> EvictorElementPtr;
+
+typedef IceUtil::Cache<Ice::Identity, EvictorElement> Cache;
+
+class ObjectStore : public Cache
+{
+public:
+
+ ObjectStore(const std::string&, const std::string&, bool, EvictorI*,
+ const std::vector<IndexPtr>& = std::vector<IndexPtr>(), bool = false);
+
+ virtual ~ObjectStore();
+
+ void close();
+
+ bool dbHasObject(const Ice::Identity&) const;
+ void save(Key& key, Value& value, Ice::Byte status, DbTxn* tx);
+
+ static void marshal(const Ice::Identity&, Key&, const Ice::CommunicatorPtr&);
+ static void unmarshal(Ice::Identity&, const Key&, const Ice::CommunicatorPtr&);
+ static void marshal(const ObjectRecord&, Value&, const Ice::CommunicatorPtr&);
+ static void unmarshal(ObjectRecord&, const Value&, const Ice::CommunicatorPtr&);
+
+ //
+ // For IndexI and Iterator
+ //
+ Db* db() const;
+ const Ice::CommunicatorPtr& communicator() const;
+ EvictorI* evictor() const;
+ const std::string& filename() const;
+ const std::string& facet() const;
+
+protected:
+
+ virtual EvictorElementPtr load(const Ice::Identity&);
+ virtual void pinned(const EvictorElementPtr&, Position p);
+
+private:
+
+ std::auto_ptr<Db> _db;
+ std::string _facet;
+ std::string _filename;
+ EvictorI* _evictor;
+ std::vector<IndexPtr> _indices;
+ Ice::CommunicatorPtr _communicator;
+};
+
+
+struct EvictorElement : public Ice::LocalObject
+{
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1200)
+
+ enum
+ {
+ clean = 0,
+ created = 1,
+ modified = 2,
+ destroyed = 3,
+ dead = 4
+ };
+
+#else
+ //
+ // Clean object; can become modified or destroyed
+ //
+ static const Ice::Byte clean = 0;
+
+ //
+ // New objects; can become clean, dead or destroyed
+ //
+ static const Ice::Byte created = 1;
+
+ //
+ // Modified object; can become clean or destroyed
+ //
+ static const Ice::Byte modified = 2;
+
+ //
+ // Being saved. Can become dead or created
+ //
+ static const Ice::Byte destroyed = 3;
+
+ //
+ // Exists only in the Evictor; for example the object was created
+ // and later destroyed (without a save in between), or it was
+ // destroyed on disk but is still in use. Can become created.
+ //
+ static const Ice::Byte dead = 4;
+
+#endif
+
+ EvictorElement(ObjectStore&);
+ ~EvictorElement();
+
+ //
+ // Immutable
+ //
+ ObjectStore& store;
+
+ //
+ // Immutable once set by position()
+ //
+ Cache::Position cachePosition;
+
+ //
+ // Protected by EvictorI
+ //
+ std::list<EvictorElementPtr>::iterator evictPosition;
+ int usageCount;
+ bool stale;
+
+ //
+ // Protected by mutex
+ //
+ IceUtil::Mutex mutex;
+ ObjectRecord rec;
+ Ice::Byte status;
+};
+
+
+//
+// Inline member function definitions
+//
+
+inline Db*
+ObjectStore::db() const
+{
+ return _db.get();
+}
+
+inline const Ice::CommunicatorPtr&
+ObjectStore::communicator() const
+{
+ return _communicator;
+}
+
+inline EvictorI*
+ObjectStore::evictor() const
+{
+ return _evictor;
+}
+
+inline const std::string&
+ObjectStore::facet() const
+{
+ return _facet;
+}
+
+}
+
+#endif
+