0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Client.h
Go to the documentation of this file.
1 /* -*- c++ -*-
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; either version 3
9  * of the 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 #ifndef FsBroker_Lib_Client_h
28 #define FsBroker_Lib_Client_h
29 
31 
32 #include <AsyncComm/Comm.h>
35 
36 #include <Common/Filesystem.h>
37 #include <Common/InetAddr.h>
38 #include <Common/Properties.h>
39 #include <Common/Status.h>
40 
41 #include <memory>
42 #include <mutex>
43 #include <unordered_map>
44 
45 namespace Hypertable {
46 namespace FsBroker {
47 namespace Lib {
48 
51 
58  class Client : public Filesystem {
59  public:
60 
61  virtual ~Client();
62 
71  Client(ConnectionManagerPtr &conn_manager_ptr,
72  const sockaddr_in &addr, uint32_t timeout_ms);
73 
85  Client(ConnectionManagerPtr &conn_manager_ptr, PropertiesPtr &cfg);
86 
93  Client(Comm *comm, const sockaddr_in &addr, uint32_t timeout_ms);
94 
101  Client(const String &host, int port, uint32_t timeout_ms);
102 
109  bool wait_for_connection(uint32_t max_wait_ms) {
110  if (m_conn_mgr)
111  return m_conn_mgr->wait_for_connection(m_addr, max_wait_ms);
112  return true;
113  }
114 
115  void open(const String &name, uint32_t flags, DispatchHandler *handler) override;
116  int open(const String &name, uint32_t flags) override;
117  int open_buffered(const String &name, uint32_t flags, uint32_t buf_size,
118  uint32_t outstanding, uint64_t start_offset=0,
119  uint64_t end_offset=0) override;
120  void decode_response_open(EventPtr &event, int32_t *fd) override;
121 
122  void create(const String &name, uint32_t flags,
123  int32_t bufsz, int32_t replication,
124  int64_t blksz, DispatchHandler *handler) override;
125  int create(const String &name, uint32_t flags, int32_t bufsz,
126  int32_t replication, int64_t blksz) override;
127  void decode_response_create(EventPtr &event, int32_t *fd) override;
128 
129  void close(int32_t fd, DispatchHandler *handler) override;
130  void close(int32_t fd) override;
131 
132  void read(int32_t fd, size_t amount, DispatchHandler *handler) override;
133  size_t read(int32_t fd, void *dst, size_t amount) override;
134  void decode_response_read(EventPtr &event, const void **buffer,
135  uint64_t *offset, uint32_t *length) override;
136 
137  void append(int32_t fd, StaticBuffer &buffer, Flags flags,
138  DispatchHandler *handler) override;
139  size_t append(int32_t fd, StaticBuffer &buffer,
140  Flags flags = Flags::NONE) override;
141  void decode_response_append(EventPtr &event, uint64_t *offset,
142  uint32_t *length) override;
143 
144  void seek(int32_t fd, uint64_t offset, DispatchHandler *handler) override;
145  void seek(int32_t fd, uint64_t offset) override;
146 
147  void remove(const String &name, DispatchHandler *handler) override;
148  void remove(const String &name, bool force = true) override;
149 
150  void length(const String &name, bool accurate,
151  DispatchHandler *handler) override;
152  int64_t length(const String &name, bool accurate = true) override;
153  int64_t decode_response_length(EventPtr &event) override;
154 
155  void pread(int32_t fd, size_t len, uint64_t offset,
156  bool verify_checksum, DispatchHandler *handler) override;
157  size_t pread(int32_t fd, void *dst, size_t len, uint64_t offset,
158  bool verify_checksum) override;
159  void decode_response_pread(EventPtr &event, const void **buffer,
160  uint64_t *offset, uint32_t *length) override;
161 
162  void mkdirs(const String &name, DispatchHandler *handler) override;
163  void mkdirs(const String &name) override;
164 
165  void flush(int32_t fd, DispatchHandler *handler) override;
166  void flush(int32_t fd) override;
167 
168  void sync(int32_t fd) override;
169 
170  void rmdir(const String &name, DispatchHandler *handler) override;
171  void rmdir(const String &name, bool force = true) override;
172 
173  void readdir(const String &name, DispatchHandler *handler) override;
174  void readdir(const String &name, std::vector<Dirent> &listing) override;
175  void decode_response_readdir(EventPtr &event,
176  std::vector<Dirent> &listing) override;
177 
178  void exists(const String &name, DispatchHandler *handler) override;
179  bool exists(const String &name) override;
180  bool decode_response_exists(EventPtr &event) override;
181 
182  void rename(const String &src, const String &dst,
183  DispatchHandler *handler) override;
184  void rename(const String &src, const String &dst) override;
185 
186  void status(Status &status, Timer *timer=0) override;
187  void decode_response_status(EventPtr &event, Status &status) override;
188 
189  void debug(int32_t command, StaticBuffer &serialized_parameters) override;
190  void debug(int32_t command, StaticBuffer &serialized_parameters,
191  DispatchHandler *handler) override;
192 
193  enum {
196  };
197 
208  void shutdown(uint16_t flags, DispatchHandler *handler);
209 
214  uint32_t get_timeout() { return m_timeout_ms; }
215 
216  private:
217 
222  void send_message(CommBufPtr &cbuf, DispatchHandler *handler, Timer *timer=0);
223 
228  uint32_t m_timeout_ms;
229  std::unordered_map<uint32_t, ClientBufferedReaderHandler *> m_buffered_reader_map;
230  };
231 
233  typedef std::shared_ptr<Client> ClientPtr;
234 
236 
237 }}}
238 
239 
240 #endif // FsBroker_Lib_Client_h
241 
void decode_response_open(EventPtr &event, int32_t *fd) override
Decodes the response from an open request.
Definition: Client.cc:195
A memory buffer of static size.
Definition: StaticBuffer.h:45
static std::mutex mutex
Definition: Logger.cc:43
void sync(int32_t fd) override
Definition: Client.cc:795
int64_t decode_response_length(EventPtr &event) override
Decodes the response from a length request.
Definition: Client.cc:653
Holds Nagios-style program status information.
Definition: Status.h:42
int open_buffered(const String &name, uint32_t flags, uint32_t buf_size, uint32_t outstanding, uint64_t start_offset=0, uint64_t end_offset=0) override
Opens a file in buffered (readahead) mode.
Definition: Client.cc:170
Abstract base class for a filesystem.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
std::unordered_map< uint32_t, ClientBufferedReaderHandler * > m_buffered_reader_map
Definition: Client.h:229
Declarations for Status.
void mkdirs(const String &name, DispatchHandler *handler) override
Creates a directory asynchronously.
Definition: Client.cc:720
Abstract base class for application dispatch handlers registered with AsyncComm.
bool decode_response_exists(EventPtr &event) override
Decodes the response from an exists request.
Definition: Client.cc:947
Flags
Enumeration type for append flags.
Definition: Filesystem.h:76
Program options handling.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
void flush(int32_t fd, DispatchHandler *handler) override
Definition: Client.cc:757
void append(int32_t fd, StaticBuffer &buffer, Flags flags, DispatchHandler *handler) override
Definition: Client.cc:404
void decode_response_pread(EventPtr &event, const void **buffer, uint64_t *offset, uint32_t *length) override
Decodes the response from a pread request.
Definition: Client.cc:715
ConnectionManagerPtr m_conn_mgr
Definition: Client.h:226
void status(Status &status, Timer *timer=0) override
Check status of filesystem.
Definition: Client.cc:579
void send_message(CommBufPtr &cbuf, DispatchHandler *handler, Timer *timer=0)
Sends a message to the FS broker.
Definition: Client.cc:1041
void length(const String &name, bool accurate, DispatchHandler *handler) override
Gets the length of a file asynchronously.
Definition: Client.cc:615
void decode_response_status(EventPtr &event, Status &status) override
Decodes the response from an status request.
Definition: Client.cc:600
uint32_t get_timeout()
Gets the configured request timeout value.
Definition: Client.h:214
void create(const String &name, uint32_t flags, int32_t bufsz, int32_t replication, int64_t blksz, DispatchHandler *handler) override
Creates a file asynchronously.
Definition: Client.cc:210
void readdir(const String &name, DispatchHandler *handler) override
Obtains a listing of all files in a directory asynchronously.
Definition: Client.cc:856
void close(int32_t fd, DispatchHandler *handler) override
Definition: Client.cc:260
Encapsulate an internet address.
Definition: InetAddr.h:66
void decode_response_create(EventPtr &event, int32_t *fd) override
Decodes the response from a create request.
Definition: Client.cc:254
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:233
void pread(int32_t fd, size_t len, uint64_t offset, bool verify_checksum, DispatchHandler *handler) override
Definition: Client.cc:668
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
void decode_response_readdir(EventPtr &event, std::vector< Dirent > &listing) override
Decodes the response from a readdir request.
Definition: Client.cc:894
bool wait_for_connection(uint32_t max_wait_ms)
Waits up to max_wait_secs for a connection to be established with the FS broker.
Definition: Client.h:109
void debug(int32_t command, StaticBuffer &serialized_parameters) override
Invokes debug request asynchronously.
Definition: Client.cc:1017
void read(int32_t fd, size_t amount, DispatchHandler *handler) override
Definition: Client.cc:321
void rename(const String &src, const String &dst, DispatchHandler *handler) override
Rename a path asynchronously.
Definition: Client.cc:963
Hypertable definitions
void shutdown(uint16_t flags, DispatchHandler *handler)
Shuts down the FS broker.
Definition: Client.cc:566
Entry point to AsyncComm service.
Definition: Comm.h:61
Client(ConnectionManagerPtr &conn_manager_ptr, const sockaddr_in &addr, uint32_t timeout_ms)
Constructor with explicit values.
Definition: Client.cc:74
Declarations for ConnectionManager.
Declarations for Comm.
void open(const String &name, uint32_t flags, DispatchHandler *handler) override
Opens a file asynchronously.
Definition: Client.cc:128
Internet address wrapper classes and utility functions.
void rmdir(const String &name, DispatchHandler *handler) override
Recursively removes a directory asynchronously.
Definition: Client.cc:817
A timer class to keep timeout states across AsyncComm related calls.
Definition: Timer.h:44
Proxy class for FS broker.
Definition: Client.h:58
void seek(int32_t fd, uint64_t offset, DispatchHandler *handler) override
Definition: Client.cc:488
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
void decode_response_append(EventPtr &event, uint64_t *offset, uint32_t *length) override
Decodes the response from an append request.
Definition: Client.cc:471
void decode_response_read(EventPtr &event, const void **buffer, uint64_t *offset, uint32_t *length) override
Decodes the response from a read request.
Definition: Client.cc:378
void exists(const String &name, DispatchHandler *handler) override
Determines if a file exists asynchronously.
Definition: Client.cc:909
Declarations for DispatchHandlerSynchronizer.
Abstract base class for a filesystem.
Definition: Filesystem.h:72