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

com.netflix.karyon.transport.tcp.KaryonTcpModule Maven / Gradle / Ivy

There is a newer version: 2.1.00-RC6
Show newest version
package com.netflix.karyon.transport.tcp;

import com.google.inject.Key;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.multibindings.MapBinder;
import com.netflix.karyon.transport.AbstractServerModule;
import com.netflix.karyon.transport.AbstractServerModule.ServerConfigBuilder;
import io.reactivex.netty.channel.ConnectionHandler;
import io.reactivex.netty.server.RxServer;

import static com.netflix.karyon.utils.TypeUtils.*;

/**
 * @author Tomasz Bak
 */
@SuppressWarnings("rawtypes")
public abstract class KaryonTcpModule extends AbstractServerModule {

    protected final Key> connectionHandlerKey;
    protected final Key> serverKey;


    protected KaryonTcpModule(String moduleName, Class iType, Class oType) {
        super(moduleName, iType, oType);
        connectionHandlerKey = keyFor(ConnectionHandler.class, iType, oType, nameAnnotation);
        serverKey = keyFor(RxServer.class, iType, oType, nameAnnotation);
    }

    @Override
    protected void configure() {
        configureServer();
        bind(serverConfigKey).toInstance(serverConfigBuilder.build());
        MapBinder.newMapBinder(binder(), String.class, RxServer.class).addBinding(nameAnnotation.value()).toProvider(
                new TcpRxServerProvider>(nameAnnotation.value(), iType, oType)
        ).asEagerSingleton();
    }

    @Override
    protected ServerConfigBuilder newServerConfigBuilder() {
        return new ServerConfigBuilder();
    }

    public LinkedBindingBuilder> bindConnectionHandler() {
        return bind(connectionHandlerKey);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy