HBase Java编程示例

- package elementary;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.TimeUnit;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.Cell;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.apache.hadoop.hbase.HColumnDescriptor;
- import org.apache.hadoop.hbase.HTableDescriptor;
- import org.apache.hadoop.hbase.MasterNotRunningException;
- import org.apache.hadoop.hbase.TableName;
- import org.apache.hadoop.hbase.ZooKeeperConnectionException;
- import org.apache.hadoop.hbase.client.Delete;
- import org.apache.hadoop.hbase.client.Get;
- import org.apache.hadoop.hbase.client.Admin;
- import org.apache.hadoop.hbase.client.BufferedMutator;
- import org.apache.hadoop.hbase.client.BufferedMutatorParams;
- import org.apache.hadoop.hbase.client.Connection;
- import org.apache.hadoop.hbase.client.ConnectionFactory;
- import org.apache.hadoop.hbase.client.Table;
- import org.apache.hadoop.hbase.client.Put;
- import org.apache.hadoop.hbase.client.Result;
- import org.apache.hadoop.hbase.client.ResultScanner;
- import org.apache.hadoop.hbase.client.Scan;
- import org.apache.hadoop.hbase.util.Bytes;
- import org.apache.hadoop.util.ThreadUtil;
- public class HelloWorld {
- private static Configuration conf = null;
- private static Connection conn = null;
- private static Admin admin = null;
- public static AtomicInteger count = new AtomicInteger();
- /**
- * Initialization configuration
- */
- static {
- conf = HBaseConfiguration.create();
- //如果沒有配置文件,一定要記得手動宣告
- conf.set("hbase.zookeeper.quorum", "10.148.137.143");
- conf.set("hbase.zookeeper.property.clientPort", "2181");
- }
- static {
- try {
- conn = ConnectionFactory.createConnection();
- admin = conn.getAdmin();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- static public class MyThread extends Thread
- {
- int _start;
- String _tablename;
- Connection conn;
- //BufferedMutator table;
- Table table;
- public MyThread(int start, String tablename) {
- _start = start;
- _tablename = tablename;
- }
- public void run() {
- String tablename = _tablename;
- Thread current = Thread.currentThread();
- long thread_id = current.getId();
- System.out.printf("thread[%d] runn", thread_id);
- try {
- conn = ConnectionFactory.createConnection();
- //BufferedMutatorParams params = new BufferedMutatorParams(TableName.valueOf(tablename));
- //params.writeBufferSize(1024 * 4);
- //table = conn.getBufferedMutator(params);
- table = conn.getTable(TableName.valueOf(tablename));
- for (int j=_start; j
- for (int i=0; i
- // zkb_0_0
- String zkb = "zkb_" String.valueOf(_start) "_" String.valueOf(i);
- Put put = new Put(Bytes.toBytes(zkb));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field1"),Bytes.toBytes(String.valueOf(i 0)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field2"),Bytes.toBytes(String.valueOf(i 1)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field3"),Bytes.toBytes(String.valueOf(i 2)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field4"),Bytes.toBytes(String.valueOf(i 3)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field5"),Bytes.toBytes(String.valueOf(i 4)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field6"),Bytes.toBytes(String.valueOf(i 5)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field7"),Bytes.toBytes(String.valueOf(i 6)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field8"),Bytes.toBytes(String.valueOf(i 7)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field9"),Bytes.toBytes(String.valueOf(i 8)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field10"),Bytes.toBytes(String.valueOf(i 9)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field11"),Bytes.toBytes(String.valueOf(i 10)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field12"),Bytes.toBytes(String.valueOf(i 11)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field13"),Bytes.toBytes(String.valueOf(i 12)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field14"),Bytes.toBytes(String.valueOf(i 13)));
- put.addColumn(Bytes.toBytes("grade"),Bytes.toBytes("field15"),Bytes.toBytes(String.valueOf(i 14)));
- //table.mutate(put);
- table.put(put);
- int m = HelloWorld.count.incrementAndGet();
- if (m % 10000 == 0) {
- Date dt = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
- String now = sdf.format(dt);
- System.out.printf("[%s] thread[%d] m=%d, j=%d, i=%dn", now, thread_id, m, j, i);
- }
- }
- }
- System.out.printf("thread[%d] overn", thread_id);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * Create table
- * @param tablename
- * @param cfs
- */
- public static void createTable(String tablename, String[] cfs){
- try {
- if (admin.tableExists(TableName.valueOf(tablename))) {
- System.out.println("table already exists!");
- } else {
- HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tablename));
- for (int i = 0; i
- HColumnDescriptor desc = new HColumnDescriptor(cfs[i]);
- desc.setMaxVersions(3650);
- tableDesc.addFamily(desc);
- }
- byte[][] splitKeys = new byte[][] {
- Bytes.toBytes("zkb_0_0"),
- Bytes.toBytes("zkb_10_0"),
- Bytes.toBytes("zkb_20_0"),
- Bytes.toBytes("zkb_30_0"),
- Bytes.toBytes("zkb_40_0"),
- Bytes.toBytes("zkb_50_0"),
- Bytes.toBytes("zkb_60_0"),
- Bytes.toBytes("zkb_70_0"),
- Bytes.toBytes("zkb_80_0"),
- Bytes.toBytes("zkb_90_0"),
- Bytes.toBytes("zkb_100_0")
- };
- admin.createTable(tableDesc, splitKeys);
- admin.close();
- System.out.println("create table " tablename " ok.");
- }
- } catch (MasterNotRunningException e) {
- e.printStackTrace();
- } catch (ZooKeeperConnectionException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Delete table
- * @param tablename
- */
- public static void deleteTable(String tablename){
- try {
- //Connection conn = ConnectionFactory.createConnection();
- //Admin admin = conn.getAdmin();
- admin.disableTable(TableName.valueOf(tablename));
- admin.deleteTable(TableName.valueOf(tablename));
- System.out.println("delete table " tablename " ok.");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Delete a piece of data
- * @param tableName
- * @param rowKey
- */
- public static void delRecord (String tableName, String rowKey){
- try {
- Table table = conn.getTable(TableName.valueOf(tableName));
- List
list = new ArrayList (); - Delete del = new Delete(rowKey.getBytes());
- list.add(del);
- table.delete(list);
- System.out.println("del recored " rowKey " ok.");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * 取得一筆資料
- * @param tableName
- * @param rowKey
- */
- public static void getOneRecord (String tableName, String rowKey){
- try {
- Table table = conn.getTable(TableName.valueOf(tableName));
-
- Get get = new Get(rowKey.getBytes());
- Result rs = table.get(get);
- List
list = rs.listCells(); | - for(Cell cell:list){
- System.out.print(new String(cell.getRowArray(),cell.getRowOffset(),cell.getRowLength()) " " );
- System.out.print(new String(cell.getFamilyArray(),cell.getFamilyOffset(),cell.getFamilyLength()) ":" );
- System.out.print(new String(cell.getQualifierArray(),cell.getQualifierOffset(),cell.getQualifierLength()) " " );
- System.out.print(cell.getTimestamp() " " );
- System.out.print(new String(cell.getValueArray(),cell.getValueOffset(),cell.getValueLength()) " " );
- System.out.println("");
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Get all data
- * @param tableName
- */
- public static void getAllRecord (String tableName) {
- try{
- //Connection conn = ConnectionFactory.createConnection();
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- ResultScanner resultscanner = table.getScanner(scan);
- for(Result rs:resultscanner){
- List
list = rs.listCells(); | - for(Cell cell:list){
- System.out.print(new String(cell.getRowArray(),cell.getRowOffset(),cell.getRowLength()) " " );
- System.out.print(new String(cell.getFamilyArray(),cell.getFamilyOffset(),cell.getFamilyLength()) ":" );
- System.out.print(new String(cell.getQualifierArray(),cell.getQualifierOffset(),cell.getQualifierLength()) " " );
- System.out.print(cell.getTimestamp() " " );
- System.out.print(new String(cell.getValueArray(),cell.getValueOffset(),cell.getValueLength()) " " );
- System.out.println("");
- }
- }
- } catch (IOException e){
- e.printStackTrace();
- }
- }
- /**
- * Get Family List
- * @param tableName
- * @return
- */
- public static ArrayList
getAllFamilyName(String tableName) { - ArrayList
familyname_list = new ArrayList (); - try{
- //Connection conn = ConnectionFactory.createConnection();
- Table table = conn.getTable(TableName.valueOf(tableName));
- HTableDescriptor htabledescriptor = table.getTableDescriptor();
- HColumnDescriptor[] hdlist = htabledescriptor.getColumnFamilies();
- for(int i=0;i
- HColumnDescriptor hd = hdlist[i];
- familyname_list.add(hd.getNameAsString());
- }
- } catch (IOException e){
- e.printStackTrace();
- }
- return familyname_list;
- }
- // java -cp HelloWorld.jar:`ls lib/*.jar|awk '{printf("%s:", $0)}'` elementary.HelloWorld 5
- public static void main(String[] args) {
- System.out.println("HelloWorldX");
- if (args.length > 0)
- System.out.println(args[0]);
- int start = 0;
- if (args.length > 1)
- start = Integer.valueOf(args[1]);
- if (start
- start = 0;
- int num_threads = 16;
- if (args.length > 2)
- num_threads = Integer.valueOf(args[2]);
- try {
- String tablename = "scores";
- String[] familys = {"grade", "course"};
- HelloWorld.createTable(tablename, familys);
- //ExecutorService thread_pool = Executors.newSingleThreadExecutor();
- ExecutorService thread_pool = Executors.newFixedThreadPool(num_threads);
- Thread[] pool = new HelloWorld.MyThread[80];
- for (int i=0; i
- pool[i] = new HelloWorld.MyThread(i, tablename);
- thread_pool.execute(pool[i]);
- }
- thread_pool.shutdown();
- System.out.println("over");
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }

根据美国司法部的解释,蓝色警报旨在提供关于可能对执法人员构成直接和紧急威胁的个人的重要信息。这种警报的目的是及时通知公众,并让他们了解与这些罪犯相关的潜在危险。通过这种主动的方式,蓝色警报有助于增强社区的安全意识,促使人们采取必要的预防措施以保护自己和周围的人。这种警报系统的建立旨在提高对潜在威胁的警觉性,并加强执法机构与公众之间的沟通,以共尽管这些紧急通知对我们社会至关重要,但有时可能会对日常生活造成干扰,尤其是在午夜或重要活动时收到通知时。为了确保安全,我们建议您保持这些通知功能开启,但如果

Android中的轮询是一项关键技术,它允许应用程序定期从服务器或数据源检索和更新信息。通过实施轮询,开发人员可以确保实时数据同步并向用户提供最新的内容。它涉及定期向服务器或数据源发送请求并获取最新信息。Android提供了定时器、线程、后台服务等多种机制来高效地完成轮询。这使开发人员能够设计与远程数据源保持同步的响应式动态应用程序。本文探讨了如何在Android中实现轮询。它涵盖了实现此功能所涉及的关键注意事项和步骤。轮询定期检查更新并从服务器或源检索数据的过程在Android中称为轮询。通过

为了提升用户体验并防止数据或进度丢失,Android应用程序开发者必须避免意外退出。他们可以通过加入“再次按返回退出”功能来实现这一点,该功能要求用户在特定时间内连续按两次返回按钮才能退出应用程序。这种实现显著提升了用户参与度和满意度,确保他们不会意外丢失任何重要信息Thisguideexaminesthepracticalstepstoadd"PressBackAgaintoExit"capabilityinAndroid.Itpresentsasystematicguid

1.java复杂类如果有什么地方不懂,请看:JAVA总纲或者构造方法这里贴代码,很简单没有难度。2.smali代码我们要把java代码转为smali代码,可以参考java转smali我们还是分模块来看。2.1第一个模块——信息模块这个模块就是基本信息,说明了类名等,知道就好对分析帮助不大。2.2第二个模块——构造方法我们来一句一句解析,如果有之前解析重复的地方就不再重复了。但是会提供链接。.methodpublicconstructor(Ljava/lang/String;I)V这一句话分为.m

如何将WhatsApp聊天从Android转移到iPhone?你已经拿到了新的iPhone15,并且你正在从Android跳跃?如果是这种情况,您可能还对将WhatsApp从Android转移到iPhone感到好奇。但是,老实说,这有点棘手,因为Android和iPhone的操作系统不兼容。但不要失去希望。这不是什么不可能完成的任务。让我们在本文中讨论几种将WhatsApp从Android转移到iPhone15的方法。因此,坚持到最后以彻底学习解决方案。如何在不删除数据的情况下将WhatsApp

原因:1、安卓系统上设置了一个JAVA虚拟机来支持Java应用程序的运行,而这种虚拟机对硬件的消耗是非常大的;2、手机生产厂商对安卓系统的定制与开发,增加了安卓系统的负担,拖慢其运行速度影响其流畅性;3、应用软件太臃肿,同质化严重,在一定程度上拖慢安卓手机的运行速度。

1.启动ida端口监听1.1启动Android_server服务1.2端口转发1.3软件进入调试模式2.ida下断2.1attach附加进程2.2断三项2.3选择进程2.4打开Modules搜索artPS:小知识Android4.4版本之前系统函数在libdvm.soAndroid5.0之后系统函数在libart.so2.5打开Openmemory()函数在libart.so中搜索Openmemory函数并且跟进去。PS:小知识一般来说,系统dex都会在这个函数中进行加载,但是会出现一个问题,后

1.自动化测试自动化测试主要包括几个部分,UI功能的自动化测试、接口的自动化测试、其他专项的自动化测试。1.1UI功能自动化测试UI功能的自动化测试,也就是大家常说的自动化测试,主要是基于UI界面进行的自动化测试,通过脚本实现UI功能的点击,替代人工进行自动化测试。这个测试的优势在于对高度重复的界面特性功能测试的测试人力进行有效的释放,利用脚本的执行,实现功能的快速高效回归。但这种测试的不足之处也是显而易见的,主要包括维护成本高,易发生误判,兼容性不足等。因为是基于界面操作,界面的稳定程度便成了


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools
