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

org.glowroot.agent.live.LiveAggregateRepositoryImpl Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.glowroot.agent.live;

import java.io.IOException;
import java.util.List;

import javax.annotation.Nullable;

import org.glowroot.agent.shaded.google.common.collect.Lists;

import org.glowroot.agent.impl.AggregateIntervalCollector;
import org.glowroot.agent.impl.Aggregator;
import org.glowroot.agent.shaded.glowroot.common.live.LiveAggregateRepository;
import org.glowroot.agent.shaded.glowroot.common.model.OverallErrorSummaryCollector;
import org.glowroot.agent.shaded.glowroot.common.model.OverallSummaryCollector;
import org.glowroot.agent.shaded.glowroot.common.model.ProfileCollector;
import org.glowroot.agent.shaded.glowroot.common.model.QueryCollector;
import org.glowroot.agent.shaded.glowroot.common.model.ServiceCallCollector;
import org.glowroot.agent.shaded.glowroot.common.model.TransactionErrorSummaryCollector;
import org.glowroot.agent.shaded.glowroot.common.model.TransactionSummaryCollector;

public class LiveAggregateRepositoryImpl implements LiveAggregateRepository {

    private final Aggregator aggregator;

    public LiveAggregateRepositoryImpl(Aggregator aggregator) {
        this.aggregator = aggregator;
    }

    @Override
    public long mergeInOverallSummary(OverallSummaryCollector collector, OverallQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInOverallSummary(collector, query.transactionType());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInTransactionSummaries(TransactionSummaryCollector collector,
            OverallQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInTransactionSummaries(collector, query.transactionType());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInOverallErrorSummary(OverallErrorSummaryCollector collector,
            OverallQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInOverallErrorSummary(collector, query.transactionType());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInTransactionErrorSummaries(TransactionErrorSummaryCollector collector,
            OverallQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInTransactionErrorSummaries(collector, query.transactionType());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public @Nullable LiveResult getOverviewAggregates(TransactionQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        if (intervalCollectors.isEmpty()) {
            return null;
        }
        List overviewAggregates = Lists.newArrayList();
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            OverviewAggregate overviewAggregate = intervalCollector
                    .getOverviewAggregate(query.transactionType(), query.transactionName());
            if (overviewAggregate != null) {
                overviewAggregates.add(overviewAggregate);
            }
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return new LiveResult(overviewAggregates, revisedTo);
    }

    @Override
    public @Nullable LiveResult getPercentileAggregates(
            TransactionQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        if (intervalCollectors.isEmpty()) {
            return null;
        }
        List percentileAggregates = Lists.newArrayList();
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            PercentileAggregate percentileAggregate = intervalCollector
                    .getPercentileAggregate(query.transactionType(), query.transactionName());
            if (percentileAggregate != null) {
                percentileAggregates.add(percentileAggregate);
            }
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return new LiveResult(percentileAggregates, revisedTo);
    }

    @Override
    public @Nullable LiveResult getThroughputAggregates(
            TransactionQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        if (intervalCollectors.isEmpty()) {
            return null;
        }
        List throughputAggregates = Lists.newArrayList();
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            ThroughputAggregate throughputAggregate = intervalCollector
                    .getThroughputAggregate(query.transactionType(), query.transactionName());
            if (throughputAggregate != null) {
                throughputAggregates.add(throughputAggregate);
            }
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return new LiveResult(throughputAggregates, revisedTo);
    }

    @Override
    public long mergeInQueries(QueryCollector collector, TransactionQuery query)
            throws IOException {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInQueries(collector, query.transactionType(),
                    query.transactionName());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInServiceCalls(ServiceCallCollector collector, TransactionQuery query)
            throws IOException {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInServiceCalls(collector, query.transactionType(),
                    query.transactionName());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInMainThreadProfiles(ProfileCollector collector, TransactionQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInMainThreadProfiles(collector, query.transactionType(),
                    query.transactionName());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }

    @Override
    public long mergeInAuxThreadProfiles(ProfileCollector collector, TransactionQuery query) {
        List intervalCollectors =
                aggregator.getOrderedIntervalCollectorsInRange(query.from(), query.to());
        long revisedTo = query.to();
        for (AggregateIntervalCollector intervalCollector : intervalCollectors) {
            intervalCollector.mergeInAuxThreadProfiles(collector, query.transactionType(),
                    query.transactionName());
            revisedTo = Math.min(revisedTo, intervalCollector.getCaptureTime() - 1);
        }
        return revisedTo;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy