HBASE-18608 AsyncConnection should return AsyncAdmin interface instead of the implemenation
This commit is contained in:
parent
242ccd5881
commit
c606a565c1
|
@ -29,7 +29,7 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
* create a new AsyncAdmin instance.
|
* create a new AsyncAdmin instance.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Public
|
@InterfaceAudience.Public
|
||||||
public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
public interface AsyncAdminBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set timeout for a whole admin operation. Operation timeout and max attempt times(or max retry
|
* Set timeout for a whole admin operation. Operation timeout and max attempt times(or max retry
|
||||||
|
@ -39,7 +39,7 @@ public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
||||||
* @param unit
|
* @param unit
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<T> setOperationTimeout(long timeout, TimeUnit unit);
|
AsyncAdminBuilder setOperationTimeout(long timeout, TimeUnit unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set timeout for each rpc request.
|
* Set timeout for each rpc request.
|
||||||
|
@ -47,7 +47,7 @@ public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
||||||
* @param unit
|
* @param unit
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<T> setRpcTimeout(long timeout, TimeUnit unit);
|
AsyncAdminBuilder setRpcTimeout(long timeout, TimeUnit unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the base pause time for retrying. We use an exponential policy to generate sleep time when
|
* Set the base pause time for retrying. We use an exponential policy to generate sleep time when
|
||||||
|
@ -56,7 +56,7 @@ public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
||||||
* @param unit
|
* @param unit
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<T> setRetryPause(long timeout, TimeUnit unit);
|
AsyncAdminBuilder setRetryPause(long timeout, TimeUnit unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the max retry times for an admin operation. Usually it is the max attempt times minus 1.
|
* Set the max retry times for an admin operation. Usually it is the max attempt times minus 1.
|
||||||
|
@ -65,7 +65,7 @@ public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
||||||
* @param maxRetries
|
* @param maxRetries
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
default AsyncAdminBuilder<T> setMaxRetries(int maxRetries) {
|
default AsyncAdminBuilder setMaxRetries(int maxRetries) {
|
||||||
return setMaxAttempts(retries2Attempts(maxRetries));
|
return setMaxAttempts(retries2Attempts(maxRetries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,18 +76,18 @@ public interface AsyncAdminBuilder<T extends AsyncAdmin> {
|
||||||
* @param maxAttempts
|
* @param maxAttempts
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<T> setMaxAttempts(int maxAttempts);
|
AsyncAdminBuilder setMaxAttempts(int maxAttempts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the number of retries that are allowed before we start to log.
|
* Set the number of retries that are allowed before we start to log.
|
||||||
* @param startLogErrorsCnt
|
* @param startLogErrorsCnt
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<T> setStartLogErrorsCnt(int startLogErrorsCnt);
|
AsyncAdminBuilder setStartLogErrorsCnt(int startLogErrorsCnt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link AsyncAdmin} instance.
|
* Create a {@link AsyncAdmin} instance.
|
||||||
* @return a {@link AsyncAdmin} instance
|
* @return a {@link AsyncAdmin} instance
|
||||||
*/
|
*/
|
||||||
T build();
|
AsyncAdmin build();
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
* Base class for all asynchronous admin builders.
|
* Base class for all asynchronous admin builders.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
abstract class AsyncAdminBuilderBase<T extends AsyncAdmin> implements AsyncAdminBuilder<T> {
|
abstract class AsyncAdminBuilderBase implements AsyncAdminBuilder {
|
||||||
|
|
||||||
protected long rpcTimeoutNs;
|
protected long rpcTimeoutNs;
|
||||||
|
|
||||||
|
@ -46,31 +46,31 @@ abstract class AsyncAdminBuilderBase<T extends AsyncAdmin> implements AsyncAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<T> setOperationTimeout(long timeout, TimeUnit unit) {
|
public AsyncAdminBuilder setOperationTimeout(long timeout, TimeUnit unit) {
|
||||||
this.operationTimeoutNs = unit.toNanos(timeout);
|
this.operationTimeoutNs = unit.toNanos(timeout);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<T> setRpcTimeout(long timeout, TimeUnit unit) {
|
public AsyncAdminBuilder setRpcTimeout(long timeout, TimeUnit unit) {
|
||||||
this.rpcTimeoutNs = unit.toNanos(timeout);
|
this.rpcTimeoutNs = unit.toNanos(timeout);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<T> setRetryPause(long timeout, TimeUnit unit) {
|
public AsyncAdminBuilder setRetryPause(long timeout, TimeUnit unit) {
|
||||||
this.pauseNs = unit.toNanos(timeout);
|
this.pauseNs = unit.toNanos(timeout);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<T> setMaxAttempts(int maxAttempts) {
|
public AsyncAdminBuilder setMaxAttempts(int maxAttempts) {
|
||||||
this.maxAttempts = maxAttempts;
|
this.maxAttempts = maxAttempts;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<T> setStartLogErrorsCnt(int startLogErrorsCnt) {
|
public AsyncAdminBuilder setStartLogErrorsCnt(int startLogErrorsCnt) {
|
||||||
this.startLogErrorsCnt = startLogErrorsCnt;
|
this.startLogErrorsCnt = startLogErrorsCnt;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ public interface AsyncConnection extends Closeable {
|
||||||
* framework's callback thread, so typically you should not do any time consuming work inside
|
* framework's callback thread, so typically you should not do any time consuming work inside
|
||||||
* these methods.
|
* these methods.
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<RawAsyncHBaseAdmin> getAdminBuilder();
|
AsyncAdminBuilder getAdminBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an {@link AsyncAdmin} implementation to administer an HBase cluster.
|
* Retrieve an {@link AsyncAdmin} implementation to administer an HBase cluster.
|
||||||
|
@ -135,5 +135,5 @@ public interface AsyncConnection extends Closeable {
|
||||||
* Returns an {@link AsyncAdminBuilder} for creating {@link AsyncAdmin}.
|
* Returns an {@link AsyncAdminBuilder} for creating {@link AsyncAdmin}.
|
||||||
* @param pool the thread pool to use for executing callback
|
* @param pool the thread pool to use for executing callback
|
||||||
*/
|
*/
|
||||||
AsyncAdminBuilder<AsyncHBaseAdmin> getAdminBuilder(ExecutorService pool);
|
AsyncAdminBuilder getAdminBuilder(ExecutorService pool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,20 +278,20 @@ class AsyncConnectionImpl implements AsyncConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<RawAsyncHBaseAdmin> getAdminBuilder() {
|
public AsyncAdminBuilder getAdminBuilder() {
|
||||||
return new AsyncAdminBuilderBase<RawAsyncHBaseAdmin>(connConf) {
|
return new AsyncAdminBuilderBase(connConf) {
|
||||||
@Override
|
@Override
|
||||||
public RawAsyncHBaseAdmin build() {
|
public AsyncAdmin build() {
|
||||||
return new RawAsyncHBaseAdmin(AsyncConnectionImpl.this, this);
|
return new RawAsyncHBaseAdmin(AsyncConnectionImpl.this, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncAdminBuilder<AsyncHBaseAdmin> getAdminBuilder(ExecutorService pool) {
|
public AsyncAdminBuilder getAdminBuilder(ExecutorService pool) {
|
||||||
return new AsyncAdminBuilderBase<AsyncHBaseAdmin>(connConf) {
|
return new AsyncAdminBuilderBase(connConf) {
|
||||||
@Override
|
@Override
|
||||||
public AsyncHBaseAdmin build() {
|
public AsyncAdmin build() {
|
||||||
RawAsyncHBaseAdmin rawAdmin = new RawAsyncHBaseAdmin(AsyncConnectionImpl.this, this);
|
RawAsyncHBaseAdmin rawAdmin = new RawAsyncHBaseAdmin(AsyncConnectionImpl.this, this);
|
||||||
return new AsyncHBaseAdmin(rawAdmin, pool);
|
return new AsyncHBaseAdmin(rawAdmin, pool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
|
|
||||||
private final NonceGenerator ng;
|
private final NonceGenerator ng;
|
||||||
|
|
||||||
RawAsyncHBaseAdmin(AsyncConnectionImpl connection, AsyncAdminBuilderBase<?> builder) {
|
RawAsyncHBaseAdmin(AsyncConnectionImpl connection, AsyncAdminBuilderBase builder) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.metaTable = connection.getRawTable(META_TABLE_NAME);
|
this.metaTable = connection.getRawTable(META_TABLE_NAME);
|
||||||
this.rpcTimeoutNs = builder.rpcTimeoutNs;
|
this.rpcTimeoutNs = builder.rpcTimeoutNs;
|
||||||
|
|
|
@ -59,13 +59,13 @@ public class TestAsyncAdminBuilder {
|
||||||
private static AsyncConnection ASYNC_CONN;
|
private static AsyncConnection ASYNC_CONN;
|
||||||
|
|
||||||
@Parameter
|
@Parameter
|
||||||
public Supplier<AsyncAdminBuilder<?>> getAdminBuilder;
|
public Supplier<AsyncAdminBuilder> getAdminBuilder;
|
||||||
|
|
||||||
private static AsyncAdminBuilder<RawAsyncHBaseAdmin> getRawAsyncAdminBuilder() {
|
private static AsyncAdminBuilder getRawAsyncAdminBuilder() {
|
||||||
return ASYNC_CONN.getAdminBuilder();
|
return ASYNC_CONN.getAdminBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AsyncAdminBuilder<AsyncHBaseAdmin> getAsyncAdminBuilder() {
|
private static AsyncAdminBuilder getAsyncAdminBuilder() {
|
||||||
return ASYNC_CONN.getAdminBuilder(ForkJoinPool.commonPool());
|
return ASYNC_CONN.getAdminBuilder(ForkJoinPool.commonPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue