OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESContainerStorageList.cc
Go to the documentation of this file.
1 // BESContainerStorageList.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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 University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <iostream>
34 
35 using std::endl;
36 
38 #include "BESContainerStorage.h"
39 #include "BESSyntaxUserError.h"
40 #include "BESContainer.h"
41 #include "TheBESKeys.h"
42 #include "BESLog.h"
43 #include "BESInfo.h"
44 
45 BESContainerStorageList *BESContainerStorageList::_instance = 0;
46 
48  _first(0)
49 {
50 }
51 
53 {
54  BESContainerStorageList::persistence_list *pl = _first;
55  while (pl) {
56  if (pl->_persistence_obj) {
57  delete pl->_persistence_obj;
58  }
59  BESContainerStorageList::persistence_list *next = pl->_next;
60  delete pl;
61  pl = next;
62  }
63 }
64 
78 {
79  bool ret = false;
80  if (!_first) {
81  _first = new BESContainerStorageList::persistence_list;
82  _first->_persistence_obj = cp;
83  _first->_reference = 1;
84  _first->_next = 0;
85  ret = true;
86  }
87  else {
88  BESContainerStorageList::persistence_list *pl = _first;
89  bool done = false;
90  while (done == false) {
91  if (pl->_persistence_obj->get_name() != cp->get_name()) {
92  if (pl->_next) {
93  pl = pl->_next;
94  }
95  else {
96  pl->_next = new BESContainerStorageList::persistence_list;
97  pl->_next->_reference = 1;
98  pl->_next->_persistence_obj = cp;
99  pl->_next->_next = 0;
100  done = true;
101  ret = true;
102  }
103  }
104  else {
105  done = true;
106  ret = false;
107  }
108  }
109  }
110  return ret;
111 }
112 
123 bool BESContainerStorageList::ref_persistence(const string &persist_name)
124 {
125  bool ret = false;
126  BESContainerStorageList::persistence_list *pl = _first;
127 
128  bool done = false;
129  while (done == false) {
130  if (pl) {
131  if (pl->_persistence_obj && pl->_persistence_obj->get_name() == persist_name) {
132  done = true;
133  ret = true;
134  pl->_reference++;
135  }
136  else {
137  pl = pl->_next;
138  }
139  }
140  else {
141  done = true;
142  }
143  }
144  return ret;
145 }
146 
159 bool BESContainerStorageList::deref_persistence(const string &persist_name)
160 {
161  bool ret = false;
162  BESContainerStorageList::persistence_list *pl = _first;
163  BESContainerStorageList::persistence_list *last = 0;
164 
165  bool done = false;
166  while (done == false) {
167  if (pl) {
168  if (pl->_persistence_obj && pl->_persistence_obj->get_name() == persist_name) {
169  ret = true;
170  done = true;
171  pl->_reference--;
172  if (!pl->_reference) {
173  if (pl == _first) {
174  _first = _first->_next;
175  }
176  else {
177  if (!last)
178  throw BESInternalError("ContainerStorageList last is null", __FILE__, __LINE__);
179  last->_next = pl->_next;
180  }
181  delete pl->_persistence_obj;
182  delete pl;
183  pl = 0;
184  }
185  }
186  else {
187  last = pl;
188  pl = pl->_next;
189  }
190  }
191  else {
192  done = true;
193  }
194  }
195 
196  return ret;
197 }
198 
208 BESContainerStorageList::find_persistence(const string &persist_name)
209 {
210  BESContainerStorage *ret = NULL;
211  BESContainerStorageList::persistence_list *pl = _first;
212  bool done = false;
213  while (done == false) {
214  if (pl) {
215  if (persist_name == pl->_persistence_obj->get_name()) {
216  ret = pl->_persistence_obj;
217  done = true;
218  }
219  else {
220  pl = pl->_next;
221  }
222  }
223  else {
224  done = true;
225  }
226  }
227  return ret;
228 }
229 
231 {
232  bool ret = false;
233  string key = "BES.Container.Persistence";
234  bool found = false;
235  string isnice;
236  TheBESKeys::TheKeys()->get_value(key, isnice, found);
237  if (isnice == "Nice" || isnice == "nice" || isnice == "NICE")
238  ret = true;
239  else
240  ret = false;
241  return ret;
242 }
243 
267 BESContainer *
268 BESContainerStorageList::look_for(const string &sym_name)
269 {
270  BESContainer *ret_container = 0;
271  BESContainerStorageList::persistence_list *pl = _first;
272  bool done = false;
273  while (done == false) {
274  if (pl) {
275  ret_container = pl->_persistence_obj->look_for(sym_name);
276  if (ret_container) {
277  done = true;
278  }
279  else {
280  pl = pl->_next;
281  }
282  }
283  else {
284  done = true;
285  }
286  }
287  if (!ret_container) {
288  if (isnice()) {
289  (*BESLog::TheLog()) << "Could not find the symbolic name " << sym_name << endl;
290  }
291  else {
292  string s = (string) "Could not find the symbolic name " + sym_name;
293  throw BESSyntaxUserError(s, __FILE__, __LINE__);
294  }
295  }
296 
297  return ret_container;
298 }
299 
313 {
314  BESContainerStorageList::persistence_list *pl = _first;
315  while (pl) {
316  map<string, string> props;
317  props["name"] = pl->_persistence_obj->get_name();
318  info.begin_tag("store", &props);
319  pl->_persistence_obj->show_containers(info);
320  info.end_tag("store");
321  pl = pl->_next;
322  }
323 }
324 
332 void BESContainerStorageList::dump(ostream &strm) const
333 {
334  strm << BESIndent::LMarg << "BESContainerStorageList::dump - (" << (void *) this << ")" << endl;
336  BESContainerStorageList::persistence_list *pl = _first;
337  if (pl) {
338  strm << BESIndent::LMarg << "container storage:" << endl;
340  while (pl) {
341  pl->_persistence_obj->dump(strm);
342  pl = pl->_next;
343  }
345  }
346  else {
347  strm << BESIndent::LMarg << "container storage: empty" << endl;
348  }
350 }
351 
354 {
355  if (_instance == 0) {
356  _instance = new BESContainerStorageList;
357  }
358  return _instance;
359 }
360 
provides persistent storage for data storage information represented by a container.
exception thrown if inernal error encountered
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
static void Indent()
Definition: BESIndent.cc:38
error thrown if there is a user syntax error in the request or any other user error ...
virtual bool ref_persistence(const string &persist_name)
refence the specified persistent store if in the list
virtual void dump(ostream &strm) const
dumps information about this object
informational response object
Definition: BESInfo.h:68
Provides a mechanism for accessing container information from different container stores registered w...
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:142
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual bool deref_persistence(const string &persist_name)
dereference a persistent store in the list.
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: BESKeys.cc:453
virtual BESContainer * look_for(const string &sym_name)
look for the specified container information in the list of persistent stores.
static BESContainerStorageList * TheList()
static BESLog * TheLog()
Definition: BESLog.cc:347
A container is something that holds data.
Definition: BESContainer.h:60
static void UnIndent()
Definition: BESIndent.cc:44
virtual void show_containers(BESInfo &info)
show information for each container in each persistence store
static BESKeys * TheKeys()
Definition: TheBESKeys.cc:48
virtual const string & get_name() const
retrieve the name of this persistent store
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149