Java client library for Okuyama KVS

Yet another client Java library connecting to Okuyama, a key-value storage middle ware.

License

License

Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

com.github.mitonize
ArtifactId

ArtifactId

okuyama-client-java
Last Version

Last Version

1.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

Java client library for Okuyama KVS
Yet another client Java library connecting to Okuyama, a key-value storage middle ware.
Project URL

Project URL

https://github.com/mitonize/okuyama-client-java
Source Code Management

Source Code Management

https://github.com/mitonize/okuyama-client-java

Download okuyama-client-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mitonize/okuyama-client-java/ -->
<dependency>
    <groupId>com.github.mitonize</groupId>
    <artifactId>okuyama-client-java</artifactId>
    <version>1.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mitonize/okuyama-client-java/
implementation 'com.github.mitonize:okuyama-client-java:1.1.3'
// https://jarcasting.com/artifacts/com.github.mitonize/okuyama-client-java/
implementation ("com.github.mitonize:okuyama-client-java:1.1.3")
'com.github.mitonize:okuyama-client-java:jar:1.1.3'
<dependency org="com.github.mitonize" name="okuyama-client-java" rev="1.1.3">
  <artifact name="okuyama-client-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mitonize', module='okuyama-client-java', version='1.1.3')
)
libraryDependencies += "com.github.mitonize" % "okuyama-client-java" % "1.1.3"
[com.github.mitonize/okuyama-client-java "1.1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.slf4j : slf4j-log4j12 jar 1.7.5
com.ning : compress-lzf jar 1.0.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

okuyama-client-java

Java client library for Okuyama KVS

Feature

  • 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.

Usage

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();

Compatibility

互換モードを指定すると、オリジナルのOkuyamaClientからでも読み出し可能な形式で格納するように下の設定でクライアントを生成する。

  • キーを必ずbase64エンコードする
  • 文字列を格納する場合にもJavaのシリアライズを行ってからBase64エンコードする
  • 圧縮しない(圧縮戦略を設定すると例外を発生させる)

Compression

Implementing CompressionStrategy

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;
	}
}

Integration testing

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).

Prerequisites

  • docker
  • docker-machine
  • docker-compose

Procedure

start docker machine

On terminal, run commands below.

$ doker-machine start <your_machine_name>
$ eval $(docker-machine env <your_machine_name>)

start okuyama in docker container

$ git clone https://github.com/mitonize/docker-okuyama.git
$ cd docker-okuyama
$ docker-compose up

run integration tests

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

Versions

Version
1.1.3