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

org.glowroot.agent.model.ThreadInfoDataBuilder 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.ThreadInfoData ThreadInfoData}.
 * Initialize attributes and then invoke {@link #build()} method to create
 * immutable instance.
 * 

{@code ThreadInfoDataBuilder} 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", "ThreadInfoData"}) @NotThreadSafe public final class ThreadInfoDataBuilder { private static final long OPT_BIT_THREAD_CPU_NANOS = 0x1L; private static final long OPT_BIT_THREAD_BLOCKED_NANOS = 0x2L; private static final long OPT_BIT_THREAD_WAITED_NANOS = 0x4L; private static final long OPT_BIT_THREAD_ALLOCATED_BYTES = 0x8L; private long optBits; private long threadCpuNanos; private long threadBlockedNanos; private long threadWaitedNanos; private long threadAllocatedBytes; /** * Fill builder with attribute values from provided {@link ThreadInfoData} 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 ThreadInfoDataBuilder copyFrom(ThreadInfoData instance) { Preconditions.checkNotNull(instance); threadCpuNanos(instance.threadCpuNanos()); threadBlockedNanos(instance.threadBlockedNanos()); threadWaitedNanos(instance.threadWaitedNanos()); threadAllocatedBytes(instance.threadAllocatedBytes()); return this; } /** * Initializes value for {@link ThreadInfoData#threadCpuNanos() threadCpuNanos}. *

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

If not set, this attribute will have default value returned by initializer of {@link ThreadInfoData#threadBlockedNanos() threadBlockedNanos}. * @param threadBlockedNanos value for threadBlockedNanos * @return {@code this} builder for chained invocation */ public final ThreadInfoDataBuilder threadBlockedNanos(long threadBlockedNanos) { this.threadBlockedNanos = threadBlockedNanos; optBits |= OPT_BIT_THREAD_BLOCKED_NANOS; return this; } /** * Initializes value for {@link ThreadInfoData#threadWaitedNanos() threadWaitedNanos}. *

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

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

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy