@ThreadSafe public abstract class AbstractClient extends Object implements Client
Modifier and Type | Class and Description |
---|---|
protected static interface |
AbstractClient.RpcCallable<V>
The RPC to be executed in
retryRPC(RpcCallable) . |
Modifier and Type | Field and Description |
---|---|
protected InetSocketAddress |
mAddress |
protected GrpcChannel |
mChannel
Underlying channel to the target service.
|
protected boolean |
mClosed
Is true if this client was closed by the user.
|
protected InetSocketAddress |
mConfAddress
Address to load configuration, which may differ from
mAddress . |
protected boolean |
mConnected
Is true if this client is currently connected.
|
protected ClientContext |
mContext |
protected long |
mServiceVersion
Stores the service version; used for detecting incompatible client-server pairs.
|
protected ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub |
mVersionService
Used to query service version for the remote service type.
|
Constructor and Description |
---|
AbstractClient(ClientContext context,
InetSocketAddress address)
Creates a new client base.
|
AbstractClient(ClientContext context,
InetSocketAddress address,
java.util.function.Supplier<RetryPolicy> retryPolicySupplier)
Creates a new client base.
|
Modifier and Type | Method and Description |
---|---|
protected void |
afterConnect()
This method is called after the connection is made to the remote.
|
protected void |
afterDisconnect()
This method is called after the connection is disconnected.
|
protected void |
beforeConnect()
This method is called before the connection is connected.
|
protected void |
beforeDisconnect()
This method is called before the connection is disconnected.
|
protected void |
checkVersion(long clientVersion)
Checks that the service version is compatible with the client.
|
void |
close()
Closes the connection with the remote permanently.
|
void |
connect()
Connects with the remote.
|
void |
disconnect()
Closes the connection with the Alluxio remote and does the necessary cleanup.
|
InetSocketAddress |
getAddress() |
InetSocketAddress |
getConfAddress() |
protected abstract ServiceType |
getRemoteServiceType() |
protected long |
getRemoteServiceVersion() |
protected abstract String |
getServiceName() |
protected abstract long |
getServiceVersion() |
boolean |
isClosed() |
boolean |
isConnected()
Returns the connected status of the client.
|
protected <V> V |
retryRPC(AbstractClient.RpcCallable<V> rpc)
Tries to execute an RPC defined as a
AbstractClient.RpcCallable . |
protected <V> V |
retryRPC(AbstractClient.RpcCallable<V> rpc,
String rpcName)
Tries to execute an RPC defined as a
AbstractClient.RpcCallable . |
protected InetSocketAddress mAddress
protected InetSocketAddress mConfAddress
mAddress
.protected GrpcChannel mChannel
protected ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub mVersionService
protected boolean mConnected
protected volatile boolean mClosed
protected long mServiceVersion
protected ClientContext mContext
public AbstractClient(ClientContext context, InetSocketAddress address)
context
- information required to connect to Alluxioaddress
- the addresspublic AbstractClient(ClientContext context, InetSocketAddress address, java.util.function.Supplier<RetryPolicy> retryPolicySupplier)
context
- information required to connect to Alluxioaddress
- the addressretryPolicySupplier
- factory for retry policies to be used when performing RPCsprotected abstract ServiceType getRemoteServiceType()
protected long getRemoteServiceVersion() throws AlluxioStatusException
AlluxioStatusException
protected abstract String getServiceName()
protected abstract long getServiceVersion()
protected void checkVersion(long clientVersion) throws IOException
clientVersion
- the client versionIOException
protected void afterConnect() throws IOException
IOException
protected void beforeConnect() throws IOException
IOException
protected void afterDisconnect()
protected void beforeDisconnect()
public void connect() throws AlluxioStatusException
connect
in interface Client
AlluxioStatusException
public void disconnect()
disconnect
in interface Client
public boolean isConnected()
Client
isConnected
in interface Client
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public InetSocketAddress getAddress() throws UnavailableException
getAddress
in interface Client
InetSocketAddress
of the remoteUnavailableException
- if the primary address cannot be determinedpublic InetSocketAddress getConfAddress() throws UnavailableException
getConfAddress
in interface Client
InetSocketAddress
of the configuration remoteUnavailableException
- if the primary address cannot be determinedprotected <V> V retryRPC(AbstractClient.RpcCallable<V> rpc) throws AlluxioStatusException
AbstractClient.RpcCallable
.
If a UnavailableException
occurs, a reconnection will be tried through
connect()
and the action will be re-executed.V
- type of return value of the RPC callrpc
- the RPC call to be executedAlluxioStatusException
protected <V> V retryRPC(AbstractClient.RpcCallable<V> rpc, String rpcName) throws AlluxioStatusException
AbstractClient.RpcCallable
. Metrics will be recorded based on
the provided rpc name.
If a UnavailableException
occurs, a reconnection will be tried through
connect()
and the action will be re-executed.V
- type of return value of the RPC callrpc
- the RPC call to be executedrpcName
- the human readable name of the RPC callAlluxioStatusException
Copyright © 2023. All Rights Reserved.