0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RecoveredServers.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #include <Common/Compat.h>
28 
29 #include "RecoveredServers.h"
30 
32 
33 #include <Common/Serialization.h>
34 
35 using namespace Hypertable;
36 using namespace std;
37 
39  : MetaLog::Entity(MetaLog::EntityType::RECOVERED_SERVERS) {
40 }
41 
43  : MetaLog::Entity(header) {
44 }
45 
46 void RecoveredServers::add(const std::string &location) {
47  lock_guard<mutex> lock(m_mutex);
48  m_servers.insert(location);
49 }
50 
51 bool RecoveredServers::contains(const std::string &location) {
52  lock_guard<mutex> lock(m_mutex);
53  return m_servers.count(location) == 1;
54 }
55 
57  return (uint8_t)1;
58 }
59 
61  size_t length = 4;
62  for (auto &name : m_servers)
64  return length;
65 }
66 
67 void RecoveredServers::encode_internal(uint8_t **bufp) const {
69  for (auto &name : m_servers)
71 }
72 
73 void RecoveredServers::decode_internal(uint8_t version, const uint8_t **bufp,
74  size_t *remainp) {
75  size_t count = Serialization::decode_i32(bufp, remainp);
76  for (size_t i=0; i<count; ++i)
77  m_servers.insert(Serialization::decode_vstr(bufp, remainp));
78 }
79 
80 void RecoveredServers::decode(const uint8_t **bufp, size_t *remainp,
81  uint16_t definition_version) {
82  Entity::decode(bufp, remainp);
83 }
84 
85 const std::string RecoveredServers::name() {
86  return "RecoveredServers";
87 }
88 
89 void RecoveredServers::display(std::ostream &os) {
90  lock_guard<mutex> lock(m_mutex);
91  bool output_comma {};
92  for (auto &name : m_servers) {
93  if (output_comma)
94  os << ",";
95  else
96  output_comma = true;
97  os << name;
98  }
99 }
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
Master MetaLog entity type constants.
void decode(const uint8_t **bufp, size_t *remainp, uint16_t definition_version) override
MetaLog entity decode method.
std::set< std::string > m_servers
Set of proxy names of recovered servers.
Declarations for RecoveredServers.
std::mutex m_mutex
Mutex for serializing access to members
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
uint8_t encoding_version() const override
Returns encoding version.
bool contains(const std::string &location)
Check to see if proxy name is in recovered servers set.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
void lock()
Locks the entity's mutex.
Definition: MetaLogEntity.h:97
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
size_t encoded_length_internal() const override
Returns internal serialized length.
const std::string name() override
Returns the name of the entity (RecoveredServers).
void display(std::ostream &os) override
Writes a textual representation of the entity to an output stream.
void add(const std::string &location)
Adds proxy name to recovered servers set.
RecoveredServers()
Default constructor.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.