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

io.mstream.trader.commons.config.ConfigModule Maven / Gradle / Ivy

package io.mstream.trader.commons.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;

import java.util.concurrent.ScheduledExecutorService;

import static com.google.inject.Scopes.SINGLETON;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;


public class ConfigModule extends AbstractModule {

    private final TypeLiteral configTypeLiteral;
    private final String appName;
    private final String zkConnectionString;

    public ConfigModule(
            Class configType,
            String appName,
            String zkConnectionString
    ) {
        configTypeLiteral = TypeLiteral.get(configType);
        this.appName = appName;
        this.zkConnectionString = zkConnectionString;
    }

    @Override
    protected void configure() {

        binder().requireExplicitBindings();

        bind(String.class)
                .annotatedWith(ApplicationName.class)
                .toInstance(appName);

        bind(Version.class)
                .annotatedWith(Application.class)
                .toProvider(ApplicationVersionProvider.class)
                .in(SINGLETON);

        bind(CuratorFrameworkSupplier.class)
                .in(SINGLETON);

        bind(ObjectMapper.class)
                .toInstance(new ObjectMapper());

        bind(String.class)
                .annotatedWith(ConnectionString.class)
                .toInstance(zkConnectionString);

        bind(ScheduledExecutorService.class)
                .toInstance(newSingleThreadScheduledExecutor());

        bind(ConfigClient.class)
                .in(SINGLETON);

        bind(Class.class)
                .annotatedWith(Config.class)
                .toInstance(configTypeLiteral.getRawType());

        bind(ConfigSupplier.class)
                .in(SINGLETON);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy