com.hubspot.imap.ImapClientFactoryConfiguration Maven / Gradle / Ivy
package com.hubspot.imap;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollMode;
import io.netty.util.concurrent.EventExecutorGroup;
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.immutables.value.Generated;
/**
* Immutable implementation of {@link ImapClientFactoryConfigurationIF}.
*
* Use the builder to create immutable instances:
* {@code ImapClientFactoryConfiguration.builder()}.
*/
@Generated(from = "ImapClientFactoryConfigurationIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImapClientFactoryConfiguration implements ImapClientFactoryConfigurationIF {
private final EventLoopGroup eventLoopGroup;
private final EventExecutorGroup executor;
private final Class extends Channel> channelClass;
private final EpollMode epollMode;
private ImapClientFactoryConfiguration(ImapClientFactoryConfiguration.Builder builder) {
if (builder.eventLoopGroup != null) {
initShim.eventLoopGroup(builder.eventLoopGroup);
}
if (builder.executor != null) {
initShim.executor(builder.executor);
}
if (builder.channelClass != null) {
initShim.channelClass(builder.channelClass);
}
if (builder.epollMode != null) {
initShim.epollMode(builder.epollMode);
}
this.eventLoopGroup = initShim.eventLoopGroup();
this.executor = initShim.executor();
this.channelClass = initShim.channelClass();
this.epollMode = initShim.epollMode();
this.initShim = null;
}
private ImapClientFactoryConfiguration(
EventLoopGroup eventLoopGroup,
EventExecutorGroup executor,
Class extends Channel> channelClass,
EpollMode epollMode) {
this.eventLoopGroup = eventLoopGroup;
this.executor = executor;
this.channelClass = channelClass;
this.epollMode = epollMode;
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 = "ImapClientFactoryConfigurationIF", generator = "Immutables")
private final class InitShim {
private byte eventLoopGroupBuildStage = STAGE_UNINITIALIZED;
private EventLoopGroup eventLoopGroup;
EventLoopGroup eventLoopGroup() {
if (eventLoopGroupBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (eventLoopGroupBuildStage == STAGE_UNINITIALIZED) {
eventLoopGroupBuildStage = STAGE_INITIALIZING;
this.eventLoopGroup = Objects.requireNonNull(eventLoopGroupInitialize(), "eventLoopGroup");
eventLoopGroupBuildStage = STAGE_INITIALIZED;
}
return this.eventLoopGroup;
}
void eventLoopGroup(EventLoopGroup eventLoopGroup) {
this.eventLoopGroup = eventLoopGroup;
eventLoopGroupBuildStage = STAGE_INITIALIZED;
}
private byte executorBuildStage = STAGE_UNINITIALIZED;
private EventExecutorGroup executor;
EventExecutorGroup executor() {
if (executorBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (executorBuildStage == STAGE_UNINITIALIZED) {
executorBuildStage = STAGE_INITIALIZING;
this.executor = Objects.requireNonNull(executorInitialize(), "executor");
executorBuildStage = STAGE_INITIALIZED;
}
return this.executor;
}
void executor(EventExecutorGroup executor) {
this.executor = executor;
executorBuildStage = STAGE_INITIALIZED;
}
private byte channelClassBuildStage = STAGE_UNINITIALIZED;
private Class extends Channel> channelClass;
Class extends Channel> channelClass() {
if (channelClassBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (channelClassBuildStage == STAGE_UNINITIALIZED) {
channelClassBuildStage = STAGE_INITIALIZING;
this.channelClass = Objects.requireNonNull(channelClassInitialize(), "channelClass");
channelClassBuildStage = STAGE_INITIALIZED;
}
return this.channelClass;
}
void channelClass(Class extends Channel> channelClass) {
this.channelClass = channelClass;
channelClassBuildStage = STAGE_INITIALIZED;
}
private byte epollModeBuildStage = STAGE_UNINITIALIZED;
private EpollMode epollMode;
EpollMode epollMode() {
if (epollModeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (epollModeBuildStage == STAGE_UNINITIALIZED) {
epollModeBuildStage = STAGE_INITIALIZING;
this.epollMode = Objects.requireNonNull(epollModeInitialize(), "epollMode");
epollModeBuildStage = STAGE_INITIALIZED;
}
return this.epollMode;
}
void epollMode(EpollMode epollMode) {
this.epollMode = epollMode;
epollModeBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (eventLoopGroupBuildStage == STAGE_INITIALIZING) attributes.add("eventLoopGroup");
if (executorBuildStage == STAGE_INITIALIZING) attributes.add("executor");
if (channelClassBuildStage == STAGE_INITIALIZING) attributes.add("channelClass");
if (epollModeBuildStage == STAGE_INITIALIZING) attributes.add("epollMode");
return "Cannot build ImapClientFactoryConfiguration, attribute initializers form cycle " + attributes;
}
}
private EventLoopGroup eventLoopGroupInitialize() {
return ImapClientFactoryConfigurationIF.super.eventLoopGroup();
}
private EventExecutorGroup executorInitialize() {
return ImapClientFactoryConfigurationIF.super.executor();
}
private Class extends Channel> channelClassInitialize() {
return ImapClientFactoryConfigurationIF.super.channelClass();
}
private EpollMode epollModeInitialize() {
return ImapClientFactoryConfigurationIF.super.epollMode();
}
/**
* @return The value of the {@code eventLoopGroup} attribute
*/
@JsonProperty("eventLoopGroup")
@Override
public EventLoopGroup eventLoopGroup() {
InitShim shim = this.initShim;
return shim != null
? shim.eventLoopGroup()
: this.eventLoopGroup;
}
/**
* @return The value of the {@code executor} attribute
*/
@JsonProperty("executor")
@Override
public EventExecutorGroup executor() {
InitShim shim = this.initShim;
return shim != null
? shim.executor()
: this.executor;
}
/**
* @return The value of the {@code channelClass} attribute
*/
@JsonProperty("channelClass")
@Override
public Class extends Channel> channelClass() {
InitShim shim = this.initShim;
return shim != null
? shim.channelClass()
: this.channelClass;
}
/**
* @return The value of the {@code epollMode} attribute
*/
@JsonProperty("epollMode")
@Override
public EpollMode epollMode() {
InitShim shim = this.initShim;
return shim != null
? shim.epollMode()
: this.epollMode;
}
/**
* Copy the current immutable object by setting a value for the {@link ImapClientFactoryConfigurationIF#eventLoopGroup() eventLoopGroup} 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 eventLoopGroup
* @return A modified copy of the {@code this} object
*/
public final ImapClientFactoryConfiguration withEventLoopGroup(EventLoopGroup value) {
if (this.eventLoopGroup == value) return this;
EventLoopGroup newValue = Objects.requireNonNull(value, "eventLoopGroup");
return new ImapClientFactoryConfiguration(newValue, this.executor, this.channelClass, this.epollMode);
}
/**
* Copy the current immutable object by setting a value for the {@link ImapClientFactoryConfigurationIF#executor() executor} 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 executor
* @return A modified copy of the {@code this} object
*/
public final ImapClientFactoryConfiguration withExecutor(EventExecutorGroup value) {
if (this.executor == value) return this;
EventExecutorGroup newValue = Objects.requireNonNull(value, "executor");
return new ImapClientFactoryConfiguration(this.eventLoopGroup, newValue, this.channelClass, this.epollMode);
}
/**
* Copy the current immutable object by setting a value for the {@link ImapClientFactoryConfigurationIF#channelClass() channelClass} 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 channelClass
* @return A modified copy of the {@code this} object
*/
public final ImapClientFactoryConfiguration withChannelClass(Class extends Channel> value) {
if (this.channelClass == value) return this;
Class extends Channel> newValue = Objects.requireNonNull(value, "channelClass");
return new ImapClientFactoryConfiguration(this.eventLoopGroup, this.executor, newValue, this.epollMode);
}
/**
* Copy the current immutable object by setting a value for the {@link ImapClientFactoryConfigurationIF#epollMode() epollMode} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for epollMode
* @return A modified copy of the {@code this} object
*/
public final ImapClientFactoryConfiguration withEpollMode(EpollMode value) {
if (this.epollMode == value) return this;
EpollMode newValue = Objects.requireNonNull(value, "epollMode");
if (this.epollMode.equals(newValue)) return this;
return new ImapClientFactoryConfiguration(this.eventLoopGroup, this.executor, this.channelClass, newValue);
}
/**
* This instance is equal to all instances of {@code ImapClientFactoryConfiguration} 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 ImapClientFactoryConfiguration
&& equalTo((ImapClientFactoryConfiguration) another);
}
private boolean equalTo(ImapClientFactoryConfiguration another) {
return eventLoopGroup.equals(another.eventLoopGroup)
&& executor.equals(another.executor)
&& channelClass.equals(another.channelClass)
&& epollMode.equals(another.epollMode);
}
/**
* Computes a hash code from attributes: {@code eventLoopGroup}, {@code executor}, {@code channelClass}, {@code epollMode}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + eventLoopGroup.hashCode();
h += (h << 5) + executor.hashCode();
h += (h << 5) + channelClass.hashCode();
h += (h << 5) + epollMode.hashCode();
return h;
}
/**
* Prints the immutable value {@code ImapClientFactoryConfiguration} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ImapClientFactoryConfiguration")
.omitNullValues()
.add("eventLoopGroup", eventLoopGroup)
.add("executor", executor)
.add("channelClass", channelClass)
.add("epollMode", epollMode)
.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 = "ImapClientFactoryConfigurationIF", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ImapClientFactoryConfigurationIF {
@Nullable EventLoopGroup eventLoopGroup;
@Nullable EventExecutorGroup executor;
@Nullable Class extends Channel> channelClass;
@Nullable EpollMode epollMode;
@JsonProperty("eventLoopGroup")
public void setEventLoopGroup(EventLoopGroup eventLoopGroup) {
this.eventLoopGroup = eventLoopGroup;
}
@JsonProperty("executor")
public void setExecutor(EventExecutorGroup executor) {
this.executor = executor;
}
@JsonProperty("channelClass")
public void setChannelClass(Class extends Channel> channelClass) {
this.channelClass = channelClass;
}
@JsonProperty("epollMode")
public void setEpollMode(EpollMode epollMode) {
this.epollMode = epollMode;
}
@Override
public EventLoopGroup eventLoopGroup() { throw new UnsupportedOperationException(); }
@Override
public EventExecutorGroup executor() { throw new UnsupportedOperationException(); }
@Override
public Class extends Channel> channelClass() { throw new UnsupportedOperationException(); }
@Override
public EpollMode epollMode() { 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 ImapClientFactoryConfiguration fromJson(Json json) {
ImapClientFactoryConfiguration.Builder builder = ImapClientFactoryConfiguration.builder();
if (json.eventLoopGroup != null) {
builder.eventLoopGroup(json.eventLoopGroup);
}
if (json.executor != null) {
builder.executor(json.executor);
}
if (json.channelClass != null) {
builder.channelClass(json.channelClass);
}
if (json.epollMode != null) {
builder.epollMode(json.epollMode);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ImapClientFactoryConfigurationIF} 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 ImapClientFactoryConfiguration instance
*/
public static ImapClientFactoryConfiguration copyOf(ImapClientFactoryConfigurationIF instance) {
if (instance instanceof ImapClientFactoryConfiguration) {
return (ImapClientFactoryConfiguration) instance;
}
return ImapClientFactoryConfiguration.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImapClientFactoryConfiguration ImapClientFactoryConfiguration}.
*
* ImapClientFactoryConfiguration.builder()
* .eventLoopGroup(io.netty.channel.EventLoopGroup) // optional {@link ImapClientFactoryConfigurationIF#eventLoopGroup() eventLoopGroup}
* .executor(io.netty.util.concurrent.EventExecutorGroup) // optional {@link ImapClientFactoryConfigurationIF#executor() executor}
* .channelClass(Class<? extends io.netty.channel.Channel>) // optional {@link ImapClientFactoryConfigurationIF#channelClass() channelClass}
* .epollMode(io.netty.channel.epoll.EpollMode) // optional {@link ImapClientFactoryConfigurationIF#epollMode() epollMode}
* .build();
*
* @return A new ImapClientFactoryConfiguration builder
*/
public static ImapClientFactoryConfiguration.Builder builder() {
return new ImapClientFactoryConfiguration.Builder();
}
/**
* Builds instances of type {@link ImapClientFactoryConfiguration ImapClientFactoryConfiguration}.
* 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 = "ImapClientFactoryConfigurationIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private @Nullable EventLoopGroup eventLoopGroup;
private @Nullable EventExecutorGroup executor;
private @Nullable Class extends Channel> channelClass;
private @Nullable EpollMode epollMode;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ImapClientFactoryConfigurationIF} 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 from(ImapClientFactoryConfigurationIF instance) {
Objects.requireNonNull(instance, "instance");
eventLoopGroup(instance.eventLoopGroup());
executor(instance.executor());
channelClass(instance.channelClass());
epollMode(instance.epollMode());
return this;
}
/**
* Initializes the value for the {@link ImapClientFactoryConfigurationIF#eventLoopGroup() eventLoopGroup} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link ImapClientFactoryConfigurationIF#eventLoopGroup() eventLoopGroup}.
* @param eventLoopGroup The value for eventLoopGroup
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("eventLoopGroup")
public final Builder eventLoopGroup(EventLoopGroup eventLoopGroup) {
this.eventLoopGroup = Objects.requireNonNull(eventLoopGroup, "eventLoopGroup");
return this;
}
/**
* Initializes the value for the {@link ImapClientFactoryConfigurationIF#executor() executor} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link ImapClientFactoryConfigurationIF#executor() executor}.
* @param executor The value for executor
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("executor")
public final Builder executor(EventExecutorGroup executor) {
this.executor = Objects.requireNonNull(executor, "executor");
return this;
}
/**
* Initializes the value for the {@link ImapClientFactoryConfigurationIF#channelClass() channelClass} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link ImapClientFactoryConfigurationIF#channelClass() channelClass}.
* @param channelClass The value for channelClass
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("channelClass")
public final Builder channelClass(Class extends Channel> channelClass) {
this.channelClass = Objects.requireNonNull(channelClass, "channelClass");
return this;
}
/**
* Initializes the value for the {@link ImapClientFactoryConfigurationIF#epollMode() epollMode} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link ImapClientFactoryConfigurationIF#epollMode() epollMode}.
* @param epollMode The value for epollMode
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("epollMode")
public final Builder epollMode(EpollMode epollMode) {
this.epollMode = Objects.requireNonNull(epollMode, "epollMode");
return this;
}
/**
* Builds a new {@link ImapClientFactoryConfiguration ImapClientFactoryConfiguration}.
* @return An immutable instance of ImapClientFactoryConfiguration
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImapClientFactoryConfiguration build() {
return new ImapClientFactoryConfiguration(this);
}
}
}