@Test public void test() throws Exception { AsyncClientExample tool = new AsyncClientExample(); tool.setConf(UTIL.getConfiguration()); assertEquals(0, ToolRunner.run(tool, new String[] { TABLE_NAME.getNameAsString() })); } }
CompletableFuture<AsyncConnection> future = getConn(); future.whenComplete((conn, error) -> { if (error != null) { table.put(new Put(getKey(i)).addColumn(FAMILY, QUAL, Bytes.toBytes(i))) .whenComplete((putResp, putErr) -> { if (putErr != null) { table.get(new Get(getKey(i))).whenComplete((result, getErr) -> { if (getErr != null) { LOG.warn("get failed for " + i); }); latch.await(); closeConn().get(); return 0;
private CompletableFuture<AsyncConnection> getConn() { CompletableFuture<AsyncConnection> f = future.get(); if (f != null) { return f; } for (;;) { if (future.compareAndSet(null, new CompletableFuture<>())) { CompletableFuture<AsyncConnection> toComplete = future.get(); ConnectionFactory.createAsyncConnection(getConf()).whenComplete((conn, error) -> { if (error != null) { toComplete.completeExceptionally(error); // we need to reset the future holder so we will get a chance to recreate an async // connection at next try. future.set(null); return; } toComplete.complete(conn); }); return toComplete; } else { f = future.get(); if (f != null) { return f; } } } }
public static void main(String[] args) throws Exception { ToolRunner.run(new AsyncClientExample(), args); } }
public static void main(String[] args) throws Exception { ToolRunner.run(new AsyncClientExample(), args); } }
@Test public void test() throws Exception { AsyncClientExample tool = new AsyncClientExample(); tool.setConf(UTIL.getConfiguration()); assertEquals(0, ToolRunner.run(tool, new String[] { TABLE_NAME.getNameAsString() })); } }
CompletableFuture<AsyncConnection> future = getConn(); future.whenComplete((conn, error) -> { if (error != null) { table.put(new Put(getKey(i)).addColumn(FAMILY, QUAL, Bytes.toBytes(i))) .whenComplete((putResp, putErr) -> { if (putErr != null) { table.get(new Get(getKey(i))).whenComplete((result, getErr) -> { if (getErr != null) { LOG.warn("get failed for " + i); }); latch.await(); closeConn().get(); return 0;
private CompletableFuture<AsyncConnection> getConn() { CompletableFuture<AsyncConnection> f = future.get(); if (f != null) { return f; } for (;;) { if (future.compareAndSet(null, new CompletableFuture<>())) { CompletableFuture<AsyncConnection> toComplete = future.get(); ConnectionFactory.createAsyncConnection(getConf()).whenComplete((conn, error) -> { if (error != null) { toComplete.completeExceptionally(error); // we need to reset the future holder so we will get a chance to recreate an async // connection at next try. future.set(null); return; } toComplete.complete(conn); }); return toComplete; } else { f = future.get(); if (f != null) { return f; } } } }
@Test public void test() throws Exception { AsyncClientExample tool = new AsyncClientExample(); tool.setConf(UTIL.getConfiguration()); assertEquals(0, ToolRunner.run(tool, new String[] { TABLE_NAME.getNameAsString() })); } }