bes  Updated for version 3.20.6
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> // needed for libdap::DAPVersion
31 //#include <DMR.h>
32 
33 #include "BESFileLockingCache.h"
34 
35 #undef DAP2_STORED_RESULTS
36 
37 namespace libdap {
38 class DDS;
39 class ConstraintEvaluator;
40 class BaseTypeFactory;
41 
42 class DMR;
43 }
44 
46 
53 private:
54  static bool d_enabled;
55  static BESStoredDapResultCache *d_instance;
56  static void delete_instance()
57  {
58  delete d_instance;
59  d_instance = 0;
60  }
61 
62  string d_storedResultsSubdir;
63  string d_dataRootDir;
64  string d_resultFilePrefix;
65  unsigned long d_maxCacheSize;
66 
69 
71 
72  bool is_valid(const std::string &cache_file_name, const std::string &dataset);
73 #ifdef DAP2_STORED_RESULTS
74  bool read_dap2_data_from_cache(const string &cache_file_name, libdap::DDS *fdds);
75 #endif
76  bool read_dap4_data_from_cache(const string &cache_file_name, libdap::DMR *dmr);
77 
78  friend class StoredDap2ResultTest;
79  friend class StoredDap4ResultTest;
80  friend class ResponseBuilderTest;
81 
82  string get_stored_result_local_id(const string &dataset, const string &ce, libdap::DAPVersion version);
83 
84  string getBesDataRootDirFromConfig();
85  string getSubDirFromConfig();
86  string getResultPrefixFromConfig();
87  unsigned long getCacheSizeFromConfig();
88 
89 protected:
90 
91  BESStoredDapResultCache(const string &data_root_dir, const string &stored_results_subdir, const string &prefix,
92  unsigned long long size);
93 
94 public:
95  static const string SUBDIR_KEY;
96  static const string PREFIX_KEY;
97  static const string SIZE_KEY;
98 
99  virtual ~BESStoredDapResultCache() { }
100 
101  static BESStoredDapResultCache *get_instance(const string &bes_catalog_root_dir,
102  const string &stored_results_subdir, const string &prefix, unsigned long long size);
104 
105 #ifdef DAP2_STORED_RESULTS
106  libdap::DDS *get_cached_dap2_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
107  // Store the passed DDS to disk as a serialized DAP2 object.
108  virtual string store_dap2_result(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
109  libdap::ConstraintEvaluator *eval);
110 #endif
111 
112  libdap::DMR *get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory,
113  const string &filename);
114 
115  // Store the passed DMR to disk as a serialized DAP4 object.
116  virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb);
117 };
118 
119 #endif // _bes_store_result_cache_h
BaseTypeFactory
BESStoredDapResultCache::store_dap4_result
virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb)
Definition: BESStoredDapResultCache.cc:739
BESStoredDapResultCache::get_cached_dap4_data
libdap::DMR * get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory, const string &filename)
Definition: BESStoredDapResultCache.cc:538
libdap
Definition: BESDapFunctionResponseCache.h:35
BESStoredDapResultCache::get_instance
static BESStoredDapResultCache * get_instance()
Definition: BESStoredDapResultCache.cc:240
BESFileLockingCache
Implementation of a caching mechanism for compressed data.
Definition: BESFileLockingCache.h:85
BESStoredDapResultCache
Definition: BESStoredDapResultCache.h:52
BESDapResponseBuilder
Definition: BESDapResponseBuilder.h:53