com.netflix.karyon.transport.tcp.KaryonTcpModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karyon-governator Show documentation
Show all versions of karyon-governator Show documentation
karyon-governator developed by Netflix
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);
}
}