| 1 | /******************************************************************** |
| 2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Zhanwei Wang |
| 6 | ********************************************************************/ |
| 7 | /******************************************************************** |
| 8 | * 2014 - |
| 9 | * open source under Apache License Version 2.0 |
| 10 | ********************************************************************/ |
| 11 | /** |
| 12 | * Licensed to the Apache Software Foundation (ASF) under one |
| 13 | * or more contributor license agreements. See the NOTICE file |
| 14 | * distributed with this work for additional information |
| 15 | * regarding copyright ownership. The ASF licenses this file |
| 16 | * to you under the Apache License, Version 2.0 (the |
| 17 | * "License"); you may not use this file except in compliance |
| 18 | * with the License. You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
| 27 | */ |
| 28 | #ifndef _HDFS_LIBHDFS3_SERVER_LOCATEDBLOCKS_H_ |
| 29 | #define _HDFS_LIBHDFS3_SERVER_LOCATEDBLOCKS_H_ |
| 30 | |
| 31 | #include "LocatedBlock.h" |
| 32 | #include "Memory.h" |
| 33 | |
| 34 | #include <cassert> |
| 35 | |
| 36 | namespace Hdfs { |
| 37 | namespace Internal { |
| 38 | |
| 39 | class LocatedBlocks { |
| 40 | public: |
| 41 | virtual ~LocatedBlocks() {} |
| 42 | |
| 43 | virtual int64_t getFileLength() const = 0; |
| 44 | |
| 45 | virtual void setFileLength(int64_t fileLength) = 0; |
| 46 | |
| 47 | virtual bool isLastBlockComplete() const = 0; |
| 48 | |
| 49 | virtual void setIsLastBlockComplete(bool lastBlockComplete) = 0; |
| 50 | |
| 51 | virtual shared_ptr<LocatedBlock> getLastBlock() = 0; |
| 52 | |
| 53 | virtual void setLastBlock(shared_ptr<LocatedBlock> lastBlock) = 0; |
| 54 | |
| 55 | virtual bool isUnderConstruction() const = 0; |
| 56 | |
| 57 | virtual void setUnderConstruction(bool underConstruction) = 0; |
| 58 | |
| 59 | virtual const LocatedBlock * findBlock(int64_t position) = 0; |
| 60 | |
| 61 | virtual std::vector<LocatedBlock> & getBlocks() = 0; |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * Collection of blocks with their locations and the file length. |
| 66 | */ |
| 67 | class LocatedBlocksImpl : public LocatedBlocks { |
| 68 | public: |
| 69 | int64_t getFileLength() const { |
| 70 | return fileLength; |
| 71 | } |
| 72 | |
| 73 | void setFileLength(int64_t fileLength) { |
| 74 | this->fileLength = fileLength; |
| 75 | } |
| 76 | |
| 77 | bool isLastBlockComplete() const { |
| 78 | return lastBlockComplete; |
| 79 | } |
| 80 | |
| 81 | void setIsLastBlockComplete(bool lastBlockComplete) { |
| 82 | this->lastBlockComplete = lastBlockComplete; |
| 83 | } |
| 84 | |
| 85 | shared_ptr<LocatedBlock> getLastBlock() { |
| 86 | assert(!lastBlockComplete); |
| 87 | return lastBlock; |
| 88 | } |
| 89 | |
| 90 | void setLastBlock(shared_ptr<LocatedBlock> lastBlock) { |
| 91 | this->lastBlock = lastBlock; |
| 92 | } |
| 93 | |
| 94 | bool isUnderConstruction() const { |
| 95 | return underConstruction; |
| 96 | } |
| 97 | |
| 98 | void setUnderConstruction(bool underConstruction) { |
| 99 | this->underConstruction = underConstruction; |
| 100 | } |
| 101 | |
| 102 | const LocatedBlock * findBlock(int64_t position); |
| 103 | |
| 104 | std::vector<LocatedBlock> & getBlocks() { |
| 105 | return blocks; |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | bool lastBlockComplete; |
| 110 | bool underConstruction; |
| 111 | int64_t fileLength; |
| 112 | shared_ptr<LocatedBlock> lastBlock; |
| 113 | std::vector<LocatedBlock> blocks; |
| 114 | |
| 115 | }; |
| 116 | |
| 117 | } |
| 118 | } |
| 119 | #endif /* _HDFS_LIBHDFS3_SERVER_LOCATEDBLOCKS_H_ */ |
| 120 | |