All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tarantool.driver.metadata.ProxyTarantoolMetadata Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.metadata;

import io.tarantool.driver.api.TarantoolClient;
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.exceptions.TarantoolClientException;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * Populates metadata from results of a call to proxy API function in Tarantool instance. The function result is
 * expected to have the format which is returned by DDL module.
 * See 
 * https://github.com/tarantool/ddl#input-data-format
 *
 * @author Sergey Volgin
 * @author Alexey Kuzin
 */
public class ProxyTarantoolMetadata extends AbstractTarantoolMetadata {

    private final String getMetadataFunctionName;
    private final TarantoolClient client;
    private final ProxyTarantoolSpaceMetadataConverter metadataConverter;

    public ProxyTarantoolMetadata(String getMetadataFunctionName,
                                  TarantoolClient client) {
        this.getMetadataFunctionName = getMetadataFunctionName;
        this.client = client;
        this.metadataConverter = new ProxyTarantoolSpaceMetadataConverter(client.getConfig().getMessagePackMapper());
    }

    @Override
    public CompletableFuture populateMetadata() throws TarantoolClientException {

        CompletableFuture> callResult = client.call(
                getMetadataFunctionName,
                metadataConverter);

        return callResult.thenAccept(result -> {
            spaceMetadata.clear();
            spaceMetadataById.clear();
            indexMetadata.clear();
            indexMetadataBySpaceId.clear();
            result.forEach(container -> {
                spaceMetadata.putAll(container.getSpaceMetadata());
                indexMetadata.putAll(container.getIndexMetadata());
                container.getSpaceMetadata().forEach((spaceName, spaceMetadata) -> {
                    spaceMetadataById.put(spaceMetadata.getSpaceId(), spaceMetadata);
                    Map indexesForSpace =
                            indexMetadata.get(spaceMetadata.getSpaceName());
                    if (indexesForSpace != null) {
                        indexMetadataBySpaceId.put(spaceMetadata.getSpaceId(), indexesForSpace);
                    }
                });
            });
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy