include/dmlite/cpp/pooldriver.h

Go to the documentation of this file.
00001 /// @file   include/dmlite/cpp/pooldriver.h
00002 /// @brief  Pool handling API.
00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
00004 #ifndef DMLITE_CPP_POOLDRIVER_H
00005 #define DMLITE_CPP_POOLDRIVER_H
00006 
00007 #include "dmlite/common/config.h"
00008 #include "base.h"
00009 #include "exceptions.h"
00010 #include "inode.h"
00011 #include "utils/urls.h"
00012 
00013 #include <map>
00014 #include <vector>
00015 
00016 namespace dmlite {
00017   
00018   // Forward declarations.
00019   class Pool;
00020   class StackInstance;
00021   
00022   /// Represents a chunk of a file.
00023   struct Chunk {
00024     Chunk();
00025     Chunk(const std::string& url, uint64_t offset, uint64_t size);
00026     /// Chunk from a serialized string
00027     explicit Chunk(const std::string& str);
00028 
00029     uint64_t offset;
00030     uint64_t size;
00031     Url      url;
00032 
00033     bool operator == (const Chunk&) const;
00034     bool operator != (const Chunk&) const;
00035     bool operator <  (const Chunk&) const;
00036     bool operator >  (const Chunk&) const;
00037 
00038     std::string toString(void) const;
00039   };
00040   
00041   /// Represent the complete location of a file.
00042   struct Location: public std::vector<Chunk> {
00043     Location() {}
00044     Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {}
00045 
00046     Location(const Location& l): std::vector<Chunk>(l) {}
00047 
00048     // Location from serialized string
00049     explicit Location(const std::string& str);
00050 
00051     std::string toString(void) const;
00052   };
00053 
00054   /// Handler for a pool. Works similary to a file handler.
00055   class PoolHandler {
00056    public:
00057     /// Destructor
00058     virtual ~PoolHandler();
00059 
00060     /// Get the pool type of this pool.
00061     virtual std::string getPoolType(void) throw (DmException);
00062 
00063     /// Get the pool name of this pool.
00064     virtual std::string getPoolName(void) throw (DmException);
00065 
00066     /// Get the total space of this pool.
00067     virtual uint64_t getTotalSpace(void) throw (DmException);
00068 
00069     /// Get the free space of this pool.
00070     virtual uint64_t getFreeSpace(void) throw (DmException);
00071 
00072     /// Check if the pool is actually available.
00073     virtual bool poolIsAvailable(bool write = true) throw (DmException);
00074     
00075     /// Check if a replica is available.
00076     virtual bool replicaIsAvailable(const Replica& replica) throw (DmException);
00077 
00078     /// Get the actual location of the file replica. This is pool-specific.
00079     virtual Location whereToRead(const Replica& replica) throw (DmException);
00080 
00081     /// Remove a replica from the pool.
00082     virtual void removeReplica(const Replica& replica) throw (DmException);
00083 
00084     /// Get where to put a file.
00085     virtual Location whereToWrite(const std::string& path) throw (DmException);
00086 
00087     /// Cancel a write.
00088     virtual void cancelWrite(const Location& loc) throw (DmException);
00089   };
00090 
00091   /// Interface for a pool driver
00092   class PoolDriver: public virtual BaseInterface {
00093    public:
00094     /// Destructor
00095     virtual ~PoolDriver();
00096 
00097     /// Create a handler.
00098     virtual PoolHandler* createPoolHandler(const std::string& poolName) throw (DmException);
00099     
00100     /// Called just before adding the pool to the database.
00101     /// To be used by a plugin, in case it needs to do some previous preparations.
00102     /// (i.e. legacy filesystem will actually create the pool here)
00103     virtual void toBeCreated(const Pool& pool) throw (DmException);
00104     
00105     /// Called just after a pool is added to the database.
00106     virtual void justCreated(const Pool& pool) throw (DmException);
00107     
00108     /// Called when updating a pool.
00109     virtual void update(const Pool& pool) throw (DmException);
00110     
00111     /// Called just before a pool of this type is removed.
00112     /// @note The driver may remove the pool itself (i.e. filesystem)
00113     virtual void toBeDeleted(const Pool& pool) throw (DmException);
00114   };
00115 
00116   /// PoolDriver factory
00117   class PoolDriverFactory: public virtual BaseFactory {
00118    public:
00119     /// Destructor.
00120     virtual ~PoolDriverFactory();
00121 
00122     /// Supported pool type
00123     virtual std::string implementedPool() throw ();
00124 
00125    protected:
00126     friend class StackInstance;
00127 
00128     /// Instantiate the implemented pool driver.
00129     virtual PoolDriver* createPoolDriver(void) throw (DmException);
00130   };
00131 
00132 };
00133 
00134 #endif  // DMLITE_CPP_POOLDRIVER_H

Generated on 4 May 2016 for dmlite by  doxygen 1.4.7