org.glowroot.central.ImmutableSyncHttpClientHolder 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.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
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.apache.http.impl.client.CloseableHttpClient;
import org.glowroot.common2.config.HttpProxyConfig;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link SyntheticMonitorService.SyncHttpClientHolder}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSyncHttpClientHolder.builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableSyncHttpClientHolder.of()}.
*/
@Generated(from = "SyntheticMonitorService.SyncHttpClientHolder", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
final class ImmutableSyncHttpClientHolder
implements SyntheticMonitorService.SyncHttpClientHolder {
private final CloseableHttpClient syncHttpClient;
private final HttpProxyConfig httpProxyConfig;
private ImmutableSyncHttpClientHolder(
CloseableHttpClient syncHttpClient,
HttpProxyConfig httpProxyConfig) {
this.syncHttpClient = Objects.requireNonNull(syncHttpClient, "syncHttpClient");
this.httpProxyConfig = Objects.requireNonNull(httpProxyConfig, "httpProxyConfig");
}
private ImmutableSyncHttpClientHolder(
ImmutableSyncHttpClientHolder original,
CloseableHttpClient syncHttpClient,
HttpProxyConfig httpProxyConfig) {
this.syncHttpClient = syncHttpClient;
this.httpProxyConfig = httpProxyConfig;
}
/**
* @return The value of the {@code syncHttpClient} attribute
*/
@JsonProperty("syncHttpClient")
@Override
public CloseableHttpClient syncHttpClient() {
return syncHttpClient;
}
/**
* @return The value of the {@code httpProxyConfig} attribute
*/
@JsonProperty("httpProxyConfig")
@Override
public HttpProxyConfig httpProxyConfig() {
return httpProxyConfig;
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyncHttpClientHolder#syncHttpClient() syncHttpClient} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for syncHttpClient
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyncHttpClientHolder withSyncHttpClient(CloseableHttpClient value) {
if (this.syncHttpClient == value) return this;
CloseableHttpClient newValue = Objects.requireNonNull(value, "syncHttpClient");
return new ImmutableSyncHttpClientHolder(this, newValue, this.httpProxyConfig);
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyncHttpClientHolder#httpProxyConfig() httpProxyConfig} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for httpProxyConfig
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyncHttpClientHolder withHttpProxyConfig(HttpProxyConfig value) {
if (this.httpProxyConfig == value) return this;
HttpProxyConfig newValue = Objects.requireNonNull(value, "httpProxyConfig");
return new ImmutableSyncHttpClientHolder(this, this.syncHttpClient, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableSyncHttpClientHolder} 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 ImmutableSyncHttpClientHolder
&& equalTo((ImmutableSyncHttpClientHolder) another);
}
private boolean equalTo(ImmutableSyncHttpClientHolder another) {
return syncHttpClient.equals(another.syncHttpClient)
&& httpProxyConfig.equals(another.httpProxyConfig);
}
/**
* Computes a hash code from attributes: {@code syncHttpClient}, {@code httpProxyConfig}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + syncHttpClient.hashCode();
h += (h << 5) + httpProxyConfig.hashCode();
return h;
}
/**
* Prints the immutable value {@code SyncHttpClientHolder} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SyncHttpClientHolder")
.omitNullValues()
.add("syncHttpClient", syncHttpClient)
.add("httpProxyConfig", httpProxyConfig)
.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 = "SyntheticMonitorService.SyncHttpClientHolder", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements SyntheticMonitorService.SyncHttpClientHolder {
@Nullable CloseableHttpClient syncHttpClient;
@Nullable HttpProxyConfig httpProxyConfig;
@JsonProperty("syncHttpClient")
public void setSyncHttpClient(CloseableHttpClient syncHttpClient) {
this.syncHttpClient = syncHttpClient;
}
@JsonProperty("httpProxyConfig")
public void setHttpProxyConfig(HttpProxyConfig httpProxyConfig) {
this.httpProxyConfig = httpProxyConfig;
}
@Override
public CloseableHttpClient syncHttpClient() { throw new UnsupportedOperationException(); }
@Override
public HttpProxyConfig httpProxyConfig() { 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 ImmutableSyncHttpClientHolder fromJson(Json json) {
ImmutableSyncHttpClientHolder.Builder builder = ImmutableSyncHttpClientHolder.builder();
if (json.syncHttpClient != null) {
builder.syncHttpClient(json.syncHttpClient);
}
if (json.httpProxyConfig != null) {
builder.httpProxyConfig(json.httpProxyConfig);
}
return builder.build();
}
/**
* Construct a new immutable {@code SyncHttpClientHolder} instance.
* @param syncHttpClient The value for the {@code syncHttpClient} attribute
* @param httpProxyConfig The value for the {@code httpProxyConfig} attribute
* @return An immutable SyncHttpClientHolder instance
*/
public static ImmutableSyncHttpClientHolder of(CloseableHttpClient syncHttpClient, HttpProxyConfig httpProxyConfig) {
return new ImmutableSyncHttpClientHolder(syncHttpClient, httpProxyConfig);
}
/**
* Creates an immutable copy of a {@link SyntheticMonitorService.SyncHttpClientHolder} 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 SyncHttpClientHolder instance
*/
public static ImmutableSyncHttpClientHolder copyOf(SyntheticMonitorService.SyncHttpClientHolder instance) {
if (instance instanceof ImmutableSyncHttpClientHolder) {
return (ImmutableSyncHttpClientHolder) instance;
}
return ImmutableSyncHttpClientHolder.builder()
.copyFrom(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSyncHttpClientHolder ImmutableSyncHttpClientHolder}.
*
* ImmutableSyncHttpClientHolder.builder()
* .syncHttpClient(org.apache.http.impl.client.CloseableHttpClient) // required {@link SyntheticMonitorService.SyncHttpClientHolder#syncHttpClient() syncHttpClient}
* .httpProxyConfig(org.glowroot.common2.config.HttpProxyConfig) // required {@link SyntheticMonitorService.SyncHttpClientHolder#httpProxyConfig() httpProxyConfig}
* .build();
*
* @return A new ImmutableSyncHttpClientHolder builder
*/
public static ImmutableSyncHttpClientHolder.Builder builder() {
return new ImmutableSyncHttpClientHolder.Builder();
}
/**
* Builds instances of type {@link ImmutableSyncHttpClientHolder ImmutableSyncHttpClientHolder}.
* 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 = "SyntheticMonitorService.SyncHttpClientHolder", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_SYNC_HTTP_CLIENT = 0x1L;
private static final long INIT_BIT_HTTP_PROXY_CONFIG = 0x2L;
private long initBits = 0x3L;
private @Nullable CloseableHttpClient syncHttpClient;
private @Nullable HttpProxyConfig httpProxyConfig;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SyncHttpClientHolder} 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(SyntheticMonitorService.SyncHttpClientHolder instance) {
Objects.requireNonNull(instance, "instance");
syncHttpClient(instance.syncHttpClient());
httpProxyConfig(instance.httpProxyConfig());
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyncHttpClientHolder#syncHttpClient() syncHttpClient} attribute.
* @param syncHttpClient The value for syncHttpClient
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder syncHttpClient(CloseableHttpClient syncHttpClient) {
this.syncHttpClient = Objects.requireNonNull(syncHttpClient, "syncHttpClient");
initBits &= ~INIT_BIT_SYNC_HTTP_CLIENT;
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyncHttpClientHolder#httpProxyConfig() httpProxyConfig} attribute.
* @param httpProxyConfig The value for httpProxyConfig
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder httpProxyConfig(HttpProxyConfig httpProxyConfig) {
this.httpProxyConfig = Objects.requireNonNull(httpProxyConfig, "httpProxyConfig");
initBits &= ~INIT_BIT_HTTP_PROXY_CONFIG;
return this;
}
/**
* Builds a new {@link ImmutableSyncHttpClientHolder ImmutableSyncHttpClientHolder}.
* @return An immutable instance of SyncHttpClientHolder
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSyncHttpClientHolder build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSyncHttpClientHolder(null, syncHttpClient, httpProxyConfig);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_SYNC_HTTP_CLIENT) != 0) attributes.add("syncHttpClient");
if ((initBits & INIT_BIT_HTTP_PROXY_CONFIG) != 0) attributes.add("httpProxyConfig");
return "Cannot build SyncHttpClientHolder, some of required attributes are not set " + attributes;
}
}
}