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