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

com.yahoo.bard.webservice.application.DimensionValueLoadTask Maven / Gradle / Ivy

Go to download

Fili web service library provides core capabilities for RESTful aggregation navigation, query planning and metadata

There is a newer version: 1.1.13
Show newest version
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.application;

import com.yahoo.bard.webservice.config.SystemConfig;
import com.yahoo.bard.webservice.config.SystemConfigProvider;
import com.yahoo.bard.webservice.druid.client.FailureCallback;
import com.yahoo.bard.webservice.druid.client.HttpErrorCallback;

import org.joda.time.DateTime;

import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import javax.inject.Singleton;

/**
 * DimensionLoaderTask takes a collection of {@link DimensionValueLoader} to update the values for dimensions.
 */
@Singleton
public class DimensionValueLoadTask extends LoadTask {
    private static final SystemConfig SYSTEM_CONFIG = SystemConfigProvider.getInstance();

    public static final String LOADER_TIMER_DURATION =
            SYSTEM_CONFIG.getPackageVariableName("druid_dim_loader_timer_duration");
    public static final String LOADER_TIMER_DELAY =
            SYSTEM_CONFIG.getPackageVariableName("druid_dim_loader_timer_delay");

    private final AtomicReference lastRunTimestamp;
    private final Collection dimensionRowProviders;

    /**
     * DimensionLoaderTask tells all of the {@link DimensionValueLoader}s to update and add values to the dimension
     * cache.
     *
     * @param dimensionRowProviders  A Collection of {@link DimensionValueLoader} to initialize dimensions.
     */
    public DimensionValueLoadTask(Collection dimensionRowProviders) {
        super(
                DimensionValueLoadTask.class.getSimpleName(),
                SYSTEM_CONFIG.getLongProperty(LOADER_TIMER_DELAY, 0),
                SYSTEM_CONFIG.getLongProperty(
                        LOADER_TIMER_DURATION,
                        TimeUnit.MINUTES.toMillis(1)
                )
        );

        this.dimensionRowProviders = dimensionRowProviders;
        lastRunTimestamp = new AtomicReference<>();

        HttpErrorCallback errorCallback = getErrorCallback();
        FailureCallback failureCallback = getFailureCallback();

        dimensionRowProviders.forEach(dimensionRowProvider -> {
            dimensionRowProvider.setErrorCallback(errorCallback);
            dimensionRowProvider.setFailureCallback(failureCallback);
        });
    }

    @Override
    public void run() {
        dimensionRowProviders.forEach(DimensionValueLoader::load);
        // tell all dimensionRowProviders to load
        lastRunTimestamp.set(DateTime.now());
    }

    public DateTime getLastRunTimestamp() {
        return lastRunTimestamp.get();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy