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_CLIENT_PACKETPOOL_H_ |
29 | #define _HDFS_LIBHDFS3_CLIENT_PACKETPOOL_H_ |
30 | #include "Memory.h" |
31 | |
32 | #include <deque> |
33 | |
34 | namespace Hdfs { |
35 | namespace Internal { |
36 | |
37 | class Packet; |
38 | |
39 | /* |
40 | * A simple packet pool implementation. |
41 | * |
42 | * Packet is created here if no packet is available. |
43 | * And then add to Pipeline's packet queue to wait for the ack. |
44 | * The Pipeline's packet queue size is not larger than the PacketPool's max size, |
45 | * otherwise the write operation will be pending for the ack. |
46 | * Once the ack is received, packet will reutrn back to the PacketPool to reuse. |
47 | */ |
48 | class PacketPool { |
49 | public: |
50 | PacketPool(int size); |
51 | shared_ptr<Packet> getPacket(int pktSize, int chunksPerPkt, |
52 | int64_t offsetInBlock, int64_t seqno, int checksumSize); |
53 | void relesePacket(shared_ptr<Packet> packet); |
54 | |
55 | void setMaxSize(int size) { |
56 | this->maxSize = size; |
57 | } |
58 | |
59 | int getMaxSize() const { |
60 | return maxSize; |
61 | } |
62 | |
63 | private: |
64 | int maxSize; |
65 | std::deque<shared_ptr<Packet> > packets; |
66 | }; |
67 | |
68 | } |
69 | } |
70 | |
71 | #endif /* _HDFS_LIBHDFS3_CLIENT_PACKETPOOL_H_ */ |
72 | |