diff Framework/Plugins/StorageBackend.h @ 269:567761f0c1ea

fix issue #151: support of retries in the storage area plugins to deal with multiple writers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Apr 2021 17:54:31 +0200
parents d663d9e44f8d
children 16aac0287485
line wrap: on
line diff
--- a/Framework/Plugins/StorageBackend.h	Wed Apr 21 11:14:40 2021 +0200
+++ b/Framework/Plugins/StorageBackend.h	Wed Apr 21 17:54:31 2021 +0200
@@ -71,11 +71,30 @@
                           OrthancPluginContentType type) = 0;
     };
     
+    /**
+     * This class is similar to
+     * "Orthanc::StatelessDatabaseOperations": It handles retries of
+     * transactions in the case of collision between multiple
+     * readers/writers.
+     **/
+    class IDatabaseOperation : public boost::noncopyable
+    {
+    public:
+      virtual ~IDatabaseOperation()
+      {
+      }
+
+      virtual void Execute(IAccessor& accessor) = 0;
+    };
+
+    class ReadWholeOperation;
+
   private:
     class StringVisitor;
     
     boost::mutex      mutex_;
     DatabaseManager   manager_;
+    unsigned int      maxRetries_;
 
   protected:
     class AccessorBase : public IAccessor
@@ -118,7 +137,8 @@
     virtual bool HasReadRange() const = 0;
 
   public:
-    StorageBackend(IDatabaseFactory* factory);  // Takes ownership
+    StorageBackend(IDatabaseFactory* factory /* takes ownership */,
+                   unsigned int maxRetries);
 
     virtual ~StorageBackend()
     {
@@ -147,5 +167,12 @@
                                   OrthancPluginContentType type,
                                   uint64_t start,
                                   size_t length);
+
+    unsigned int GetMaxRetries() const
+    {
+      return maxRetries_;
+    }
+
+    void Execute(IDatabaseOperation& operation);
   };
 }