
org.glowroot.ui.CreateUiModuleBuilder Maven / Gradle / Ivy
package org.glowroot.ui;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.base.Ticker;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import java.io.File;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;
import org.glowroot.common.config.PluginDescriptor;
import org.glowroot.common.live.LiveAggregateRepository;
import org.glowroot.common.live.LiveJvmService;
import org.glowroot.common.live.LiveTraceRepository;
import org.glowroot.common.live.LiveWeavingService;
import org.glowroot.common.util.Clock;
import org.glowroot.storage.repo.AggregateRepository;
import org.glowroot.storage.repo.ConfigRepository;
import org.glowroot.storage.repo.GaugeValueRepository;
import org.glowroot.storage.repo.RepoAdmin;
import org.glowroot.storage.repo.TraceRepository;
import org.glowroot.storage.repo.TransactionTypeRepository;
/**
* {@code CreateUiModuleBuilder} collects parameters and invokes static factory method:
* {@code org.glowroot.ui.UiModule.createUiModule(..)}.
* Call {@link #build()} method to get result of type {@code org.glowroot.ui.UiModule}.
* {@code CreateUiModuleBuilder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "UiModule.createUiModule"})
@NotThreadSafe
public final class CreateUiModuleBuilder {
private static final long INIT_BIT_CENTRAL = 0x1L;
private static final long INIT_BIT_TICKER = 0x2L;
private static final long INIT_BIT_CLOCK = 0x4L;
private static final long INIT_BIT_CONFIG_REPOSITORY = 0x8L;
private static final long INIT_BIT_TRANSACTION_TYPE_REPOSITORY = 0x10L;
private static final long INIT_BIT_TRACE_REPOSITORY = 0x20L;
private static final long INIT_BIT_AGGREGATE_REPOSITORY = 0x40L;
private static final long INIT_BIT_GAUGE_VALUE_REPOSITORY = 0x80L;
private static final long INIT_BIT_REPO_ADMIN = 0x100L;
private static final long INIT_BIT_LIVE_TRACE_REPOSITORY = 0x200L;
private static final long INIT_BIT_LIVE_AGGREGATE_REPOSITORY = 0x400L;
private static final long INIT_BIT_VIEWER_MODE = 0x800L;
private static final long INIT_BIT_BIND_ADDRESS = 0x1000L;
private static final long INIT_BIT_VERSION = 0x2000L;
private long initBits = 0x3fff;
private boolean central;
private @Nullable Ticker ticker;
private @Nullable Clock clock;
private @Nullable File logDir;
private @Nullable LiveJvmService liveJvmService;
private @Nullable ConfigRepository configRepository;
private @Nullable TransactionTypeRepository transactionTypeRepository;
private @Nullable TraceRepository traceRepository;
private @Nullable AggregateRepository aggregateRepository;
private @Nullable GaugeValueRepository gaugeValueRepository;
private @Nullable RepoAdmin repoAdmin;
private @Nullable LiveTraceRepository liveTraceRepository;
private @Nullable LiveAggregateRepository liveAggregateRepository;
private @Nullable LiveWeavingService liveWeavingService;
private boolean viewerMode;
private @Nullable String bindAddress;
private @Nullable String version;
private ImmutableList.Builder pluginDescriptorsBuilder = ImmutableList.builder();
/**
* Constructs {@code CreateUiModuleBuilder} factory builder.
*/
public CreateUiModuleBuilder() {
}
/**
* Initializes value for {@code central}.
* @param central value for central
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder central(boolean central) {
this.central = central;
initBits &= ~INIT_BIT_CENTRAL;
return this;
}
/**
* Initializes value for {@code ticker}.
* @param ticker value for ticker
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder ticker(Ticker ticker) {
this.ticker = Preconditions.checkNotNull(ticker);
initBits &= ~INIT_BIT_TICKER;
return this;
}
/**
* Initializes value for {@code clock}.
* @param clock value for clock
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder clock(Clock clock) {
this.clock = Preconditions.checkNotNull(clock);
initBits &= ~INIT_BIT_CLOCK;
return this;
}
/**
* Initializes value for {@code logDir}.
* @param logDir value for logDir, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder logDir(@Nullable File logDir) {
this.logDir = logDir;
return this;
}
/**
* Initializes value for {@code liveJvmService}.
* @param liveJvmService value for liveJvmService, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder liveJvmService(@Nullable LiveJvmService liveJvmService) {
this.liveJvmService = liveJvmService;
return this;
}
/**
* Initializes value for {@code configRepository}.
* @param configRepository value for configRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder configRepository(ConfigRepository configRepository) {
this.configRepository = Preconditions.checkNotNull(configRepository);
initBits &= ~INIT_BIT_CONFIG_REPOSITORY;
return this;
}
/**
* Initializes value for {@code transactionTypeRepository}.
* @param transactionTypeRepository value for transactionTypeRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder transactionTypeRepository(TransactionTypeRepository transactionTypeRepository) {
this.transactionTypeRepository = Preconditions.checkNotNull(transactionTypeRepository);
initBits &= ~INIT_BIT_TRANSACTION_TYPE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code traceRepository}.
* @param traceRepository value for traceRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder traceRepository(TraceRepository traceRepository) {
this.traceRepository = Preconditions.checkNotNull(traceRepository);
initBits &= ~INIT_BIT_TRACE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code aggregateRepository}.
* @param aggregateRepository value for aggregateRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder aggregateRepository(AggregateRepository aggregateRepository) {
this.aggregateRepository = Preconditions.checkNotNull(aggregateRepository);
initBits &= ~INIT_BIT_AGGREGATE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code gaugeValueRepository}.
* @param gaugeValueRepository value for gaugeValueRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder gaugeValueRepository(GaugeValueRepository gaugeValueRepository) {
this.gaugeValueRepository = Preconditions.checkNotNull(gaugeValueRepository);
initBits &= ~INIT_BIT_GAUGE_VALUE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code repoAdmin}.
* @param repoAdmin value for repoAdmin
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder repoAdmin(RepoAdmin repoAdmin) {
this.repoAdmin = Preconditions.checkNotNull(repoAdmin);
initBits &= ~INIT_BIT_REPO_ADMIN;
return this;
}
/**
* Initializes value for {@code liveTraceRepository}.
* @param liveTraceRepository value for liveTraceRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder liveTraceRepository(LiveTraceRepository liveTraceRepository) {
this.liveTraceRepository = Preconditions.checkNotNull(liveTraceRepository);
initBits &= ~INIT_BIT_LIVE_TRACE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code liveAggregateRepository}.
* @param liveAggregateRepository value for liveAggregateRepository
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder liveAggregateRepository(LiveAggregateRepository liveAggregateRepository) {
this.liveAggregateRepository = Preconditions.checkNotNull(liveAggregateRepository);
initBits &= ~INIT_BIT_LIVE_AGGREGATE_REPOSITORY;
return this;
}
/**
* Initializes value for {@code liveWeavingService}.
* @param liveWeavingService value for liveWeavingService, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder liveWeavingService(@Nullable LiveWeavingService liveWeavingService) {
this.liveWeavingService = liveWeavingService;
return this;
}
/**
* Initializes value for {@code viewerMode}.
* @param viewerMode value for viewerMode
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder viewerMode(boolean viewerMode) {
this.viewerMode = viewerMode;
initBits &= ~INIT_BIT_VIEWER_MODE;
return this;
}
/**
* Initializes value for {@code bindAddress}.
* @param bindAddress value for bindAddress
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder bindAddress(String bindAddress) {
this.bindAddress = Preconditions.checkNotNull(bindAddress);
initBits &= ~INIT_BIT_BIND_ADDRESS;
return this;
}
/**
* Initializes value for {@code version}.
* @param version value for version
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder version(String version) {
this.version = Preconditions.checkNotNull(version);
initBits &= ~INIT_BIT_VERSION;
return this;
}
/**
* Adds one element to {@code pluginDescriptors} list.
* @param element pluginDescriptors element
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder addPluginDescriptors(PluginDescriptor element) {
pluginDescriptorsBuilder.add(element);
return this;
}
/**
* Adds elements to {@code pluginDescriptors} list.
* @param elements array of pluginDescriptors elements
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder addPluginDescriptors(PluginDescriptor... elements) {
pluginDescriptorsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@code pluginDescriptors} list.
* @param elements iterable of pluginDescriptors elements
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder pluginDescriptors(Iterable extends PluginDescriptor> elements) {
pluginDescriptorsBuilder = ImmutableList.builder();
return addAllPluginDescriptors(elements);
}
/**
* Adds elements to {@code pluginDescriptors} list.
* @param elements iterable of pluginDescriptors elements
* @return {@code this} builder for chained invocation
*/
public final CreateUiModuleBuilder addAllPluginDescriptors(Iterable extends PluginDescriptor> elements) {
pluginDescriptorsBuilder.addAll(elements);
return this;
}
/**
* Invokes {@code org.glowroot.ui.UiModule.createUiModule(..)} using collected parameters and returning it's result
* @return result of type {@code org.glowroot.ui.UiModule}
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public UiModule build()
throws IllegalStateException, Exception {
checkRequiredAttributes();
return UiModule.createUiModule(central,
ticker,
clock,
logDir,
liveJvmService,
configRepository,
transactionTypeRepository,
traceRepository,
aggregateRepository,
gaugeValueRepository,
repoAdmin,
liveTraceRepository,
liveAggregateRepository,
liveWeavingService,
viewerMode,
bindAddress,
version,
pluginDescriptorsBuilder.build());
}
private boolean centralIsSet() {
return (initBits & INIT_BIT_CENTRAL) == 0;
}
private boolean tickerIsSet() {
return (initBits & INIT_BIT_TICKER) == 0;
}
private boolean clockIsSet() {
return (initBits & INIT_BIT_CLOCK) == 0;
}
private boolean configRepositoryIsSet() {
return (initBits & INIT_BIT_CONFIG_REPOSITORY) == 0;
}
private boolean transactionTypeRepositoryIsSet() {
return (initBits & INIT_BIT_TRANSACTION_TYPE_REPOSITORY) == 0;
}
private boolean traceRepositoryIsSet() {
return (initBits & INIT_BIT_TRACE_REPOSITORY) == 0;
}
private boolean aggregateRepositoryIsSet() {
return (initBits & INIT_BIT_AGGREGATE_REPOSITORY) == 0;
}
private boolean gaugeValueRepositoryIsSet() {
return (initBits & INIT_BIT_GAUGE_VALUE_REPOSITORY) == 0;
}
private boolean repoAdminIsSet() {
return (initBits & INIT_BIT_REPO_ADMIN) == 0;
}
private boolean liveTraceRepositoryIsSet() {
return (initBits & INIT_BIT_LIVE_TRACE_REPOSITORY) == 0;
}
private boolean liveAggregateRepositoryIsSet() {
return (initBits & INIT_BIT_LIVE_AGGREGATE_REPOSITORY) == 0;
}
private boolean viewerModeIsSet() {
return (initBits & INIT_BIT_VIEWER_MODE) == 0;
}
private boolean bindAddressIsSet() {
return (initBits & INIT_BIT_BIND_ADDRESS) == 0;
}
private boolean versionIsSet() {
return (initBits & INIT_BIT_VERSION) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!centralIsSet()) attributes.add("central");
if (!tickerIsSet()) attributes.add("ticker");
if (!clockIsSet()) attributes.add("clock");
if (!configRepositoryIsSet()) attributes.add("configRepository");
if (!transactionTypeRepositoryIsSet()) attributes.add("transactionTypeRepository");
if (!traceRepositoryIsSet()) attributes.add("traceRepository");
if (!aggregateRepositoryIsSet()) attributes.add("aggregateRepository");
if (!gaugeValueRepositoryIsSet()) attributes.add("gaugeValueRepository");
if (!repoAdminIsSet()) attributes.add("repoAdmin");
if (!liveTraceRepositoryIsSet()) attributes.add("liveTraceRepository");
if (!liveAggregateRepositoryIsSet()) attributes.add("liveAggregateRepository");
if (!viewerModeIsSet()) attributes.add("viewerMode");
if (!bindAddressIsSet()) attributes.add("bindAddress");
if (!versionIsSet()) attributes.add("version");
return "Cannot build createUiModule, some of required attributes are not set " + attributes;
}
}