1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.rest;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.client.HBaseAdmin;
27 import org.apache.hadoop.hbase.client.HTablePool;
28
29
30
31
32 @InterfaceAudience.Private
33 public class RESTServlet implements Constants {
34 private static RESTServlet INSTANCE;
35 private final Configuration conf;
36 private final HTablePool pool;
37 private final MetricsREST metrics = new MetricsREST();
38 private final HBaseAdmin admin;
39
40
41
42
43
44 public synchronized static RESTServlet getInstance() throws IOException {
45 assert(INSTANCE != null);
46 return INSTANCE;
47 }
48
49
50
51
52
53
54 public synchronized static RESTServlet getInstance(Configuration conf)
55 throws IOException {
56 if (INSTANCE == null) {
57 INSTANCE = new RESTServlet(conf);
58 }
59 return INSTANCE;
60 }
61
62 public synchronized static void stop() {
63 if (INSTANCE != null) INSTANCE = null;
64 }
65
66
67
68
69
70
71 RESTServlet(Configuration conf) throws IOException {
72 this.conf = conf;
73 int maxSize = conf.getInt("hbase.rest.htablepool.size", 10);
74 this.pool = new HTablePool(conf, maxSize);
75 this.admin = new HBaseAdmin(conf);
76 }
77
78 HBaseAdmin getAdmin() {
79 return admin;
80 }
81
82 HTablePool getTablePool() {
83 return pool;
84 }
85
86 Configuration getConfiguration() {
87 return conf;
88 }
89
90 MetricsREST getMetrics() {
91 return metrics;
92 }
93
94
95
96
97
98
99 boolean isReadOnly() {
100 return getConfiguration().getBoolean("hbase.rest.readonly", false);
101 }
102 }