// Path: src/main/java/com/flipkart/ranger/model/Deserializer.java
// public interface Deserializer<T> {
//     public ServiceNode<T> deserialize(final byte[] data);
// }
// 
// Path: src/main/java/com/flipkart/ranger/model/ServiceRegistry.java
// public abstract class ServiceRegistry<T> {
//     private final Service service;
//     private final Deserializer<T> deserializer;
// 
//     protected ServiceRegistry(Service service, Deserializer<T> deserializer) {
//         this.service = service;
//         this.deserializer = deserializer;
//     }
// 
//     public abstract void start() throws Exception;
// 
//     public abstract void stop() throws Exception;
// 
//     public abstract void nodes(List<ServiceNode<T>> nodes);
// 
//     public Service getService() {
//         return service;
//     }
// 
//     public Deserializer<T> getDeserializer() {
//         return deserializer;
//     }
// }
// 
// Path: src/main/java/com/flipkart/ranger/model/ShardSelector.java
// public interface ShardSelector<T, ServiceRegistryType extends ServiceRegistry<T>> {
//     List<ServiceNode<T>> nodes(T criteria, ServiceRegistryType serviceRegistry);
// }


import com.flipkart.ranger.model.Deserializer;
import com.flipkart.ranger.model.ServiceNodeSelector;
import com.flipkart.ranger.model.ServiceRegistry;
import com.flipkart.ranger.model.ShardSelector;
import com.google.common.base.Preconditions;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * Copyright 2015 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 com.flipkart.ranger.finder;


public abstract class BaseServiceFinderBuilder<T, RegistryType extends ServiceRegistry<T>, FinderType extends ServiceFinder<T, RegistryType>> {
    private static final Logger LOGGER = LoggerFactory.getLogger(BaseServiceFinderBuilder.class);

    private String namespace;
    private String serviceName;
    private CuratorFramework curatorFramework;
    private String connectionString;
    private int nodeRefreshIntervalMs;
    private boolean disableWatchers;
    private Deserializer<T> deserializer;
    private ShardSelector<T, RegistryType> shardSelector;
    private ServiceNodeSelector<T> nodeSelector = new RandomServiceNodeSelector<>();

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withNamespace(final String namespace) {
        this.namespace = namespace;
        return this;
    }

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withServiceName(final String serviceName) {
        this.serviceName = serviceName;
        return this;
    }

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withCuratorFramework(CuratorFramework curatorFramework) {
        this.curatorFramework = curatorFramework;
// Path: src/main/java/com/flipkart/ranger/model/Deserializer.java
// public interface Deserializer<T> {
//     public ServiceNode<T> deserialize(final byte[] data);
// }
// 
// Path: src/main/java/com/flipkart/ranger/model/ServiceRegistry.java
// public abstract class ServiceRegistry<T> {
//     private final Service service;
//     private final Deserializer<T> deserializer;
// 
//     protected ServiceRegistry(Service service, Deserializer<T> deserializer) {
//         this.service = service;
//         this.deserializer = deserializer;
//     }
// 
//     public abstract void start() throws Exception;
// 
//     public abstract void stop() throws Exception;
// 
//     public abstract void nodes(List<ServiceNode<T>> nodes);
// 
//     public Service getService() {
//         return service;
//     }
// 
//     public Deserializer<T> getDeserializer() {
//         return deserializer;
//     }
// }
// 
// Path: src/main/java/com/flipkart/ranger/model/ShardSelector.java
// public interface ShardSelector<T, ServiceRegistryType extends ServiceRegistry<T>> {
//     List<ServiceNode<T>> nodes(T criteria, ServiceRegistryType serviceRegistry);
// }


// Path: src/main/java/com/flipkart/ranger/finder/BaseServiceFinderBuilder.java
import com.flipkart.ranger.model.Deserializer;
import com.flipkart.ranger.model.ServiceNodeSelector;
import com.flipkart.ranger.model.ServiceRegistry;
import com.flipkart.ranger.model.ShardSelector;
import com.google.common.base.Preconditions;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Copyright 2015 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 com.flipkart.ranger.finder;


public abstract class BaseServiceFinderBuilder<T, RegistryType extends ServiceRegistry<T>, FinderType extends ServiceFinder<T, RegistryType>> {
    private static final Logger LOGGER = LoggerFactory.getLogger(BaseServiceFinderBuilder.class);

    private String namespace;
    private String serviceName;
    private CuratorFramework curatorFramework;
    private String connectionString;
    private int nodeRefreshIntervalMs;
    private boolean disableWatchers;
    private Deserializer<T> deserializer;
    private ShardSelector<T, RegistryType> shardSelector;
    private ServiceNodeSelector<T> nodeSelector = new RandomServiceNodeSelector<>();

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withNamespace(final String namespace) {
        this.namespace = namespace;
        return this;
    }

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withServiceName(final String serviceName) {
        this.serviceName = serviceName;
        return this;
    }

    public BaseServiceFinderBuilder<T, RegistryType, FinderType> withCuratorFramework(CuratorFramework curatorFramework) {
        this.curatorFramework = curatorFramework;
        return this;