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

org.cloudfoundry.operations.applications.StartApplicationRequest Maven / Gradle / Ivy

There is a newer version: 5.12.2.RELEASE
Show newest version
package org.cloudfoundry.operations.applications;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

/**
 * The request options for the start application operation
 */
@Generated(from = "_StartApplicationRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class StartApplicationRequest
    extends org.cloudfoundry.operations.applications._StartApplicationRequest {
  private final String name;
  private final Duration stagingTimeout;
  private final Duration startupTimeout;

  private StartApplicationRequest(StartApplicationRequest.Builder builder) {
    this.name = builder.name;
    if (builder.stagingTimeout != null) {
      initShim.stagingTimeout(builder.stagingTimeout);
    }
    if (builder.startupTimeout != null) {
      initShim.startupTimeout(builder.startupTimeout);
    }
    this.stagingTimeout = initShim.getStagingTimeout();
    this.startupTimeout = initShim.getStartupTimeout();
    this.initShim = null;
  }

  private static final byte STAGE_INITIALIZING = -1;
  private static final byte STAGE_UNINITIALIZED = 0;
  private static final byte STAGE_INITIALIZED = 1;
  private transient volatile InitShim initShim = new InitShim();

  @Generated(from = "_StartApplicationRequest", generator = "Immutables")
  private final class InitShim {
    private byte stagingTimeoutBuildStage = STAGE_UNINITIALIZED;
    private Duration stagingTimeout;

    Duration getStagingTimeout() {
      if (stagingTimeoutBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
      if (stagingTimeoutBuildStage == STAGE_UNINITIALIZED) {
        stagingTimeoutBuildStage = STAGE_INITIALIZING;
        this.stagingTimeout = Objects.requireNonNull(StartApplicationRequest.super.getStagingTimeout(), "stagingTimeout");
        stagingTimeoutBuildStage = STAGE_INITIALIZED;
      }
      return this.stagingTimeout;
    }

    void stagingTimeout(Duration stagingTimeout) {
      this.stagingTimeout = stagingTimeout;
      stagingTimeoutBuildStage = STAGE_INITIALIZED;
    }

    private byte startupTimeoutBuildStage = STAGE_UNINITIALIZED;
    private Duration startupTimeout;

    Duration getStartupTimeout() {
      if (startupTimeoutBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
      if (startupTimeoutBuildStage == STAGE_UNINITIALIZED) {
        startupTimeoutBuildStage = STAGE_INITIALIZING;
        this.startupTimeout = Objects.requireNonNull(StartApplicationRequest.super.getStartupTimeout(), "startupTimeout");
        startupTimeoutBuildStage = STAGE_INITIALIZED;
      }
      return this.startupTimeout;
    }

    void startupTimeout(Duration startupTimeout) {
      this.startupTimeout = startupTimeout;
      startupTimeoutBuildStage = STAGE_INITIALIZED;
    }

    private String formatInitCycleMessage() {
      List attributes = new ArrayList<>();
      if (stagingTimeoutBuildStage == STAGE_INITIALIZING) attributes.add("stagingTimeout");
      if (startupTimeoutBuildStage == STAGE_INITIALIZING) attributes.add("startupTimeout");
      return "Cannot build StartApplicationRequest, attribute initializers form cycle " + attributes;
    }
  }

  /**
   * The name of the application
   */
  @Override
  public String getName() {
    return name;
  }

  /**
   * How long to wait for staging
   */
  @Override
  public Duration getStagingTimeout() {
    InitShim shim = this.initShim;
    return shim != null
        ? shim.getStagingTimeout()
        : this.stagingTimeout;
  }

  /**
   * How long to wait for startup
   */
  @Override
  public Duration getStartupTimeout() {
    InitShim shim = this.initShim;
    return shim != null
        ? shim.getStartupTimeout()
        : this.startupTimeout;
  }

  /**
   * This instance is equal to all instances of {@code StartApplicationRequest} that have equal attribute values.
   * @return {@code true} if {@code this} is equal to {@code another} instance
   */
  @Override
  public boolean equals(Object another) {
    if (this == another) return true;
    return another instanceof StartApplicationRequest
        && equalTo((StartApplicationRequest) another);
  }

  private boolean equalTo(StartApplicationRequest another) {
    return name.equals(another.name)
        && stagingTimeout.equals(another.stagingTimeout)
        && startupTimeout.equals(another.startupTimeout);
  }

  /**
   * Computes a hash code from attributes: {@code name}, {@code stagingTimeout}, {@code startupTimeout}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + name.hashCode();
    h += (h << 5) + stagingTimeout.hashCode();
    h += (h << 5) + startupTimeout.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code StartApplicationRequest} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "StartApplicationRequest{"
        + "name=" + name
        + ", stagingTimeout=" + stagingTimeout
        + ", startupTimeout=" + startupTimeout
        + "}";
  }

  /**
   * Creates a builder for {@link StartApplicationRequest StartApplicationRequest}.
   * @return A new StartApplicationRequest builder
   */
  public static StartApplicationRequest.Builder builder() {
    return new StartApplicationRequest.Builder();
  }

  /**
   * Builds instances of type {@link StartApplicationRequest StartApplicationRequest}.
   * 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 = "_StartApplicationRequest", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private long initBits = 0x1L; private String name; private Duration stagingTimeout; private Duration startupTimeout; private Builder() { } /** * Fill a builder with attribute values from the provided {@code StartApplicationRequest} 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 */ public final Builder from(StartApplicationRequest instance) { return from((_StartApplicationRequest) instance); } /** * Copy abstract value type {@code _StartApplicationRequest} instance into builder. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ final Builder from(_StartApplicationRequest instance) { Objects.requireNonNull(instance, "instance"); name(instance.getName()); stagingTimeout(instance.getStagingTimeout()); startupTimeout(instance.getStartupTimeout()); return this; } /** * Initializes the value for the {@link StartApplicationRequest#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ public final Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link StartApplicationRequest#getStagingTimeout() stagingTimeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link StartApplicationRequest#getStagingTimeout() stagingTimeout}. * @param stagingTimeout The value for stagingTimeout * @return {@code this} builder for use in a chained invocation */ public final Builder stagingTimeout(Duration stagingTimeout) { this.stagingTimeout = Objects.requireNonNull(stagingTimeout, "stagingTimeout"); return this; } /** * Initializes the value for the {@link StartApplicationRequest#getStartupTimeout() startupTimeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link StartApplicationRequest#getStartupTimeout() startupTimeout}. * @param startupTimeout The value for startupTimeout * @return {@code this} builder for use in a chained invocation */ public final Builder startupTimeout(Duration startupTimeout) { this.startupTimeout = Objects.requireNonNull(startupTimeout, "startupTimeout"); return this; } /** * Builds a new {@link StartApplicationRequest StartApplicationRequest}. * @return An immutable instance of StartApplicationRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public StartApplicationRequest build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new StartApplicationRequest(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); return "Cannot build StartApplicationRequest, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy