public boolean nextKeyValue() { while (tapclient.hasMoreMessages()) { lastmessage = tapclient.getNextMessage(10, TimeUnit.SECONDS); if (lastmessage != null) { return true; } } return false; }
@Override public float getProgress() { if (!tapclient.hasMoreMessages()) { return 1; } return 0; }
public void initialize(InputSplit isplit, JobConf conf) throws IOException { final URI ClusterURI; try { ClusterURI = new URI(conf.get(CouchbaseConfig.CB_INPUT_CLUSTER)); } catch (URISyntaxException e) { throw new IOException(e); } final List<URI> ClientURIList = new ArrayList<URI>(); ClientURIList.add(ClusterURI.resolve("/pools")); final String bucket = conf.get(CouchbaseConfig.CB_INPUT_BUCKET, "default"); final String password = conf.get(CouchbaseConfig.CB_INPUT_PASSWORD, ""); RequestMessage tapReq = new RequestMessage(); tapReq.setMagic(TapMagic.PROTOCOL_BINARY_REQ); tapReq.setOpcode(TapOpcode.REQUEST); tapReq.setFlags(TapRequestFlag.DUMP); tapReq.setFlags(TapRequestFlag.SUPPORT_ACK); tapReq.setFlags(TapRequestFlag.FIX_BYTEORDER); tapReq.setFlags(TapRequestFlag.LIST_VBUCKETS); final CouchbaseSplit split = (CouchbaseSplit) isplit; short[] vbids = new short[split.vbuckets.size()]; int i = 0; for (Integer vbnum : split.vbuckets) { vbids[i] = vbnum.shortValue(); i++; } final String namebase = conf.get(CouchbaseConfig.CB_INPUT_STREAM_NAME, "hadoop"); tapReq.setVbucketlist(vbids); final String streamName = namebase + "_" + uuid.toString(); tapReq.setName(streamName); tapclient = new TapClient(ClientURIList, bucket, password); try { tapclient.tapCustom(streamName, tapReq); } catch (ConfigurationException e) { throw new IOException(e); } }
@Override public void close() throws IOException { tapclient.shutdown(); }