Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
bucket.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Couchbase, 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 <couchbase/support.hxx>
20 
21 #include <chrono>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <thread>
26 #include <vector>
33 namespace couchbase
34 {
35 class collection;
36 class cluster;
37 
39 template<typename T> class pool;
40 
44 class bucket : public std::enable_shared_from_this<bucket>
45 {
46  friend class collection;
47  friend class cluster;
48 
49  private:
50  std::unique_ptr<pool<lcb_st*>> instance_pool_;
51  const std::string name_;
52  std::vector<std::shared_ptr<class collection> > collections_;
53  std::shared_ptr<class collection> find_or_create_collection(const std::string& name);
54  std::mutex mutex_;
55  std::chrono::microseconds kv_timeout_;
56 
57  bucket(std::unique_ptr<pool<lcb_st*>>& instance_pool, const std::string& name, std::chrono::microseconds kv_timeout);
58 
59  static const std::string default_name;
60 
61  public:
67  CB_NODISCARD std::shared_ptr<class collection> default_collection();
74  CB_NODISCARD std::shared_ptr<class collection> collection(const std::string& name);
83  CB_NODISCARD const std::string& name() const
84  {
85  return name_;
86  };
95  void close();
101  ~bucket();
102 
114  CB_NODISCARD size_t max_instances() const;
115 
121  CB_NODISCARD size_t instances() const;
122 
128  CB_NODISCARD size_t available_instances() const;
129 
136  CB_NODISCARD std::chrono::microseconds default_kv_timeout() const;
137 
141  template<typename OStream>
142  friend OStream& operator<<(OStream& os, const bucket& b)
143  {
144  os << "bucket:{";
145  os << "name: " << b.name() << ",";
146  os << "instance_pool: " << *b.instance_pool_;
147  os << "}";
148  return os;
149  }
150 
151  CB_NODISCARD bool operator==(const bucket& b) const
152  {
153  return &b == this;
154  }
155 };
156 }// namespace couchbase
Exposes bucket-level operations and collections accessors.
Definition: bucket.hxx:45
CB_NODISCARD size_t available_instances() const
return the current number of libcouchbase instances that are not being used.
Definition: bucket.hxx:33
void close()
Close connection to this bucket.
CB_NODISCARD size_t max_instances() const
return maximum number of libcouchbase instances this bucket can use
CB_NODISCARD size_t instances() const
return current number of libcouchbase instances the cluster has created.
~bucket()
Destroy the bucket.
CB_NODISCARD std::shared_ptr< class collection > default_collection()
Connects to a couchbase cluster, exposes cluster operations and bucket accessors. ...
Definition: cluster.hxx:172
CB_NODISCARD std::chrono::microseconds default_kv_timeout() const
return default kv timeout
CB_NODISCARD const std::string & name() const
Get collection name.
Definition: bucket.hxx:84
friend OStream & operator<<(OStream &os, const bucket &b)
convienence method to allow outputtng information about the bucket to an ostream or similar...
Definition: bucket.hxx:143
Exposes collection-level kv operations.
Definition: collection.hxx:46