filesystem.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef FS_FILESYSTEM_H_
  19. #define FS_FILESYSTEM_H_
  20. #include "namenode_protocol.h"
  21. #include "common/wrapper.h"
  22. #include "libhdfs++/hdfs.h"
  23. namespace hdfs {
  24. class FileSystemImpl : public FileSystem {
  25. public:
  26. FileSystemImpl(IoService *io_service);
  27. Status Connect(const char *server, unsigned short port);
  28. virtual Status Open(const char *path, InputStream **isptr) override;
  29. RpcEngine &rpc_engine() { return engine_; }
  30. private:
  31. IoServiceImpl *io_service_;
  32. RpcEngine engine_;
  33. ClientNamenodeProtocol namenode_;
  34. };
  35. class InputStreamImpl : public InputStream {
  36. public:
  37. InputStreamImpl(FileSystemImpl *fs, const ::hadoop::hdfs::LocatedBlocksProto *blocks);
  38. virtual Status PositionRead(void *buf, size_t nbyte, size_t offset, size_t *read_bytes) override;
  39. template<class MutableBufferSequence, class Handler>
  40. void AsyncPreadSome(size_t offset, const MutableBufferSequence &buffers,
  41. const Handler &handler);
  42. private:
  43. FileSystemImpl *fs_;
  44. unsigned long long file_length_;
  45. std::vector<::hadoop::hdfs::LocatedBlockProto> blocks_;
  46. struct HandshakeContinuation;
  47. template<class MutableBufferSequence>
  48. struct ReadBlockContinuation;
  49. };
  50. }
  51. #include "inputstream_impl.h"
  52. #endif