com.netflix.karyon.transport.AbstractServerModule 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;
import com.google.inject.AbstractModule;
import com.google.inject.Key;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.netflix.karyon.transport.AbstractServerModule.ServerConfigBuilder;
import io.reactivex.netty.metrics.MetricEventsListenerFactory;
import io.reactivex.netty.pipeline.PipelineConfigurator;
/**
* @author Tomasz Bak
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractServerModule extends AbstractModule {
protected final Named nameAnnotation;
protected final Class iType;
protected final Class oType;
protected final Key pipelineConfiguratorKey;
protected final Key metricEventsListenerFactoryKey;
protected final Key serverConfigKey;
protected final B serverConfigBuilder;
protected AbstractServerModule(String moduleName, Class iType, Class oType) {
nameAnnotation = Names.named(moduleName);
this.iType = iType;
this.oType = oType;
pipelineConfiguratorKey = Key.get(PipelineConfigurator.class, nameAnnotation);
metricEventsListenerFactoryKey = Key.get(MetricEventsListenerFactory.class, nameAnnotation);
serverConfigKey = Key.get(ServerConfig.class, nameAnnotation);
serverConfigBuilder = newServerConfigBuilder();
}
protected abstract void configureServer();
protected abstract B newServerConfigBuilder();
protected LinkedBindingBuilder bindPipelineConfigurator() {
return bind(pipelineConfiguratorKey);
}
protected LinkedBindingBuilder bindEventsListenerFactory() {
return bind(metricEventsListenerFactoryKey);
}
protected B server() {
return serverConfigBuilder;
}
public static class ServerConfig {
private final int port;
public ServerConfig(int port) {
this.port = port;
}
public int getPort() {
return port;
}
}
@SuppressWarnings("unchecked")
public static class ServerConfigBuilder {
protected int port = 8080;
public B port(int port) {
this.port = port;
return (B) this;
}
public C build() {
return (C) new ServerConfig(port);
}
}
}