Rev 1627 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1619 | runge | 1 | /* |
| 2 | * |
||
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | |||
| 21 | #include "Manager.h" |
||
| 22 | |||
| 1964 | runge | 23 | #include "common/exception.h" |
| 24 | |||
| 1619 | runge | 25 | namespace atom { |
| 26 | namespace storage { |
||
| 27 | |||
| 28 | Manager::Pointer Manager::instance_; |
||
| 29 | |||
| 30 | Manager::Manager() : LOG("storage::Manager") |
||
| 31 | { |
||
| 32 | } |
||
| 33 | |||
| 34 | Manager::~Manager() |
||
| 35 | { |
||
| 36 | for (StoreList::iterator it = this->stores_.begin(); it != this->stores_.end(); it++) |
||
| 37 | { |
||
| 38 | try |
||
| 39 | { |
||
| 40 | it->second->Flush(); |
||
| 41 | } |
||
| 42 | catch (std::runtime_error& e) |
||
| 43 | { |
||
| 44 | LOG.Error("Error while flusing store, " + std::string(e.what())); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | Manager::Pointer Manager::Instance() |
||
| 50 | { |
||
| 51 | return Manager::instance_; |
||
| 52 | } |
||
| 53 | |||
| 54 | void Manager::Create() |
||
| 55 | { |
||
| 56 | Manager::instance_ = Manager::Pointer(new Manager()); |
||
| 57 | } |
||
| 58 | |||
| 59 | void Manager::Delete() |
||
| 60 | { |
||
| 61 | Manager::instance_.reset(); |
||
| 62 | } |
||
| 63 | |||
| 64 | void Manager::SetRootPath(std::string root_path) |
||
| 65 | { |
||
| 66 | this->root_path_ = root_path; |
||
| 67 | } |
||
| 68 | |||
| 1627 | runge | 69 | void Manager::SetStoreFlushPolicy(std::string store_name, Store::FlushPolicy flush_policy) |
| 70 | { |
||
| 71 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 72 | |||
| 73 | if (it == this->stores_.end()) |
||
| 74 | { |
||
| 75 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 76 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 77 | } |
||
| 78 | |||
| 79 | this->stores_[store_name]->SetFlushPolicy(flush_policy); |
||
| 80 | } |
||
| 81 | |||
| 82 | void Manager::FlushStore(std::string store_name) |
||
| 83 | { |
||
| 84 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 85 | |||
| 86 | if (it == this->stores_.end()) |
||
| 87 | { |
||
| 88 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 89 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 90 | } |
||
| 91 | |||
| 92 | this->stores_[store_name]->Flush(); |
||
| 93 | } |
||
| 94 | |||
| 1619 | runge | 95 | Store::ParameterList& Manager::GetParameters(std::string store_name) |
| 96 | { |
||
| 97 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 98 | |||
| 99 | if (it == this->stores_.end()) |
||
| 100 | { |
||
| 101 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 102 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 103 | } |
||
| 104 | |||
| 105 | return this->stores_[store_name]->GetParameters(); |
||
| 106 | } |
||
| 107 | |||
| 108 | std::string Manager::GetParameter(std::string store_name, std::string parameter_name) |
||
| 109 | { |
||
| 110 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 111 | |||
| 112 | if (it == this->stores_.end()) |
||
| 113 | { |
||
| 114 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 115 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 116 | } |
||
| 117 | |||
| 118 | return this->stores_[store_name]->GetParameter(parameter_name); |
||
| 119 | } |
||
| 120 | |||
| 121 | void Manager::SetParameter(std::string store_name, std::string parameter_name, std::string parameter_value) |
||
| 122 | { |
||
| 123 | StoreList::iterator it = this->stores_.find(store_name); |
||
| 124 | |||
| 125 | if (it == this->stores_.end()) |
||
| 126 | { |
||
| 127 | LOG.Info("Loading storage " + store_name + "..."); |
||
| 128 | this->stores_[store_name] = Store::Pointer(new Store(this->root_path_ + store_name)); |
||
| 129 | } |
||
| 130 | |||
| 131 | return this->stores_[store_name]->SetParameter(parameter_name, parameter_value); |
||
| 132 | } |
||
| 133 | |||
| 134 | }; // namespace timer |
||
| 135 | }; // namespace atom |