@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 boolean |
mClosed
Is true if this client was closed by the user.
|
protected boolean |
mConnected
Is true if this client is currently connected.
|
protected org.apache.thrift.protocol.TProtocol |
mProtocol |
protected long |
mServiceVersion
Stores the service version; used for detecting incompatible client-server pairs.
|
Constructor and Description |
---|
AbstractClient(Subject subject,
InetSocketAddress address)
Creates a new client base.
|
AbstractClient(Subject subject,
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 |
beforeDisconnect()
This method is called before the connection is disconnected.
|
protected void |
checkVersion(AlluxioService.Client client,
long version)
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() |
protected abstract AlluxioService.Client |
getClient() |
protected abstract String |
getServiceName() |
protected abstract long |
getServiceVersion() |
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 org.apache.thrift.protocol.TProtocol mProtocol
protected boolean mConnected
protected volatile boolean mClosed
protected long mServiceVersion
public AbstractClient(Subject subject, InetSocketAddress address)
subject
- the parent subject, set to null if not presentaddress
- the addresspublic AbstractClient(Subject subject, InetSocketAddress address, java.util.function.Supplier<RetryPolicy> retryPolicySupplier)
subject
- the parent subject, set to null if not presentaddress
- the addressretryPolicySupplier
- factory for retry policies to be used when performing RPCsprotected abstract AlluxioService.Client getClient()
protected abstract String getServiceName()
protected abstract long getServiceVersion()
protected void checkVersion(AlluxioService.Client client, long version) throws IOException
client
- the service clientversion
- the client versionIOException
protected void afterConnect() 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 remote,UnavailableException
- 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.