A Java client for Tarantool
Java
Pull request Compare This branch is 98 commits ahead, 1 commit behind dork:master.
Latest commit 53d42e2 Jan 23, 2017 @dgreenru dgreenru committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
src auth fix Jan 23, 2017
.gitignore 1.6 Mar 27, 2015
README.md Update README.md Jan 23, 2017
pom.xml [maven-release-plugin] prepare for next development iteration Jan 23, 2017

README.md

You could get 1.6.9

Java Connector for Tarantool 1.7.2

Join the chat at https://gitter.im/tarantool/tarantool-java

Problems & Questions

http://stackoverflow.com/questions/ask/advice with tags tarantool and java.

Note

Tarantool client is not supports name resolving for fields, indexes, space etc. I highly recommend to use server side lua to operate with named items. For example you could create dao object with simple CRUD functions. If you still need client name resolving for some reasons you could create function which will return required maps with name to id mappings.

How to start

First you should add dependency to your pom file

<dependency>
  <groupId>org.tarantool</groupId>
  <artifactId>connector</artifactId>
  <version>1.7.2</version>
</dependency>

Second configure TarantoolClientConfig.

     TarantoolClientConfig config = new TarantoolClientConfig();
     config.username = "test";
     config.password = "test";

Then implements your SocketChannelProvider. SocketChannelProvider should return connected SocketChannel. Here you also could implement some reconnect or fallback policy. Remember that TarantoolClient uses fail fast policy when client is not connected.

     SocketChannelProvider socketChannelProvider = new SocketChannelProvider() {
                @Override
                public SocketChannel get(int retryNumber, Throwable lastError) {
                    if (lastError != null) {
                        lastError.printStackTrace(System.out);
                    }
                    try {
                        return SocketChannel.open(new InetSocketAddress("localhost", 3301));
                    } catch (IOException e) {
                        throw new IllegalStateException(e);
                    }
                }
            };

Now you are ready to create client

TarantoolClient client = new TarantoolClientImpl(socketChannelProvider, config);

TarantoolClient is thread safe and async so you should use one client inside whole application.

TarantoolClient provides 3 interfaces to execute queries

  • SyncOps returns operation result
  • AsyncOps returns operation result Future
  • FireAndForgetOps returns query ID

Feel free to override any method of TarantoolClientImpl. For example you could override

protected void complete(long code, FutureImpl<List> q);

to hook all results.