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

io.appform.ranger.client.AbstractRangerClient Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2024 Authors, Flipkart Internet Pvt. Ltd.
 *
 * 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 io.appform.ranger.client;

import io.appform.ranger.client.utils.CriteriaUtils;
import io.appform.ranger.core.finder.ServiceFinder;
import io.appform.ranger.core.model.ServiceNode;
import io.appform.ranger.core.model.ServiceNodeSelector;
import io.appform.ranger.core.model.ServiceRegistry;
import io.appform.ranger.core.model.ShardSelector;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

@SuperBuilder
public abstract class AbstractRangerClient> implements RangerClient {

    private final Predicate initialCriteria;
    private final boolean alwaysUseInitialCriteria;

    public abstract ServiceFinder getServiceFinder();

    @Override
    public Optional> getNode() {
        return getNode(initialCriteria);
    }

    @Override
    public Optional> getNode(Predicate criteria) {
        return getNode(criteria, null);
    }

    @Override
    public Optional> getNode(
            Predicate criteria, ShardSelector shardSelector) {
        return getNode(criteria, shardSelector, null);
    }

    @Override
    public Optional> getNode(
            Predicate criteria,
            ShardSelector shardSelector,
            ServiceNodeSelector nodeSelector) {
        return getServiceFinder().get(CriteriaUtils.getCriteria(alwaysUseInitialCriteria, initialCriteria, criteria),
                                      shardSelector,
                                      nodeSelector);
    }

    @Override
    public List> getAllNodes() {
        return getAllNodes(initialCriteria);
    }

    @Override
    public List> getAllNodes(Predicate criteria) {
        return getAllNodes(criteria, null);
    }

    @Override
    public List> getAllNodes(
            Predicate criteria, ShardSelector shardSelector) {
        return getServiceFinder().getAll(CriteriaUtils.getCriteria(alwaysUseInitialCriteria,
                                                                   initialCriteria,
                                                                   criteria),
                                         shardSelector);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy