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

com.proofpoint.http.client.StaticHttpServiceBalancerProvider Maven / Gradle / Ivy

There is a newer version: 3.23
Show newest version
/*
 * Copyright 2015 Proofpoint, Inc.
 *
 * 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.proofpoint.http.client;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.proofpoint.http.client.balancing.HttpServiceBalancer;
import com.proofpoint.http.client.balancing.HttpServiceBalancerImpl;
import com.proofpoint.http.client.balancing.HttpServiceBalancerStats;
import com.proofpoint.reporting.ReportCollectionFactory;
import com.proofpoint.reporting.ReportExporter;

import java.net.URI;
import java.util.Map;
import java.util.Set;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

class StaticHttpServiceBalancerProvider implements Provider
{
    private final String type;
    private final Set baseUris;
    private ReportExporter reportExporter;
    private ReportCollectionFactory reportCollectionFactory;

    StaticHttpServiceBalancerProvider(String type, Set baseUris)
    {
        this.type = requireNonNull(type, "type is null");
        this.baseUris = ImmutableSet.copyOf(baseUris);
    }

    @Inject
    public void setReportExporter(ReportExporter reportExporter)
    {
        requireNonNull(reportExporter, "reportExporter is null");
        this.reportExporter = reportExporter;
    }

    @Inject
    public void setReportCollectionFactory(ReportCollectionFactory reportCollectionFactory)
    {
        requireNonNull(reportCollectionFactory, "reportCollectionFactory is null");
        this.reportCollectionFactory = reportCollectionFactory;
    }

    @Override
    public HttpServiceBalancer get()
    {
        requireNonNull(type, "type is null");
        requireNonNull(baseUris, "baseUris is null");

        Map tags = ImmutableMap.of("serviceType", type);
        HttpServiceBalancerStats httpServiceBalancerStats = reportCollectionFactory.createReportCollection(HttpServiceBalancerStats.class, false, "ServiceClient", tags);
        HttpServiceBalancerImpl balancer = new HttpServiceBalancerImpl(format("type=[%s], static", type), httpServiceBalancerStats);
        reportExporter.export(balancer, false, "ServiceClient", tags);
        balancer.updateHttpUris(baseUris);
        return balancer;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy