1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.codec.prefixtree.decode;
20
21 import java.nio.ByteBuffer;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
25 import org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher;
26
27
28
29
30 @InterfaceAudience.Private
31 public class DecoderFactory {
32
33 private static final ArraySearcherPool POOL = new ArraySearcherPool();
34
35
36 public static PrefixTreeArraySearcher checkOut(final ByteBuffer buffer,
37 boolean includeMvccVersion) {
38 if (buffer.isDirect()) {
39 throw new IllegalArgumentException("DirectByteBuffers not supported yet");
40
41 }
42
43 PrefixTreeArraySearcher searcher = POOL.checkOut(buffer,
44 includeMvccVersion);
45 return searcher;
46 }
47
48 public static void checkIn(CellSearcher pSearcher) {
49 if (pSearcher == null) {
50 return;
51 }
52 if (! (pSearcher instanceof PrefixTreeArraySearcher)) {
53 throw new IllegalArgumentException("Cannot return "+pSearcher.getClass()+" to "
54 +DecoderFactory.class);
55 }
56 PrefixTreeArraySearcher searcher = (PrefixTreeArraySearcher) pSearcher;
57 POOL.checkIn(searcher);
58 }
59
60
61
62 public static PrefixTreeArraySearcher ensureArraySearcherValid(ByteBuffer buffer,
63 PrefixTreeArraySearcher searcher, boolean includeMvccVersion) {
64 if (searcher == null) {
65 PrefixTreeBlockMeta blockMeta = new PrefixTreeBlockMeta(buffer);
66 searcher = new PrefixTreeArraySearcher(blockMeta, blockMeta.getRowTreeDepth(),
67 blockMeta.getMaxRowLength(), blockMeta.getMaxQualifierLength(),
68 blockMeta.getMaxTagsLength());
69 searcher.initOnBlock(blockMeta, buffer.array(), includeMvccVersion);
70 return searcher;
71 }
72
73 PrefixTreeBlockMeta blockMeta = searcher.getBlockMeta();
74 blockMeta.initOnBlock(buffer);
75 if (!searcher.areBuffersBigEnough()) {
76 int maxRowTreeStackNodes = Math.max(blockMeta.getRowTreeDepth(),
77 searcher.getMaxRowTreeStackNodes());
78 int rowBufferLength = Math.max(blockMeta.getMaxRowLength(), searcher.getRowBufferLength());
79 int qualifierBufferLength = Math.max(blockMeta.getMaxQualifierLength(),
80 searcher.getQualifierBufferLength());
81 int tagBufferLength = Math.max(blockMeta.getMaxTagsLength(), searcher.getTagBufferLength());
82 searcher = new PrefixTreeArraySearcher(blockMeta, maxRowTreeStackNodes, rowBufferLength,
83 qualifierBufferLength, tagBufferLength);
84 }
85
86 searcher.initOnBlock(blockMeta, buffer.array(), includeMvccVersion);
87 return searcher;
88 }
89
90 }