hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raghavendhra rahul <raghavendhrara...@gmail.com>
Subject Re: Coprocessor execution
Date Wed, 21 Mar 2012 08:48:38 GMT
This is my coprocessor end point

public class RowcountEndpoint extends BaseEndpointCoprocessor implements
        RowcountProtocol {

    @Override
    public long getRowcount() throws IOException {
        Scan scan = new Scan();
        scan.setCaching(100);
        scan.setCacheBlocks(false);
        RegionCoprocessorEnvironment env =
(RegionCoprocessorEnvironment)getEnvironment();
        InternalScanner scanner = env.getRegion().getScanner(scan);
        long result = 0;
        try{
            List<KeyValue> val = new ArrayList<KeyValue>();
            boolean done = false;
            do{
                val.clear();
                done = scanner.next(val);
                result+=1;
            }while(done);
        }
        finally{
            scanner.close();
        }
        return result;
    }
}


This is my client

public class RowClient {
    public Map<byte[], Long> getcount(String name) throws Throwable {

        Configuration conf = HBaseConfiguration.create();
        HTable table = new HTable(conf, name);
        Map<byte[], Long> res;
        try {
            res = table.coprocessorExec(RowcountProtocol.class, null, null,
                    new Batch.Call<RowcountProtocol, Long>() {
                        @Override
                        public Long call(RowcountProtocol counter)
                                throws IOException {
                            return counter.getRowcount();
                        }
                    });
        } finally {

        }
        return res;
    }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message