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

org.glowroot.agent.model.ThreadInfoSnapshotBuilder Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.agent.model;

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.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
import java.util.ArrayList;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Builds instances of {@link org.glowroot.agent.model.ThreadInfoComponent.ThreadInfoSnapshot ThreadInfoSnapshot}.
 * Initialize attributes and then invoke {@link #build()} method to create
 * immutable instance.
 * 

{@code ThreadInfoSnapshotBuilder} is not thread safe and generally should not be stored in field or collection, * but used immediately to create instances. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ThreadInfoComponent.ThreadInfoSnapshot"}) @NotThreadSafe final class ThreadInfoSnapshotBuilder { private static final long OPT_BIT_THREAD_CPU_NANOS = 0x1L; private static final long OPT_BIT_THREAD_BLOCKED_MILLIS = 0x2L; private static final long OPT_BIT_THREAD_WAITED_MILLIS = 0x4L; private static final long OPT_BIT_THREAD_ALLOCATED_BYTES = 0x8L; private long optBits; private long threadCpuNanos; private long threadBlockedMillis; private long threadWaitedMillis; private long threadAllocatedBytes; /** * Fill builder with attribute values from provided {@link ThreadInfoComponent.ThreadInfoSnapshot} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final ThreadInfoSnapshotBuilder copyFrom(ThreadInfoComponent.ThreadInfoSnapshot instance) { Preconditions.checkNotNull(instance); threadCpuNanos(instance.threadCpuNanos()); threadBlockedMillis(instance.threadBlockedMillis()); threadWaitedMillis(instance.threadWaitedMillis()); threadAllocatedBytes(instance.threadAllocatedBytes()); return this; } /** * Initializes value for {@link ThreadInfoComponent.ThreadInfoSnapshot#threadCpuNanos() threadCpuNanos}. *

If not set, this attribute will have default value returned by initializer of {@link ThreadInfoComponent.ThreadInfoSnapshot#threadCpuNanos() threadCpuNanos}. * @param threadCpuNanos value for threadCpuNanos * @return {@code this} builder for chained invocation */ public final ThreadInfoSnapshotBuilder threadCpuNanos(long threadCpuNanos) { this.threadCpuNanos = threadCpuNanos; optBits |= OPT_BIT_THREAD_CPU_NANOS; return this; } /** * Initializes value for {@link ThreadInfoComponent.ThreadInfoSnapshot#threadBlockedMillis() threadBlockedMillis}. *

If not set, this attribute will have default value returned by initializer of {@link ThreadInfoComponent.ThreadInfoSnapshot#threadBlockedMillis() threadBlockedMillis}. * @param threadBlockedMillis value for threadBlockedMillis * @return {@code this} builder for chained invocation */ public final ThreadInfoSnapshotBuilder threadBlockedMillis(long threadBlockedMillis) { this.threadBlockedMillis = threadBlockedMillis; optBits |= OPT_BIT_THREAD_BLOCKED_MILLIS; return this; } /** * Initializes value for {@link ThreadInfoComponent.ThreadInfoSnapshot#threadWaitedMillis() threadWaitedMillis}. *

If not set, this attribute will have default value returned by initializer of {@link ThreadInfoComponent.ThreadInfoSnapshot#threadWaitedMillis() threadWaitedMillis}. * @param threadWaitedMillis value for threadWaitedMillis * @return {@code this} builder for chained invocation */ public final ThreadInfoSnapshotBuilder threadWaitedMillis(long threadWaitedMillis) { this.threadWaitedMillis = threadWaitedMillis; optBits |= OPT_BIT_THREAD_WAITED_MILLIS; return this; } /** * Initializes value for {@link ThreadInfoComponent.ThreadInfoSnapshot#threadAllocatedBytes() threadAllocatedBytes}. *

If not set, this attribute will have default value returned by initializer of {@link ThreadInfoComponent.ThreadInfoSnapshot#threadAllocatedBytes() threadAllocatedBytes}. * @param threadAllocatedBytes value for threadAllocatedBytes * @return {@code this} builder for chained invocation */ public final ThreadInfoSnapshotBuilder threadAllocatedBytes(long threadAllocatedBytes) { this.threadAllocatedBytes = threadAllocatedBytes; optBits |= OPT_BIT_THREAD_ALLOCATED_BYTES; return this; } /** * Builds new {@link org.glowroot.agent.model.ThreadInfoComponent.ThreadInfoSnapshot ThreadInfoSnapshot}. * @return immutable instance of ThreadInfoSnapshot * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ThreadInfoComponent.ThreadInfoSnapshot build() throws IllegalStateException { return new ThreadInfoSnapshotBuilder.ImmutableThreadInfoSnapshot(this); } private boolean threadCpuNanosIsSet() { return (optBits & OPT_BIT_THREAD_CPU_NANOS) != 0; } private boolean threadBlockedMillisIsSet() { return (optBits & OPT_BIT_THREAD_BLOCKED_MILLIS) != 0; } private boolean threadWaitedMillisIsSet() { return (optBits & OPT_BIT_THREAD_WAITED_MILLIS) != 0; } private boolean threadAllocatedBytesIsSet() { return (optBits & OPT_BIT_THREAD_ALLOCATED_BYTES) != 0; } /** * Immutable implementation of {@link ThreadInfoComponent.ThreadInfoSnapshot}. *

* Use builder to create immutable instances: * {@code new ThreadInfoSnapshotBuilder()}. */ @Immutable private static final class ImmutableThreadInfoSnapshot extends ThreadInfoComponent.ThreadInfoSnapshot { private final long threadCpuNanos; private final long threadBlockedMillis; private final long threadWaitedMillis; private final long threadAllocatedBytes; private ImmutableThreadInfoSnapshot(ThreadInfoSnapshotBuilder builder) { if (builder.threadCpuNanosIsSet()) { initShim.threadCpuNanos(builder.threadCpuNanos); } if (builder.threadBlockedMillisIsSet()) { initShim.threadBlockedMillis(builder.threadBlockedMillis); } if (builder.threadWaitedMillisIsSet()) { initShim.threadWaitedMillis(builder.threadWaitedMillis); } if (builder.threadAllocatedBytesIsSet()) { initShim.threadAllocatedBytes(builder.threadAllocatedBytes); } this.threadCpuNanos = initShim.threadCpuNanos(); this.threadBlockedMillis = initShim.threadBlockedMillis(); this.threadWaitedMillis = initShim.threadWaitedMillis(); this.threadAllocatedBytes = initShim.threadAllocatedBytes(); this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private volatile InitShim initShim = new InitShim(); private final class InitShim { private long threadCpuNanos; private byte threadCpuNanosStage; long threadCpuNanos() { if (threadCpuNanosStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (threadCpuNanosStage == STAGE_UNINITIALIZED) { threadCpuNanosStage = STAGE_INITIALIZING; this.threadCpuNanos = ImmutableThreadInfoSnapshot.super.threadCpuNanos(); threadCpuNanosStage = STAGE_INITIALIZED; } return threadCpuNanos; } long threadCpuNanos(long value) { this.threadCpuNanos = value; threadCpuNanosStage = STAGE_INITIALIZED; return value; } private long threadBlockedMillis; private byte threadBlockedMillisStage; long threadBlockedMillis() { if (threadBlockedMillisStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (threadBlockedMillisStage == STAGE_UNINITIALIZED) { threadBlockedMillisStage = STAGE_INITIALIZING; this.threadBlockedMillis = ImmutableThreadInfoSnapshot.super.threadBlockedMillis(); threadBlockedMillisStage = STAGE_INITIALIZED; } return threadBlockedMillis; } long threadBlockedMillis(long value) { this.threadBlockedMillis = value; threadBlockedMillisStage = STAGE_INITIALIZED; return value; } private long threadWaitedMillis; private byte threadWaitedMillisStage; long threadWaitedMillis() { if (threadWaitedMillisStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (threadWaitedMillisStage == STAGE_UNINITIALIZED) { threadWaitedMillisStage = STAGE_INITIALIZING; this.threadWaitedMillis = ImmutableThreadInfoSnapshot.super.threadWaitedMillis(); threadWaitedMillisStage = STAGE_INITIALIZED; } return threadWaitedMillis; } long threadWaitedMillis(long value) { this.threadWaitedMillis = value; threadWaitedMillisStage = STAGE_INITIALIZED; return value; } private long threadAllocatedBytes; private byte threadAllocatedBytesStage; long threadAllocatedBytes() { if (threadAllocatedBytesStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (threadAllocatedBytesStage == STAGE_UNINITIALIZED) { threadAllocatedBytesStage = STAGE_INITIALIZING; this.threadAllocatedBytes = ImmutableThreadInfoSnapshot.super.threadAllocatedBytes(); threadAllocatedBytesStage = STAGE_INITIALIZED; } return threadAllocatedBytes; } long threadAllocatedBytes(long value) { this.threadAllocatedBytes = value; threadAllocatedBytesStage = STAGE_INITIALIZED; return value; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList();; if (threadCpuNanosStage == STAGE_INITIALIZING) attributes.add("threadCpuNanos"); if (threadBlockedMillisStage == STAGE_INITIALIZING) attributes.add("threadBlockedMillis"); if (threadWaitedMillisStage == STAGE_INITIALIZING) attributes.add("threadWaitedMillis"); if (threadAllocatedBytesStage == STAGE_INITIALIZING) attributes.add("threadAllocatedBytes"); return "Cannot build ThreadInfoSnapshot, attribute initializers form cycle" + attributes; } } /** * @return value of {@code threadCpuNanos} attribute */ @JsonProperty @Override long threadCpuNanos() { return initShim != null ? initShim.threadCpuNanos() : threadCpuNanos; } /** * @return value of {@code threadBlockedMillis} attribute */ @JsonProperty @Override long threadBlockedMillis() { return initShim != null ? initShim.threadBlockedMillis() : threadBlockedMillis; } /** * @return value of {@code threadWaitedMillis} attribute */ @JsonProperty @Override long threadWaitedMillis() { return initShim != null ? initShim.threadWaitedMillis() : threadWaitedMillis; } /** * @return value of {@code threadAllocatedBytes} attribute */ @JsonProperty @Override long threadAllocatedBytes() { return initShim != null ? initShim.threadAllocatedBytes() : threadAllocatedBytes; } /** * This instance is equal to instances of {@code ImmutableThreadInfoSnapshot} 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 ImmutableThreadInfoSnapshot && equalTo((ImmutableThreadInfoSnapshot) another); } private boolean equalTo(ImmutableThreadInfoSnapshot another) { return threadCpuNanos == another.threadCpuNanos && threadBlockedMillis == another.threadBlockedMillis && threadWaitedMillis == another.threadWaitedMillis && threadAllocatedBytes == another.threadAllocatedBytes; } /** * Computes hash code from attributes: {@code threadCpuNanos}, {@code threadBlockedMillis}, {@code threadWaitedMillis}, {@code threadAllocatedBytes}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Longs.hashCode(threadCpuNanos); h = h * 17 + Longs.hashCode(threadBlockedMillis); h = h * 17 + Longs.hashCode(threadWaitedMillis); h = h * 17 + Longs.hashCode(threadAllocatedBytes); return h; } /** * Prints immutable value {@code ThreadInfoSnapshot...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("ThreadInfoSnapshot") .add("threadCpuNanos", threadCpuNanos) .add("threadBlockedMillis", threadBlockedMillis) .add("threadWaitedMillis", threadWaitedMillis) .add("threadAllocatedBytes", threadAllocatedBytes) .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 threadCpuNanos; @JsonProperty @Nullable Long threadBlockedMillis; @JsonProperty @Nullable Long threadWaitedMillis; @JsonProperty @Nullable Long threadAllocatedBytes; } /** * @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 ThreadInfoComponent.ThreadInfoSnapshot fromJson(Json json) { ThreadInfoSnapshotBuilder builder = new ThreadInfoSnapshotBuilder(); if (json.threadCpuNanos != null) { builder.threadCpuNanos(json.threadCpuNanos); } if (json.threadBlockedMillis != null) { builder.threadBlockedMillis(json.threadBlockedMillis); } if (json.threadWaitedMillis != null) { builder.threadWaitedMillis(json.threadWaitedMillis); } if (json.threadAllocatedBytes != null) { builder.threadAllocatedBytes(json.threadAllocatedBytes); } return builder.build(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy