net.yudichev.jiotty.appliance.ApplianceServerModule Maven / Gradle / Ivy
package net.yudichev.jiotty.appliance;
import com.google.inject.Module;
import net.yudichev.jiotty.common.inject.BaseLifecycleComponentModule;
import net.yudichev.jiotty.common.inject.BindingSpec;
import net.yudichev.jiotty.common.lang.TypedBuilder;
import net.yudichev.jiotty.common.rest.RestServer;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.yudichev.jiotty.common.inject.BindingSpec.boundTo;
public final class ApplianceServerModule extends BaseLifecycleComponentModule {
private final BindingSpec applianceIdSpec;
private final BindingSpec applianceSpec;
private final BindingSpec restServerSpec;
private ApplianceServerModule(BindingSpec applianceIdSpec,
BindingSpec applianceSpec,
BindingSpec restServerSpec) {
this.applianceIdSpec = checkNotNull(applianceIdSpec);
this.applianceSpec = checkNotNull(applianceSpec);
this.restServerSpec = checkNotNull(restServerSpec);
}
public static Builder builder() {
return new Builder();
}
@Override
protected void configure() {
applianceIdSpec.bind(String.class)
.annotatedWith(ApplianceServer.ApplianceId.class)
.installedBy(this::installLifecycleComponentModule);
applianceSpec.bind(Appliance.class)
.annotatedWith(ApplianceServer.Dependency.class)
.installedBy(this::installLifecycleComponentModule);
restServerSpec.bind(RestServer.class)
.annotatedWith(ApplianceServer.Dependency.class)
.installedBy(this::installLifecycleComponentModule);
boundLifecycleComponent(ApplianceServer.class);
}
public static final class Builder implements TypedBuilder {
private BindingSpec applianceIdSpec;
private BindingSpec applianceSpec;
private BindingSpec restServerSpec = boundTo(RestServer.class);
public Builder setApplianceId(BindingSpec applianceIdSpec) {
this.applianceIdSpec = checkNotNull(applianceIdSpec);
return this;
}
public Builder setAppliance(BindingSpec applianceSpec) {
this.applianceSpec = checkNotNull(applianceSpec);
return this;
}
public Builder withRestServer(BindingSpec restServerSpec) {
this.restServerSpec = checkNotNull(restServerSpec);
return this;
}
@Override
public Module build() {
return new ApplianceServerModule(applianceIdSpec, applianceSpec, restServerSpec);
}
}
}