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

com.proofpoint.http.client.balancing.HttpServiceBalancerUriConfig Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2021 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.balancing;

import com.google.common.collect.ForwardingMultiset;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.Multiset;
import com.proofpoint.configuration.Config;
import com.proofpoint.configuration.ConfigDescription;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

import java.net.URI;
import java.util.Arrays;
import java.util.Collection;

import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset;

public class HttpServiceBalancerUriConfig
{
    private UriMultiset uris;

    @Config("uri")
    @ConfigDescription("Set of URIs for the service")
    public HttpServiceBalancerUriConfig setUris(UriMultiset uris)
    {
        this.uris = uris;
        return this;
    }

    @NotNull
    @NotEmpty
    public Collection getUris()
    {
        return uris;
    }

    public static final class UriMultiset extends ForwardingMultiset
    {
        private final Multiset delegate;

        private UriMultiset(Multiset delegate)
        {
            this.delegate = ImmutableMultiset.copyOf(delegate);
        }

        public static UriMultiset of(URI... uris)
        {
            return new UriMultiset(ImmutableMultiset.copyOf(uris));
        }

        public static UriMultiset valueOf(String string)
        {
            ImmutableMultiset uris = Arrays.stream(string.split("\\s*,\\s*"))
                    .map(URI::create)
                    .collect(toImmutableMultiset());
            return new UriMultiset(uris);
        }

        @Override
        protected Multiset delegate()
        {
            return delegate;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy