OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESStoredDapResultCache.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2013 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef _bes_store_result_cache_h
27 #define _bes_store_result_cache_h
28 
29 #include <string>
30 
31 #include <DapXmlNamespaces.h>
32 #include <DMR.h>
33 #include "BESFileLockingCache.h"
34 
36 
37 // using the namespace in the forward declaration works with older g++ versions
38 // because they are sensible and not literal. It should not work; the decl class
39 // libdap::BaseType; tells the compiler go look i the 'libdap' namespace for 'BaseType'
40 // but _while it's compiling this file_ there is no 'libdap' namespace. So we make one.
41 namespace libdap {
42  class DDS;
43  class ConstraintEvaluator;
44  class BaseTypeFactory;
45 }
46 
53 {
54 private:
55 
56  static BESStoredDapResultCache * d_instance;
57  static void delete_instance();
58 
59  string d_storedResultsSubdir;
60  string d_dataRootDir;
61  string d_resultFilePrefix;
62  unsigned long d_maxCacheSize;
63 
67 
68  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
69  bool read_dap2_data_from_cache(const string &cache_file_name/*FILE *data*/, libdap::DDS *fdds);
70  bool read_dap4_data_from_cache(const string &cache_file_name, libdap::DMR *dmr);
71 
72  friend class StoredDap2ResultTest;
73  friend class StoredDap4ResultTest;
74  friend class ResponseBuilderTest;
75 
76  string get_stored_result_local_id(const string &dataset, const string &ce, libdap::DAPVersion version);
77 
78  string getBesDataRootDirFromConfig();
79  string getSubDirFromConfig();
80  string getResultPrefixFromConfig();
81  unsigned long getCacheSizeFromConfig();
82 
83 protected:
84 
85  BESStoredDapResultCache(const string &data_root_dir, const string &stored_results_subdir, const string &prefix, unsigned long long size);
86 
87 public:
88  static const string SUBDIR_KEY;
89  static const string PREFIX_KEY;
90  static const string SIZE_KEY;
91 
92  static BESStoredDapResultCache *get_instance(const string &bes_catalog_root_dir, const string &stored_results_subdir, const string &prefix, unsigned long long size);
94  static string assemblePath(const string &firstPart, const string &secondPart, bool addLeadingSlash = false);
95 
96  libdap::DDS *get_cached_dap2_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
97  libdap::DMR *get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory, const string &filename);
98 
100 
101  // Store the passed DDS to disk as a serialized DAP2 object.
102  virtual string store_dap2_result(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
103  libdap::ConstraintEvaluator *eval);
104 
105  // Store the passed DMR to disk as a serialized DAP4 object.
106  virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb);
107 
108  // virtual void unlock_and_close(const std::string &cache_token);
109 
110  // Overrides parent
111  virtual string get_cache_file_name(const string &src, bool mangle = false);
112 
113 };
114 
115 #endif // _bes_store_result_cache_h
static string assemblePath(const string &firstPart, const string &secondPart, bool addLeadingSlash=false)
virtual string get_cache_file_name(const string &src, bool mangle=false)
Build the name of file that will holds the uncompressed data from 'src' in the cache.
virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb)
libdap::DMR * get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory, const string &filename)
Read data from cache.
Implementation of a caching mechanism for compressed data.
static class NCMLUtil overview
static BESStoredDapResultCache * get_instance()
Get the default instance of the BESStoredDapResultCache object.
libdap::DDS * get_cached_dap2_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset)
Read data from cache.
static const string SUBDIR_KEY
static const string PREFIX_KEY
This class is used to build responses for/by the BES.
This class is used to cache DAP2 response objects.
virtual string store_dap2_result(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb, libdap::ConstraintEvaluator *eval)