Java client library for Okuyama KVS
- Basic set and get operation
- Compare And Set value updating
- Tagging
- Value compression ability with customizable compression strategy
- Socket pooling with adaptive expansion
- Adaptive value serialization form. Encoding base64 for serializable object.
For detail, see Javadoc
At first, create OkuyamaClientFactory and specify endpoints and pool size. OkuyamaClientFactory can be held through application life time.
String[] endpoints = {"127.0.0.1:8888", "127.0.0.1:8889"};
int poolSize = 10;
OkuyamaClientFactory factory = new OkuyamaClientFactoryImpl(endpoints, poolSize);
// Enable compression with default compression strategy, compress if size of value is over 32 bytes
factory.setCompressionMode(true);
// Or set your own compression strategy
factory.setCompressionStrategy(new YourCompressionStrategy());
When you use client instance, call factory.createClient(). This instance is supposed to retain short time as in function.
OkuyamaClient client = factory.createClient();
互換モードを指定すると、オリジナルのOkuyamaClientからでも読み出し可能な形式で格納するように下の設定でクライアントを生成する。
- キーを必ずbase64エンコードする
- 文字列を格納する場合にもJavaのシリアライズを行ってからBase64エンコードする
- 圧縮しない(圧縮戦略を設定すると例外を発生させる)
public class YourCompressionStrategy implements CompressionStrategy {
private static final int MINIMUM_LENGTH_TO_COMPRESS = 32;
private Compressor compressorDefault;
private Compressor compressorFast;
public YourCompressionStrategy() {
compressorDefault = Compressor.getCompressor(JdkDeflaterCompressor.COMPRESSOR_ID);
compressorFast = Compressor.getCompressor(LZFCompressor.COMPRESSOR_ID);
}
@Override
public Compressor getSuitableCompressor(String key, int valueLength) {
if (valueLength < MINIMUM_LENGTH_TO_COMPRESS) {
return null;
}
if (key.startsWith("session:")) {
return compressorFast;
}
if (key.startsWith("count:")) {
return null;
}
return compressorDefault;
}
}
We need okuyama server for integration testing. For your convinience, I prepare docker images and docker-compose.yml. It is destributed on [mitonize/docker-okuyama] (https://github.com/mitonize/docker-okuyama).
- docker
- docker-machine
- docker-compose
On terminal, run commands below.
$ doker-machine start <your_machine_name>
$ eval $(docker-machine env <your_machine_name>)
$ git clone https://github.com/mitonize/docker-okuyama.git
$ cd docker-okuyama
$ docker-compose up
On another terminal, do maven integration-test with Okuyama endpoints settings as jvm system properties with named "OKUYAMA_ENDPOINTS".
mvn integration-test -DOKUYAMA_ENDPOINTS=$(docker-machine ip):8888