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

cdc.perfs.snapshot.SnapshotEnvironment Maven / Gradle / Ivy

There is a newer version: 0.52.0
Show newest version
package cdc.perfs.snapshot;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

import cdc.perfs.Context;
import cdc.perfs.Environment;
import cdc.perfs.EnvironmentKind;
import cdc.perfs.api.Source;
import cdc.perfs.core.AbstractContext;
import cdc.perfs.core.AbstractEnvironment;

/**
 * Implementation of Environment for snapshots.
 *
 * @author Damien Carbonne
 *
 */
public final class SnapshotEnvironment extends AbstractEnvironment {
    private final List contexts = new ArrayList<>();
    private final long elapsedNanos;

    /**
     * Create an empty SnapshotEnvironment.
     * 

* This is intended for deserialization. * * @param refNanos The reference absolute nano time. * @param refInstant The reference date. * @param elapsedNanos The duration of this environment. */ public SnapshotEnvironment(long refNanos, Instant refInstant, long elapsedNanos) { super(refNanos, refInstant); this.elapsedNanos = elapsedNanos; } /** * Create a SnapshotEnvironment by cloning another Environment. * * @param environment The environment to clone. */ public SnapshotEnvironment(Environment environment) { super(environment.getReferenceNanos(), environment.getReferenceInstant()); this.elapsedNanos = environment.getElapsedNanos(); // Clone sources for (final Source source : environment.getSources()) { final Source clone = getSource(source.getName()); clone.setMaxLevel(source.getMaxLevel()); } // Clone contexts for (final Context context : environment.getContexts()) { createContext(context); } } @Override public final EnvironmentKind getKind() { return EnvironmentKind.SNAPSHOT; } @Override public final List getContexts() { return contexts; } @Override public final void removeDeadContexts() { final ArrayList deads = new ArrayList<>(); for (final SnapshotContext context : contexts) { if (!context.isAlive()) { deads.add(context); } } contexts.removeAll(deads); } @Override public long getCurrentNanos() { return refNanos + elapsedNanos; } @Override public long getElapsedNanos() { return elapsedNanos; } private SnapshotContext createContext(Context context) { final SnapshotContext clone = new SnapshotContext(this, context); contexts.add(clone); return clone; } public SnapshotContext createContext(int id, String name, boolean alive) { final SnapshotContext result = new SnapshotContext(this, id, name, alive); contexts.add(result); return result; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy