public class KvStateClient extends Object
KvStateServer
instances.
This client can be used by multiple threads concurrently. Operations are executed asynchronously and return Futures to their result.
The incoming pipeline looks as follows:
Socket.read() -> LengthFieldBasedFrameDecoder -> KvStateServerHandler
Received binary messages are expected to contain a frame length field. Netty's
LengthFieldBasedFrameDecoder
is used to fully receive the frame before
giving it to our KvStateClientHandler
.
Connections are established and closed by the client. The server only closes the connection on a fatal failure that cannot be recovered.
Constructor and Description |
---|
KvStateClient(int numEventLoopThreads,
KvStateRequestStats stats)
Creates a client with the specified number of event loop threads.
|
Modifier and Type | Method and Description |
---|---|
void |
closeConnection(KvStateServerAddress serverAddress)
Closes the connection to the given server address if it exists.
|
scala.concurrent.Future<byte[]> |
getKvState(KvStateServerAddress serverAddress,
KvStateID kvStateId,
byte[] serializedKeyAndNamespace)
Returns a future holding the serialized request result.
|
void |
shutDown()
Shuts down the client and closes all connections.
|
public KvStateClient(int numEventLoopThreads, KvStateRequestStats stats)
numEventLoopThreads
- Number of event loop threads (minimum 1).public scala.concurrent.Future<byte[]> getKvState(KvStateServerAddress serverAddress, KvStateID kvStateId, byte[] serializedKeyAndNamespace)
If the server does not serve a KvState instance with the given ID,
the Future will be failed with a UnknownKvStateID
.
If the KvState instance does not hold any data for the given key
and namespace, the Future will be failed with a UnknownKeyOrNamespace
.
All other failures are forwarded to the Future.
serverAddress
- Address of the server to querykvStateId
- ID of the KvState instance to queryserializedKeyAndNamespace
- Serialized key and namespace to query KvState instance withpublic void shutDown()
After a call to this method, all returned futures will be failed.
public void closeConnection(KvStateServerAddress serverAddress)
If there is a request to the server a new connection will be established.
serverAddress
- Target address of the connection to closeCopyright © 2014–2018 The Apache Software Foundation. All rights reserved.