// Path: zing-client/src/main/java/org/zxc/zing/client/provider/ServiceProviderManager.java
// public class ServiceProviderManager {
// 
//     private static final Logger log = LoggerFactory.getLogger(ServiceProviderManager.class);
// 
//     private static Map<String, Set<ProviderInfo>> serviceServerMap = new ConcurrentHashMap<String, Set<ProviderInfo>>();
// 
//     static {
//         try {
//             bootstrap();
//         } catch (Exception e) {
//             log.error("client start error:"+e.getMessage(), e);
//             System.exit(1);
//         }
//     }
// 
//     public static void bootstrap() throws Exception {
//         ProviderStateListenerManager.getInstance().registerProviderStateListener(new ClientProviderStateListener());
//         RegistryManager.start();
//     }
// 
//     public static ProviderInfo getProvider(String serviceName) {
//         Set<ProviderInfo> providerInfoSet = serviceServerMap.get(serviceName);
// 
//         if (CollectionUtils.isEmpty(providerInfoSet)) {
//             throw new RuntimeException("no service provider found in registry");
//         }
// 
//         List<ProviderInfo> providerInfoList = Lists.newArrayList(providerInfoSet);
//         int randomIndex = new Random().nextInt(providerInfoList.size());
//         return providerInfoList.get(randomIndex);
//     }
// 
//     public static void initServerListOfService(String serviceName) {
//         log.debug("client start load "+serviceName+" service provider list from zk");
// 
//         List<ProviderInfo> providerInfoList = RegistryManager.loadServerListOfService(serviceName);
//         log.debug("client load "+serviceName+" service provider list from zk:"+providerInfoList);
// 
//         log.debug("client serviceServerMap before load:"+serviceServerMap);
// 
//         Set<ProviderInfo> providerInfoSet = new HashSet<ProviderInfo>(providerInfoList);
//         serviceServerMap.put(serviceName, providerInfoSet);
// 
//         log.debug("client serviceServerMap after load:"+serviceServerMap);
//     }
// }


import com.google.common.reflect.Reflection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zxc.zing.client.provider.ServiceProviderManager;
package org.zxc.zing.client.proxy;


/**
 * Created by xuanchen.zhao on 15-12-10.
 */
public class ServiceProxyBeanFactory {

    private static final Logger log = LoggerFactory.getLogger(ServiceProxyBeanFactory.class);


    public static Object getService(String serviceName) throws ClassNotFoundException {
        Class<?> serviceClass = Class.forName(serviceName);
// Path: zing-client/src/main/java/org/zxc/zing/client/provider/ServiceProviderManager.java
// public class ServiceProviderManager {
// 
//     private static final Logger log = LoggerFactory.getLogger(ServiceProviderManager.class);
// 
//     private static Map<String, Set<ProviderInfo>> serviceServerMap = new ConcurrentHashMap<String, Set<ProviderInfo>>();
// 
//     static {
//         try {
//             bootstrap();
//         } catch (Exception e) {
//             log.error("client start error:"+e.getMessage(), e);
//             System.exit(1);
//         }
//     }
// 
//     public static void bootstrap() throws Exception {
//         ProviderStateListenerManager.getInstance().registerProviderStateListener(new ClientProviderStateListener());
//         RegistryManager.start();
//     }
// 
//     public static ProviderInfo getProvider(String serviceName) {
//         Set<ProviderInfo> providerInfoSet = serviceServerMap.get(serviceName);
// 
//         if (CollectionUtils.isEmpty(providerInfoSet)) {
//             throw new RuntimeException("no service provider found in registry");
//         }
// 
//         List<ProviderInfo> providerInfoList = Lists.newArrayList(providerInfoSet);
//         int randomIndex = new Random().nextInt(providerInfoList.size());
//         return providerInfoList.get(randomIndex);
//     }
// 
//     public static void initServerListOfService(String serviceName) {
//         log.debug("client start load "+serviceName+" service provider list from zk");
// 
//         List<ProviderInfo> providerInfoList = RegistryManager.loadServerListOfService(serviceName);
//         log.debug("client load "+serviceName+" service provider list from zk:"+providerInfoList);
// 
//         log.debug("client serviceServerMap before load:"+serviceServerMap);
// 
//         Set<ProviderInfo> providerInfoSet = new HashSet<ProviderInfo>(providerInfoList);
//         serviceServerMap.put(serviceName, providerInfoSet);
// 
//         log.debug("client serviceServerMap after load:"+serviceServerMap);
//     }
// }


// Path: zing-client/src/main/java/org/zxc/zing/client/proxy/ServiceProxyBeanFactory.java
import com.google.common.reflect.Reflection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zxc.zing.client.provider.ServiceProviderManager;

package org.zxc.zing.client.proxy;


/**
 * Created by xuanchen.zhao on 15-12-10.
 */
public class ServiceProxyBeanFactory {

    private static final Logger log = LoggerFactory.getLogger(ServiceProxyBeanFactory.class);


    public static Object getService(String serviceName) throws ClassNotFoundException {
        Class<?> serviceClass = Class.forName(serviceName);
        ServiceProviderManager.initServerListOfService(serviceName);