import org.apache.hadoop.conf.Configuration;
import java.io.IOException;
/**
* Created by Michael on 2015/6/22.
*/
public class EndpointExample {
// private final HTableInterface table;
// private static final Configuration conf;
// private static final HTableDescriptor EP_TABLE_DISCRIPTOR;
//
// static {
// conf = new Configuration();
// conf.set("hbase.zookeeper.quorum", "ccf04:2181");
//
// EP_TABLE_DISCRIPTOR = new HTableDescriptor("epTest");
// HColumnDescriptor family = new HColumnDescriptor("_tis".getBytes());
// family.setInMemory(true);
// family.setMaxVersions(1);
// EP_TABLE_DISCRIPTOR.addFamily(family);
// try {
// EP_TABLE_DISCRIPTOR.addCoprocessor("ict.wde.test.RowCountServer");
// } catch (IOException ioe) {
//
// }
//
// table = initTidTable();
// }
//
// private HTableInterface initTidTable() throws IOException {
// HBaseAdmin admin = new HBaseAdmin(conf);
// if (!admin.tableExists("epTest")) {
// admin.createTable(EP_TABLE_DISCRIPTOR);
// }
// admin.close();
// return new HTable(conf, "epTest");
// }
public static void main(String[] agrs) throws IOException {
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum", "ccf04:2181");
EndpointTestClient client = new EndpointTestClient(conf);
String name = client.getStr();
System.out.println(name);
}
}
在Hbase Endpoint Coprocessor中使用coprocessor Proxy操作例子与问题解析(二)
t.HTableInterface;
import org.apache.hadoop.hbase.filter.Filter;
import java.io.IOException;
/**
* Created by Michael on 2015/6/30.
*/
public class EndpointTestClient {
private final HTableInterface table;
private final Configuration conf;
private final RowCountProtocol server;
private static final HTableDescriptor EP_TABLE_DISCRIPTOR;
static {
EP_TABLE_DISCRIPTOR = new HTableDescriptor("epTest");
HColumnDescriptor family = new HColumnDescriptor("_tis".getBytes());
family.setInMemory(true);
family.setMaxVersions(1);
EP_TABLE_DISCRIPTOR.addFamily(family);
try {
EP_TABLE_DISCRIPTOR.addCoprocessor("ict.wde.test.RowCountServer");
} catch (IOException ioe) {
}
}
public EndpointTestClient(Configuration config) throws IOException {
conf = config;
table = initTidTable();
server = table.coprocessorProxy(RowCountProtocol.class, "0".getBytes());
}
private HTableInterface initTidTable() throws IOException {
HBaseAdmin admin = new HBaseAdmin(conf);
if (!admin.tableExists("epTest")) {
admin.createTable(EP_TABLE_DISCRIPTOR);
}
admin.close();
return new HTable(conf, "epTest");
}
public String getStr() throws IOException {
return server.getStr();
}
}
启动类: