ScaleOut C++ Native Client API  5.1
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
object_metadata.h
1 /*
2  Copyright (c) 2013 by ScaleOut Software, Inc.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #pragma once
18 
19 #include <vector>
20 #include <stdint.h>
21 #include "boost/date_time/posix_time/posix_time_duration.hpp"
22 #include "soss_client/object_policy.h"
23 
24 namespace sosscli {
25 
27 class ObjectMetadata;
28 
31 {
32 public:
33 
34  /* Constants */
35 
39 
40  /* Constructors */
41 
44  : throw_on_error_(true) {}
45 
50  : throw_on_error_(throw_on_error) {}
51 
53  virtual ~GetMetadataOptions() {};
54 
55  /* Accessors */
56 
59  bool throw_on_error() const { return throw_on_error_; }
65  GetMetadataOptions& set_throw_on_error(bool throw_on_error) { throw_on_error_ = throw_on_error; return *this; }
66 
67 protected:
68 
69 private:
70 
71  bool throw_on_error_;
72 };
73 
74 
77 {
78 public:
79 
80  /* Constructors */
81 
83  GetMetadataResult(int32_t return_code, boost::shared_ptr<ObjectMetadata> object_ptr)
84  : return_code_(return_code), object_ptr_(object_ptr) {}
85 
87  virtual ~GetMetadataResult() {};
88 
89  /* Accessors */
90 
93  boost::shared_ptr<ObjectMetadata> object_ptr()
94  {
95  if (return_code_ < 1)
96  throw std::runtime_error("The object was not retrieved successfully. Check GetMetadataResult.return_code() for error info.");
97  return object_ptr_;
98  }
99 
101  int32_t return_code() { return return_code_; }
102 
103 protected:
104 
105 private:
106  GetMetadataResult() {}
107 
108  int32_t return_code_;
109  boost::shared_ptr<ObjectMetadata> object_ptr_;
110 };
111 
117 {
118 public:
120  ObjectMetadata(PSOSS_OBJ_METADATA pobj_metadata)
121  {
122  boost::posix_time::time_duration timeout;
123  if(pobj_metadata->timeout_granularity == SOSSLIB_TIMEOUT_GRAN_SECONDS)
124  timeout = boost::posix_time::seconds(pobj_metadata->timeout);
125  else
126  timeout = boost::posix_time::minutes(pobj_metadata->timeout);
127 
128  std::vector<SossKey> parents(pobj_metadata->parent_list, pobj_metadata->parent_list + SOSSLIB_MAX_PARENTS);
129 
130  // Construct the ObjectPolicy from various SOSS_OBJ_METADATA parameters
131  object_policy_
132  .set_timeout(timeout)
133  .set_timeout_type(static_cast<ObjectPolicy::TimeoutType>(pobj_metadata->absolute_timeout))
134  .set_preemption_priority(static_cast<ObjectPolicy::PreemptionPriority>(pobj_metadata->allow_lru))
135  .set_allow_push_repl(pobj_metadata->allow_repl != 0)
136  .set_parents(std::vector<SossKey>(pobj_metadata->parent_list, pobj_metadata->parent_list + SOSSLIB_MAX_PARENTS));
137 
138  // The remainder of the SOSS_OBJ_DATA parameters are not expressed in the ObjectPolicy, and are stored local to this class.
139  size_ = pobj_metadata->size;
140  backstore_mode_ = static_cast<BackingStoreMode>(pobj_metadata->backstore_mode);
141  immutable_ = (pobj_metadata->immutable == TRUE);
142  backstore_timeout_ = boost::posix_time::seconds(pobj_metadata->backstore_timeout);
143  coherency_timeout_ = boost::posix_time::seconds(pobj_metadata->coherency_timeout);
144  coherency_policy_ = static_cast<CoherencyPolicy>(pobj_metadata->coherency_policy);
145  last_replication_succeeded_ = static_cast<ReplicationStatus>(pobj_metadata->replication_status);
146  is_proxy_ = (pobj_metadata->is_proxy == TRUE);
147  allow_remote_ = (pobj_metadata->allow_remote == TRUE);
148  }
149 
151  virtual ~ObjectMetadata(void) {}
152 
155  {
156  ASYNC_WRITE_BEHIND,
157  ASYNC_REFRESH_AHEAD,
158  ASYNC_WRITE_AND_REFRESH
159  };
160 
163  {
164  NONE,
165  POLL,
166  NOTIFY
167  };
168 
171  {
172  SUCCESS,
173  UPDATE_FAILED,
174  REFRESH_FAILED
175  };
176 
177 public:
179  ObjectPolicy object_policy() const { return object_policy_; }
180 
182  unsigned long size() const { return size_; }
183 
185  BackingStoreMode backstore_mode() const { return backstore_mode_; }
186 
188  bool immutable() const { return immutable_; }
189 
191  boost::posix_time::time_duration backstore_timeout() const { return backstore_timeout_; }
192 
194  boost::posix_time::time_duration coherency_timeout() const { return coherency_timeout_; }
195 
197  CoherencyPolicy coherency_policy() const { return coherency_policy_; }
198 
200  ReplicationStatus last_replication_succeeded() const { return last_replication_succeeded_; }
201 
203  bool is_proxy() const { return is_proxy_; }
204 
206  bool allow_remote() const { return allow_remote_; }
207 
208 private:
210  ObjectPolicy object_policy_;
211 
213  unsigned long size_;
214 
216  BackingStoreMode backstore_mode_;
217 
219  bool immutable_;
220 
222  boost::posix_time::time_duration
223  backstore_timeout_;
224 
226  boost::posix_time::time_duration
227  coherency_timeout_;
228 
230  CoherencyPolicy coherency_policy_;
231 
233  ReplicationStatus last_replication_succeeded_;
234 
236  bool is_proxy_;
237 
239  bool allow_remote_;
240 };
241 
242 }
243