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

org.glowroot.central.ImmutableAgentResult Maven / Gradle / Ivy

package org.glowroot.central;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link DownstreamServiceImpl.AgentResult}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableAgentResult.builder()}. */ @Generated(from = "DownstreamServiceImpl.AgentResult", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutableAgentResult implements DownstreamServiceImpl.AgentResult { private final Optional value; private final boolean timeout; private final boolean interrupted; private final boolean shuttingDown; private ImmutableAgentResult(ImmutableAgentResult.Builder builder) { this.value = builder.value; if (builder.timeoutIsSet()) { initShim.timeout(builder.timeout); } if (builder.interruptedIsSet()) { initShim.interrupted(builder.interrupted); } if (builder.shuttingDownIsSet()) { initShim.shuttingDown(builder.shuttingDown); } this.timeout = initShim.timeout(); this.interrupted = initShim.interrupted(); this.shuttingDown = initShim.shuttingDown(); this.initShim = null; } private ImmutableAgentResult( Optional value, boolean timeout, boolean interrupted, boolean shuttingDown) { this.value = value; this.timeout = timeout; this.interrupted = interrupted; this.shuttingDown = shuttingDown; this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; @SuppressWarnings("Immutable") private transient volatile InitShim initShim = new InitShim(); @Generated(from = "DownstreamServiceImpl.AgentResult", generator = "Immutables") private final class InitShim { private byte timeoutBuildStage = STAGE_UNINITIALIZED; private boolean timeout; boolean timeout() { if (timeoutBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (timeoutBuildStage == STAGE_UNINITIALIZED) { timeoutBuildStage = STAGE_INITIALIZING; this.timeout = timeoutInitialize(); timeoutBuildStage = STAGE_INITIALIZED; } return this.timeout; } void timeout(boolean timeout) { this.timeout = timeout; timeoutBuildStage = STAGE_INITIALIZED; } private byte interruptedBuildStage = STAGE_UNINITIALIZED; private boolean interrupted; boolean interrupted() { if (interruptedBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (interruptedBuildStage == STAGE_UNINITIALIZED) { interruptedBuildStage = STAGE_INITIALIZING; this.interrupted = interruptedInitialize(); interruptedBuildStage = STAGE_INITIALIZED; } return this.interrupted; } void interrupted(boolean interrupted) { this.interrupted = interrupted; interruptedBuildStage = STAGE_INITIALIZED; } private byte shuttingDownBuildStage = STAGE_UNINITIALIZED; private boolean shuttingDown; boolean shuttingDown() { if (shuttingDownBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (shuttingDownBuildStage == STAGE_UNINITIALIZED) { shuttingDownBuildStage = STAGE_INITIALIZING; this.shuttingDown = shuttingDownInitialize(); shuttingDownBuildStage = STAGE_INITIALIZED; } return this.shuttingDown; } void shuttingDown(boolean shuttingDown) { this.shuttingDown = shuttingDown; shuttingDownBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (timeoutBuildStage == STAGE_INITIALIZING) attributes.add("timeout"); if (interruptedBuildStage == STAGE_INITIALIZING) attributes.add("interrupted"); if (shuttingDownBuildStage == STAGE_INITIALIZING) attributes.add("shuttingDown"); return "Cannot build AgentResult, attribute initializers form cycle " + attributes; } } private boolean timeoutInitialize() { return DownstreamServiceImpl.AgentResult.super.timeout(); } private boolean interruptedInitialize() { return DownstreamServiceImpl.AgentResult.super.interrupted(); } private boolean shuttingDownInitialize() { return DownstreamServiceImpl.AgentResult.super.shuttingDown(); } /** * @return The value of the {@code value} attribute */ @JsonProperty("value") @Override public Optional value() { return value; } /** * @return The value of the {@code timeout} attribute */ @JsonProperty("timeout") @Override public boolean timeout() { InitShim shim = this.initShim; return shim != null ? shim.timeout() : this.timeout; } /** * @return The value of the {@code interrupted} attribute */ @JsonProperty("interrupted") @Override public boolean interrupted() { InitShim shim = this.initShim; return shim != null ? shim.interrupted() : this.interrupted; } /** * @return The value of the {@code shuttingDown} attribute */ @JsonProperty("shuttingDown") @Override public boolean shuttingDown() { InitShim shim = this.initShim; return shim != null ? shim.shuttingDown() : this.shuttingDown; } /** * Copy the current immutable object by setting a present value for the optional {@link DownstreamServiceImpl.AgentResult#value() value} attribute. * @param value The value for value * @return A modified copy of {@code this} object */ public final ImmutableAgentResult withValue(DownstreamServiceOuterClass.AgentResponse value) { Optional newValue = Optional.of(value); if (this.value.isPresent() && this.value.get() == value) return this; return new ImmutableAgentResult(newValue, this.timeout, this.interrupted, this.shuttingDown); } /** * Copy the current immutable object by setting an optional value for the {@link DownstreamServiceImpl.AgentResult#value() value} attribute. * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}. * @param optional A value for value * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final ImmutableAgentResult withValue(Optional optional) { Optional value = (Optional) optional; if (!this.value.isPresent() && !value.isPresent()) return this; if (this.value.isPresent() && value.isPresent() && this.value.get() == value.get()) return this; return new ImmutableAgentResult(value, this.timeout, this.interrupted, this.shuttingDown); } /** * Copy the current immutable object by setting a value for the {@link DownstreamServiceImpl.AgentResult#timeout() timeout} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for timeout * @return A modified copy of the {@code this} object */ public final ImmutableAgentResult withTimeout(boolean value) { if (this.timeout == value) return this; return new ImmutableAgentResult(this.value, value, this.interrupted, this.shuttingDown); } /** * Copy the current immutable object by setting a value for the {@link DownstreamServiceImpl.AgentResult#interrupted() interrupted} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for interrupted * @return A modified copy of the {@code this} object */ public final ImmutableAgentResult withInterrupted(boolean value) { if (this.interrupted == value) return this; return new ImmutableAgentResult(this.value, this.timeout, value, this.shuttingDown); } /** * Copy the current immutable object by setting a value for the {@link DownstreamServiceImpl.AgentResult#shuttingDown() shuttingDown} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for shuttingDown * @return A modified copy of the {@code this} object */ public final ImmutableAgentResult withShuttingDown(boolean value) { if (this.shuttingDown == value) return this; return new ImmutableAgentResult(this.value, this.timeout, this.interrupted, value); } /** * This instance is equal to all instances of {@code ImmutableAgentResult} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableAgentResult && equalTo((ImmutableAgentResult) another); } private boolean equalTo(ImmutableAgentResult another) { return value.equals(another.value) && timeout == another.timeout && interrupted == another.interrupted && shuttingDown == another.shuttingDown; } /** * Computes a hash code from attributes: {@code value}, {@code timeout}, {@code interrupted}, {@code shuttingDown}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + value.hashCode(); h += (h << 5) + Booleans.hashCode(timeout); h += (h << 5) + Booleans.hashCode(interrupted); h += (h << 5) + Booleans.hashCode(shuttingDown); return h; } /** * Prints the immutable value {@code AgentResult} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("AgentResult") .omitNullValues() .add("value", value.orNull()) .add("timeout", timeout) .add("interrupted", interrupted) .add("shuttingDown", shuttingDown) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Generated(from = "DownstreamServiceImpl.AgentResult", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements DownstreamServiceImpl.AgentResult { @Nullable Optional value = Optional.absent(); boolean timeout; boolean timeoutIsSet; boolean interrupted; boolean interruptedIsSet; boolean shuttingDown; boolean shuttingDownIsSet; @JsonProperty("value") public void setValue(Optional value) { this.value = value; } @JsonProperty("timeout") public void setTimeout(boolean timeout) { this.timeout = timeout; this.timeoutIsSet = true; } @JsonProperty("interrupted") public void setInterrupted(boolean interrupted) { this.interrupted = interrupted; this.interruptedIsSet = true; } @JsonProperty("shuttingDown") public void setShuttingDown(boolean shuttingDown) { this.shuttingDown = shuttingDown; this.shuttingDownIsSet = true; } @Override public Optional value() { throw new UnsupportedOperationException(); } @Override public boolean timeout() { throw new UnsupportedOperationException(); } @Override public boolean interrupted() { throw new UnsupportedOperationException(); } @Override public boolean shuttingDown() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableAgentResult fromJson(Json json) { ImmutableAgentResult.Builder builder = ImmutableAgentResult.builder(); if (json.value != null) { builder.value(json.value); } if (json.timeoutIsSet) { builder.timeout(json.timeout); } if (json.interruptedIsSet) { builder.interrupted(json.interrupted); } if (json.shuttingDownIsSet) { builder.shuttingDown(json.shuttingDown); } return builder.build(); } /** * Creates an immutable copy of a {@link DownstreamServiceImpl.AgentResult} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable AgentResult instance */ public static ImmutableAgentResult copyOf(DownstreamServiceImpl.AgentResult instance) { if (instance instanceof ImmutableAgentResult) { return (ImmutableAgentResult) instance; } return ImmutableAgentResult.builder() .copyFrom(instance) .build(); } /** * The serialized form captures the structural content of the value object, * providing the ability to reconstruct values with the capability to migrate * data. Uses optional, nullable, and provides flexible handling of * collection attributes. */ @Generated(from = "DownstreamServiceImpl.AgentResult", generator = "Immutables") private static class SerialForm implements Serializable { private static final long serialVersionUID = 0L; private final String[] names; private final Object[] values; SerialForm(ImmutableAgentResult instance) { List names = new ArrayList<>(4); List values = new ArrayList<>(4); if (instance.value().isPresent()) { names.add("value"); values.add(instance.value().get()); } names.add("timeout"); values.add(instance.timeout()); names.add("interrupted"); values.add(instance.interrupted()); names.add("shuttingDown"); values.add(instance.shuttingDown()); this.names = names.toArray(new String[names.size()]); this.values = values.toArray(); } Object readResolve() { ImmutableAgentResult.Builder builder = ImmutableAgentResult.builder(); for (int i = 0; i < names.length; i++) { String name = names[i]; if ("value".equals(name)) { if (values[i] != null) { builder.value((DownstreamServiceOuterClass.AgentResponse) values[i]); } continue; } if ("timeout".equals(name)) { builder.timeout((Boolean) toSingle("timeout", values[i])); continue; } if ("interrupted".equals(name)) { builder.interrupted((Boolean) toSingle("interrupted", values[i])); continue; } if ("shuttingDown".equals(name)) { builder.shuttingDown((Boolean) toSingle("shuttingDown", values[i])); continue; } } return builder.build(); } private static Object toSingle(String attribute, Object value) { if (value instanceof Object[]) { Object[] elements = (Object[]) value; if (elements.length == 1) { return elements[0]; } throw new IllegalStateException("Cannot extract scalar value for attribute '" + attribute + "' from array of length " + elements.length); } return value; } } private Object writeReplace() { return new SerialForm(this); } /** * Creates a builder for {@link ImmutableAgentResult ImmutableAgentResult}. *
   * ImmutableAgentResult.builder()
   *    .value(org.glowroot.wire.api.model.DownstreamServiceOuterClass.AgentResponse) // optional {@link DownstreamServiceImpl.AgentResult#value() value}
   *    .timeout(boolean) // optional {@link DownstreamServiceImpl.AgentResult#timeout() timeout}
   *    .interrupted(boolean) // optional {@link DownstreamServiceImpl.AgentResult#interrupted() interrupted}
   *    .shuttingDown(boolean) // optional {@link DownstreamServiceImpl.AgentResult#shuttingDown() shuttingDown}
   *    .build();
   * 
* @return A new ImmutableAgentResult builder */ public static ImmutableAgentResult.Builder builder() { return new ImmutableAgentResult.Builder(); } /** * Builds instances of type {@link ImmutableAgentResult ImmutableAgentResult}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "DownstreamServiceImpl.AgentResult", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long OPT_BIT_TIMEOUT = 0x1L; private static final long OPT_BIT_INTERRUPTED = 0x2L; private static final long OPT_BIT_SHUTTING_DOWN = 0x4L; private long optBits; private Optional value = Optional.absent(); private boolean timeout; private boolean interrupted; private boolean shuttingDown; private Builder() { } /** * Fill a builder with attribute values from the provided {@code AgentResult} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder copyFrom(DownstreamServiceImpl.AgentResult instance) { Objects.requireNonNull(instance, "instance"); Optional valueOptional = instance.value(); if (valueOptional.isPresent()) { value(valueOptional); } timeout(instance.timeout()); interrupted(instance.interrupted()); shuttingDown(instance.shuttingDown()); return this; } /** * Initializes the optional value {@link DownstreamServiceImpl.AgentResult#value() value} to value. * @param value The value for value * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder value(DownstreamServiceOuterClass.AgentResponse value) { this.value = Optional.of(value); return this; } /** * Initializes the optional value {@link DownstreamServiceImpl.AgentResult#value() value} to value. * @param value The value for value * @return {@code this} builder for use in a chained invocation */ @SuppressWarnings("unchecked") // safe covariant cast @CanIgnoreReturnValue public final Builder value(Optional value) { this.value = (Optional) value; return this; } /** * Initializes the value for the {@link DownstreamServiceImpl.AgentResult#timeout() timeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link DownstreamServiceImpl.AgentResult#timeout() timeout}. * @param timeout The value for timeout * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder timeout(boolean timeout) { this.timeout = timeout; optBits |= OPT_BIT_TIMEOUT; return this; } /** * Initializes the value for the {@link DownstreamServiceImpl.AgentResult#interrupted() interrupted} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link DownstreamServiceImpl.AgentResult#interrupted() interrupted}. * @param interrupted The value for interrupted * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder interrupted(boolean interrupted) { this.interrupted = interrupted; optBits |= OPT_BIT_INTERRUPTED; return this; } /** * Initializes the value for the {@link DownstreamServiceImpl.AgentResult#shuttingDown() shuttingDown} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link DownstreamServiceImpl.AgentResult#shuttingDown() shuttingDown}. * @param shuttingDown The value for shuttingDown * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder shuttingDown(boolean shuttingDown) { this.shuttingDown = shuttingDown; optBits |= OPT_BIT_SHUTTING_DOWN; return this; } /** * Builds a new {@link ImmutableAgentResult ImmutableAgentResult}. * @return An immutable instance of AgentResult * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAgentResult build() { return new ImmutableAgentResult(this); } private boolean timeoutIsSet() { return (optBits & OPT_BIT_TIMEOUT) != 0; } private boolean interruptedIsSet() { return (optBits & OPT_BIT_INTERRUPTED) != 0; } private boolean shuttingDownIsSet() { return (optBits & OPT_BIT_SHUTTING_DOWN) != 0; } } }