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 extends DownstreamServiceOuterClass.AgentResponse> 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