
org.glowroot.common.live.ImmutableProcessInfo Maven / Gradle / Ivy
package org.glowroot.common.live;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link LiveJvmService.ProcessInfo}.
*
* Use builder to create immutable instances:
* {@code ImmutableProcessInfo.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "LiveJvmService.ProcessInfo"})
@Immutable
public final class ImmutableProcessInfo implements LiveJvmService.ProcessInfo {
private final long startTime;
private final long uptime;
private final String pid;
private final String mainClass;
private final ImmutableList mainClassArguments;
private final String jvm;
private final String java;
private final String javaHome;
private final ImmutableList jvmArguments;
private ImmutableProcessInfo(
long startTime,
long uptime,
String pid,
String mainClass,
ImmutableList mainClassArguments,
String jvm,
String java,
String javaHome,
ImmutableList jvmArguments) {
this.startTime = startTime;
this.uptime = uptime;
this.pid = pid;
this.mainClass = mainClass;
this.mainClassArguments = mainClassArguments;
this.jvm = jvm;
this.java = java;
this.javaHome = javaHome;
this.jvmArguments = jvmArguments;
}
/**
* @return value of {@code startTime} attribute
*/
@JsonProperty
@Override
public long startTime() {
return startTime;
}
/**
* @return value of {@code uptime} attribute
*/
@JsonProperty
@Override
public long uptime() {
return uptime;
}
/**
* @return value of {@code pid} attribute
*/
@JsonProperty
@Override
public String pid() {
return pid;
}
/**
* @return value of {@code mainClass} attribute
*/
@JsonProperty
@Override
public String mainClass() {
return mainClass;
}
/**
* @return value of {@code mainClassArguments} attribute
*/
@JsonProperty
@Override
public ImmutableList mainClassArguments() {
return mainClassArguments;
}
/**
* @return value of {@code jvm} attribute
*/
@JsonProperty
@Override
public String jvm() {
return jvm;
}
/**
* @return value of {@code java} attribute
*/
@JsonProperty
@Override
public String java() {
return java;
}
/**
* @return value of {@code javaHome} attribute
*/
@JsonProperty
@Override
public String javaHome() {
return javaHome;
}
/**
* @return value of {@code jvmArguments} attribute
*/
@JsonProperty
@Override
public ImmutableList jvmArguments() {
return jvmArguments;
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#startTime() startTime}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for startTime
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withStartTime(long value) {
if (this.startTime == value) return this;
long newValue = value;
return new ImmutableProcessInfo(
newValue,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#uptime() uptime}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for uptime
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withUptime(long value) {
if (this.uptime == value) return this;
long newValue = value;
return new ImmutableProcessInfo(
this.startTime,
newValue,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#pid() pid}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pid
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withPid(String value) {
if (this.pid == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
newValue,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#mainClass() mainClass}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for mainClass
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withMainClass(String value) {
if (this.mainClass == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
newValue,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableProcessInfo withMainClassArguments(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
newValue,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of mainClassArguments elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableProcessInfo withMainClassArguments(Iterable elements) {
if (this.mainClassArguments == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
newValue,
this.jvm,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#jvm() jvm}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for jvm
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withJvm(String value) {
if (this.jvm == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
newValue,
this.java,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#java() java}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for java
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withJava(String value) {
if (this.java == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
newValue,
this.javaHome,
this.jvmArguments);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.ProcessInfo#javaHome() javaHome}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for javaHome
* @return modified copy of the {@code this} object
*/
public final ImmutableProcessInfo withJavaHome(String value) {
if (this.javaHome == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
newValue,
this.jvmArguments);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableProcessInfo withJvmArguments(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of jvmArguments elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableProcessInfo withJvmArguments(Iterable elements) {
if (this.jvmArguments == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableProcessInfo(
this.startTime,
this.uptime,
this.pid,
this.mainClass,
this.mainClassArguments,
this.jvm,
this.java,
this.javaHome,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableProcessInfo} with 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 ImmutableProcessInfo
&& equalTo((ImmutableProcessInfo) another);
}
private boolean equalTo(ImmutableProcessInfo another) {
return startTime == another.startTime
&& uptime == another.uptime
&& pid.equals(another.pid)
&& mainClass.equals(another.mainClass)
&& mainClassArguments.equals(another.mainClassArguments)
&& jvm.equals(another.jvm)
&& java.equals(another.java)
&& javaHome.equals(another.javaHome)
&& jvmArguments.equals(another.jvmArguments);
}
/**
* Computes hash code from attributes: {@code startTime}, {@code uptime}, {@code pid}, {@code mainClass}, {@code mainClassArguments}, {@code jvm}, {@code java}, {@code javaHome}, {@code jvmArguments}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Longs.hashCode(startTime);
h = h * 17 + Longs.hashCode(uptime);
h = h * 17 + pid.hashCode();
h = h * 17 + mainClass.hashCode();
h = h * 17 + mainClassArguments.hashCode();
h = h * 17 + jvm.hashCode();
h = h * 17 + java.hashCode();
h = h * 17 + javaHome.hashCode();
h = h * 17 + jvmArguments.hashCode();
return h;
}
/**
* Prints immutable value {@code ProcessInfo...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ProcessInfo")
.add("startTime", startTime)
.add("uptime", uptime)
.add("pid", pid)
.add("mainClass", mainClass)
.add("mainClassArguments", mainClassArguments)
.add("jvm", jvm)
.add("java", java)
.add("javaHome", javaHome)
.add("jvmArguments", jvmArguments)
.toString();
}
/**
* Simple representation of this value type suitable Jackson binding
* @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
static final class Json {
@JsonProperty
@Nullable Long startTime;
@JsonProperty
@Nullable Long uptime;
@JsonProperty
@Nullable String pid;
@JsonProperty
@Nullable String mainClass;
@JsonProperty
@Nullable List mainClassArguments;
@JsonProperty
@Nullable String jvm;
@JsonProperty
@Nullable String java;
@JsonProperty
@Nullable String javaHome;
@JsonProperty
@Nullable List jvmArguments;
}
/**
* @param json JSON-bindable data structure
* @return immutable value type
* @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator
static ImmutableProcessInfo fromJson(Json json) {
ImmutableProcessInfo.Builder builder = ImmutableProcessInfo.builder();
if (json.startTime != null) {
builder.startTime(json.startTime);
}
if (json.uptime != null) {
builder.uptime(json.uptime);
}
if (json.pid != null) {
builder.pid(json.pid);
}
if (json.mainClass != null) {
builder.mainClass(json.mainClass);
}
if (json.mainClassArguments != null) {
builder.addAllMainClassArguments(json.mainClassArguments);
}
if (json.jvm != null) {
builder.jvm(json.jvm);
}
if (json.java != null) {
builder.java(json.java);
}
if (json.javaHome != null) {
builder.javaHome(json.javaHome);
}
if (json.jvmArguments != null) {
builder.addAllJvmArguments(json.jvmArguments);
}
return builder.build();
}
/**
* Creates immutable copy of {@link LiveJvmService.ProcessInfo}.
* Uses accessors to get values to initialize immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance instance to copy
* @return copied immutable ProcessInfo instance
*/
public static ImmutableProcessInfo copyOf(LiveJvmService.ProcessInfo instance) {
if (instance instanceof ImmutableProcessInfo) {
return (ImmutableProcessInfo) instance;
}
return ImmutableProcessInfo.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.common.live.ImmutableProcessInfo ImmutableProcessInfo}.
* @return new ImmutableProcessInfo builder
*/
public static ImmutableProcessInfo.Builder builder() {
return new ImmutableProcessInfo.Builder();
}
/**
* Builds instances of {@link org.glowroot.common.live.ImmutableProcessInfo ImmutableProcessInfo}.
* Initialize attributes and then invoke {@link #build()} method to create
* immutable instance.
* {@code Builder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_START_TIME = 0x1L;
private static final long INIT_BIT_UPTIME = 0x2L;
private static final long INIT_BIT_PID = 0x4L;
private static final long INIT_BIT_MAIN_CLASS = 0x8L;
private static final long INIT_BIT_JVM = 0x10L;
private static final long INIT_BIT_JAVA = 0x20L;
private static final long INIT_BIT_JAVA_HOME = 0x40L;
private long initBits = 0x7f;
private long startTime;
private long uptime;
private @Nullable String pid;
private @Nullable String mainClass;
private ImmutableList.Builder mainClassArgumentsBuilder = ImmutableList.builder();
private @Nullable String jvm;
private @Nullable String java;
private @Nullable String javaHome;
private ImmutableList.Builder jvmArgumentsBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link LiveJvmService.ProcessInfo} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(LiveJvmService.ProcessInfo instance) {
Preconditions.checkNotNull(instance);
startTime(instance.startTime());
uptime(instance.uptime());
pid(instance.pid());
mainClass(instance.mainClass());
addAllMainClassArguments(instance.mainClassArguments());
jvm(instance.jvm());
java(instance.java());
javaHome(instance.javaHome());
addAllJvmArguments(instance.jvmArguments());
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#startTime() startTime}.
* @param startTime value for startTime
* @return {@code this} builder for chained invocation
*/
public final Builder startTime(long startTime) {
this.startTime = startTime;
initBits &= ~INIT_BIT_START_TIME;
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#uptime() uptime}.
* @param uptime value for uptime
* @return {@code this} builder for chained invocation
*/
public final Builder uptime(long uptime) {
this.uptime = uptime;
initBits &= ~INIT_BIT_UPTIME;
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#pid() pid}.
* @param pid value for pid
* @return {@code this} builder for chained invocation
*/
public final Builder pid(String pid) {
this.pid = Preconditions.checkNotNull(pid);
initBits &= ~INIT_BIT_PID;
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#mainClass() mainClass}.
* @param mainClass value for mainClass
* @return {@code this} builder for chained invocation
*/
public final Builder mainClass(String mainClass) {
this.mainClass = Preconditions.checkNotNull(mainClass);
initBits &= ~INIT_BIT_MAIN_CLASS;
return this;
}
/**
* Adds one element to {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments} list.
* @param element mainClassArguments element
* @return {@code this} builder for chained invocation
*/
public final Builder addMainClassArguments(String element) {
mainClassArgumentsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments} list.
* @param elements array of mainClassArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder addMainClassArguments(String... elements) {
mainClassArgumentsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments} list.
* @param elements iterable of mainClassArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder mainClassArguments(Iterable elements) {
mainClassArgumentsBuilder = ImmutableList.builder();
return addAllMainClassArguments(elements);
}
/**
* Adds elements to {@link LiveJvmService.ProcessInfo#mainClassArguments() mainClassArguments} list.
* @param elements iterable of mainClassArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllMainClassArguments(Iterable elements) {
mainClassArgumentsBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#jvm() jvm}.
* @param jvm value for jvm
* @return {@code this} builder for chained invocation
*/
public final Builder jvm(String jvm) {
this.jvm = Preconditions.checkNotNull(jvm);
initBits &= ~INIT_BIT_JVM;
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#java() java}.
* @param java value for java
* @return {@code this} builder for chained invocation
*/
public final Builder java(String java) {
this.java = Preconditions.checkNotNull(java);
initBits &= ~INIT_BIT_JAVA;
return this;
}
/**
* Initializes value for {@link LiveJvmService.ProcessInfo#javaHome() javaHome}.
* @param javaHome value for javaHome
* @return {@code this} builder for chained invocation
*/
public final Builder javaHome(String javaHome) {
this.javaHome = Preconditions.checkNotNull(javaHome);
initBits &= ~INIT_BIT_JAVA_HOME;
return this;
}
/**
* Adds one element to {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments} list.
* @param element jvmArguments element
* @return {@code this} builder for chained invocation
*/
public final Builder addJvmArguments(String element) {
jvmArgumentsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments} list.
* @param elements array of jvmArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder addJvmArguments(String... elements) {
jvmArgumentsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments} list.
* @param elements iterable of jvmArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder jvmArguments(Iterable elements) {
jvmArgumentsBuilder = ImmutableList.builder();
return addAllJvmArguments(elements);
}
/**
* Adds elements to {@link LiveJvmService.ProcessInfo#jvmArguments() jvmArguments} list.
* @param elements iterable of jvmArguments elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllJvmArguments(Iterable elements) {
jvmArgumentsBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.common.live.ImmutableProcessInfo ImmutableProcessInfo}.
* @return immutable instance of ProcessInfo
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableProcessInfo build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableProcessInfo(
startTime,
uptime,
pid,
mainClass,
mainClassArgumentsBuilder.build(),
jvm,
java,
javaHome,
jvmArgumentsBuilder.build());
}
private boolean startTimeIsSet() {
return (initBits & INIT_BIT_START_TIME) == 0;
}
private boolean uptimeIsSet() {
return (initBits & INIT_BIT_UPTIME) == 0;
}
private boolean pidIsSet() {
return (initBits & INIT_BIT_PID) == 0;
}
private boolean mainClassIsSet() {
return (initBits & INIT_BIT_MAIN_CLASS) == 0;
}
private boolean jvmIsSet() {
return (initBits & INIT_BIT_JVM) == 0;
}
private boolean javaIsSet() {
return (initBits & INIT_BIT_JAVA) == 0;
}
private boolean javaHomeIsSet() {
return (initBits & INIT_BIT_JAVA_HOME) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!startTimeIsSet()) attributes.add("startTime");
if (!uptimeIsSet()) attributes.add("uptime");
if (!pidIsSet()) attributes.add("pid");
if (!mainClassIsSet()) attributes.add("mainClass");
if (!jvmIsSet()) attributes.add("jvm");
if (!javaIsSet()) attributes.add("java");
if (!javaHomeIsSet()) attributes.add("javaHome");
return "Cannot build ProcessInfo, some of required attributes are not set " + attributes;
}
}
}