Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015 Groupon.com
*
* 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 com.arpnetworking.metrics.mad;
import com.arpnetworking.logback.annotations.LogValue;
import com.arpnetworking.metrics.incubator.PeriodicMetrics;
import com.arpnetworking.metrics.mad.model.Record;
import com.arpnetworking.steno.LogValueMapFactory;
import com.arpnetworking.steno.Logger;
import com.arpnetworking.steno.LoggerFactory;
import com.arpnetworking.tsdcore.model.Key;
import com.google.common.collect.Lists;
import org.apache.pekko.actor.AbstractActor;
import org.apache.pekko.actor.AbstractActorWithTimers;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.PoisonPill;
import org.apache.pekko.actor.Props;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.TreeMap;
/**
* Actor that aggregates a particular slice of the data set over time and metric.
*
* @author Ville Koskela (ville dot koskela at inscopemetrics dot io)
*/
/* package private */ final class PeriodWorker extends AbstractActorWithTimers {
/**
* Public constructor. Use {@code props} to create instances.
*
* @param aggregator The {@code ActorRef} to the aggregator.
* @param key The key for the data slice.
* @param period The period for the data slice.
* @param idleTimeout The idle timeout for the data slice.
* @param bucketBuilder The {@code Bucket.Builder} to use to create buckets.
* @param periodicMetrics The {@code PeriodicMetrics} instance to record metrics.
*/
public static Props props(
final ActorRef aggregator,
final Key key,
final Duration period,
final Duration idleTimeout,
final Bucket.Builder bucketBuilder,
final PeriodicMetrics periodicMetrics) {
return Props.create(
PeriodWorker.class,
() -> new PeriodWorker(aggregator, key, period, idleTimeout, bucketBuilder, periodicMetrics));
}
/**
* Public constructor. Since this is an {@code Actor} this method should not be
* called directly, but instead you should use {@code PeriodWorker::props}.
*/
PeriodWorker(
final ActorRef aggregator,
final Key key,
final Duration period,
final Duration idleTimeout,
final Bucket.Builder bucketBuilder,
final PeriodicMetrics periodicMetrics) {
_aggregator = aggregator;
_key = key;
_period = period;
_idleTimeout = idleTimeout;
_bucketBuilder = bucketBuilder;
_periodicMetrics = periodicMetrics;
_hasReceivedRecords = false;
_nextScheduledRotationTime = Optional.empty();
}
@Override
public void preStart() throws Exception {
super.preStart();
_periodicMetrics.recordCounter("actors/period_worker/started", 1);
timers().startTimerAtFixedRate(
IDLE_CHECK_TIMER,
IDLE_CHECK_MESSAGE,
_idleTimeout);
}
@Override
public void postStop() throws Exception {
_periodicMetrics.recordCounter("actors/period_worker/stopped", 1);
timers().cancel(IDLE_CHECK_TIMER);
if (timers().isTimerActive(ROTATE_TIMER_KEY)) {
timers().cancel(ROTATE_TIMER_KEY);
_nextScheduledRotationTime = Optional.empty();
// Force a rotation of ALL buckets using epoch zero
performRotation(ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.systemDefault()));
LOGGER.debug()
.setMessage("Shutdown forced rotations")
.log();
}
super.postStop();
}
@Override
public void preRestart(final Throwable reason, final Optional