/** * Copy the current immutable object with elements that replace the content of {@link Check#getServiceTags() serviceTags}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableCheck withServiceTags(String... elements) { ImmutableList<String> newValue = ImmutableList.copyOf(elements); return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, newValue, this.deregisterCriticalServiceAfter)); }
/** * This instance is equal to all instances of {@code ImmutableCheck} 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 ImmutableCheck && equalTo((ImmutableCheck) another); }
/** * Creates an immutable copy of a {@link Check} 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 Check instance */ public static ImmutableCheck copyOf(Check instance) { if (instance instanceof ImmutableCheck) { return (ImmutableCheck) instance; } return ImmutableCheck.builder() .from(instance) .build(); }
private static ImmutableCheck validate(ImmutableCheck instance) { instance.validate(); return instance; }
/** * Builds a new {@link ImmutableCheck ImmutableCheck}. * @return An immutable instance of Check * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCheck build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableCheck.validate(new ImmutableCheck( id, name, notes, output, args, interval, ttl, http, tcp, grpc, grpcUseTls, serviceId, serviceTagsBuilder.build(), deregisterCriticalServiceAfter)); }
/** * Registers a script Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param args Specifies command argument to run to update the status of the check. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, String args, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .args(Collections.singletonList(args)) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Copy the current immutable object with elements that replace the content of {@link Check#getServiceTags() serviceTags}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of serviceTags elements to set * @return A modified copy of {@code this} object */ public final ImmutableCheck withServiceTags(Iterable<String> elements) { if (this.serviceTags == elements) return this; ImmutableList<String> newValue = ImmutableList.copyOf(elements); return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, newValue, this.deregisterCriticalServiceAfter)); }
/** * Registers a HTTP Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param http Health check URL. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, URL http, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .http(http.toExternalForm()) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Copy the current immutable object by setting a value for the {@link Check#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableCheck withName(String value) { if (this.name.equals(value)) return this; return validate(new ImmutableCheck( this.id, Preconditions.checkNotNull(value, "name"), this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Registers a Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param ttl Time to live for the Consul dead man's switch. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, long ttl, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .ttl(String.format("%ss", ttl)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Copy the current immutable object by setting an optional value for the {@link Check#getTtl() ttl} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for ttl * @return A modified copy of {@code this} object */ public final ImmutableCheck withTtl(Optional<String> optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.ttl, value)) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, value, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Registers a script Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param args Health script for Consul to use. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, List<String> args, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .args(args) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Copy the current immutable object by setting a value for the {@link Check#getId() id} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for id * @return A modified copy of the {@code this} object */ public final ImmutableCheck withId(String value) { if (this.id.equals(value)) return this; return validate(new ImmutableCheck( Preconditions.checkNotNull(value, "id"), this.name, this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Registers a TCP Health Check with the Agent. * * @param checkId The Check ID to use. Must be unique for the Agent. * @param name The Check Name. * @param tcp Health check TCP host and port. * @param interval Health script run interval in seconds. * @param notes Human readable notes. Not used by Consul. */ public void registerCheck(String checkId, String name, HostAndPort tcp, long interval, String notes) { Check check = ImmutableCheck.builder() .id(checkId) .name(name) .tcp(tcp.toString()) .interval(String.format("%ss", interval)) .notes(Optional.ofNullable(notes)) .build(); registerCheck(check); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Check#getArgs() args} attribute. * @param value The value for args * @return A modified copy of {@code this} object */ public final ImmutableCheck withArgs(List<String> value) { @Nullable List<String> newValue = Preconditions.checkNotNull(value, "args"); if (this.args == newValue) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, newValue, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
@JsonCreator static ImmutableCheck fromJson(Json json) { ImmutableCheck.Builder builder = ImmutableCheck.builder(); if (json.id != null) { builder.id(json.id);
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Check#getGrpcUseTls() grpcUseTls} attribute. * @param value The value for grpcUseTls * @return A modified copy of {@code this} object */ public final ImmutableCheck withGrpcUseTls(boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.grpcUseTls, newValue)) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, newValue, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Check#getOutput() output} attribute. * @param value The value for output * @return A modified copy of {@code this} object */ public final ImmutableCheck withOutput(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "output"); if (Objects.equals(this.output, newValue)) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, newValue, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Check#getTtl() ttl} attribute. * @param value The value for ttl * @return A modified copy of {@code this} object */ public final ImmutableCheck withTtl(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "ttl"); if (Objects.equals(this.ttl, newValue)) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, newValue, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, this.deregisterCriticalServiceAfter)); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Check#getDeregisterCriticalServiceAfter() deregisterCriticalServiceAfter} attribute. * @param value The value for deregisterCriticalServiceAfter * @return A modified copy of {@code this} object */ public final ImmutableCheck withDeregisterCriticalServiceAfter(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "deregisterCriticalServiceAfter"); if (Objects.equals(this.deregisterCriticalServiceAfter, newValue)) return this; return validate(new ImmutableCheck( this.id, this.name, this.notes, this.output, this.args, this.interval, this.ttl, this.http, this.tcp, this.grpc, this.grpcUseTls, this.serviceId, this.serviceTags, newValue)); }