bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 <libdap/DapXmlNamespaces.h> // needed for libdap::DAPVersion
31//#include <libdap/DMR.h>
32
33#include "BESFileLockingCache.h"
34
35#define DAP_STORED_RESULTS_CACHE_SUBDIR_KEY "DAP.StoredResultsCache.subdir"
36#define DAP_STORED_RESULTS_CACHE_PREFIX_KEY "DAP.StoredResultsCache.prefix"
37#define DAP_STORED_RESULTS_CACHE_SIZE_KEY "DAP.StoredResultsCache.size"
38
39#undef DAP2_STORED_RESULTS
40
41namespace libdap {
42class DDS;
43class ConstraintEvaluator;
44class BaseTypeFactory;
45
46class DMR;
47}
48
50
55
56class BESStoredDapResultCache: public BESFileLockingCache {
57private:
58 static bool d_enabled;
59 static BESStoredDapResultCache *d_instance;
60 static void delete_instance()
61 {
62 delete d_instance;
63 d_instance = 0;
64 }
65
66 string d_storedResultsSubdir;
67 string d_dataRootDir;
68 string d_resultFilePrefix;
69 unsigned long d_maxCacheSize;
70
72 BESStoredDapResultCache();
73
74 BESStoredDapResultCache(const BESStoredDapResultCache &src);
75
76 bool is_valid(const std::string &cache_file_name, const std::string &dataset);
77#ifdef DAP2_STORED_RESULTS
78 bool read_dap2_data_from_cache(const string &cache_file_name, libdap::DDS *fdds);
79#endif
80 bool read_dap4_data_from_cache(const string &cache_file_name, libdap::DMR *dmr);
81
82 friend class StoredDap2ResultTest;
83 friend class StoredDap4ResultTest;
84 friend class ResponseBuilderTest;
85
86 string get_stored_result_local_id(const string &dataset, const string &ce, libdap::DAPVersion version);
87
88 string getBesDataRootDirFromConfig();
89 string getSubDirFromConfig();
90 string getResultPrefixFromConfig();
91 unsigned long getCacheSizeFromConfig();
92
93protected:
94
95 BESStoredDapResultCache(const string &data_root_dir, const string &stored_results_subdir, const string &prefix,
96 unsigned long long size);
97
98public:
99#if 0
100 static const string SUBDIR_KEY;
101 static const string PREFIX_KEY;
102 static const string SIZE_KEY;
103#endif
104
105 virtual ~BESStoredDapResultCache() { }
106
107 static BESStoredDapResultCache *get_instance(const string &bes_catalog_root_dir,
108 const string &stored_results_subdir, const string &prefix, unsigned long long size);
109 static BESStoredDapResultCache *get_instance();
110
111#ifdef DAP2_STORED_RESULTS
112 libdap::DDS *get_cached_dap2_data_ddx(const std::string &cache_file_name, libdap::BaseTypeFactory *factory, const std::string &dataset);
113 // Store the passed DDS to disk as a serialized DAP2 object.
114 virtual string store_dap2_result(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb,
115 libdap::ConstraintEvaluator *eval);
116#endif
117
118 libdap::DMR *get_cached_dap4_data(const string &cache_file_name, libdap::D4BaseTypeFactory *factory,
119 const string &filename);
120
121 // Store the passed DMR to disk as a serialized DAP4 object.
122 virtual string store_dap4_result(libdap::DMR &dmr, const string &constraint, BESDapResponseBuilder *rb);
123};
124
125#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)
static BESStoredDapResultCache * get_instance()