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

org.cattleframework.cloud.discovery.reflect.DiscoveryClientProxy Maven / Gradle / Ivy

There is a newer version: 1.0.1-M5
Show newest version
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * 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 org.cattleframework.cloud.discovery.reflect;

import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.collections4.CollectionUtils;
import org.cattleframework.cloud.discovery.event.DiscoveryClientEvent;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;

import com.google.common.reflect.Reflection;

/**
 * 服务发现客户端代理
 * 
 * @author orange
 *
 */
public interface DiscoveryClientProxy extends DiscoveryClient {

    /**
     * 获得目标服务发现客户端
     * 
     * @return 服务发现客户端
     */
    DiscoveryClient getTargetDiscoveryClient();

    /**
     * 获得服务发现客户端代理
     * 
     * @param beanFactory Bean工厂
     * @param target      目标服务发现客户端
     * @return 服务发现客户端代理
     */
    public static DiscoveryClient getDiscoveryClientProxy(ConfigurableListableBeanFactory beanFactory,
	    DiscoveryClient target) {
	List discoveryClientEvents = beanFactory.getBeansOfType(DiscoveryClientEvent.class)
		.values().stream().collect(Collectors.toList());
	if (CollectionUtils.isNotEmpty(discoveryClientEvents)) {
	    AnnotationAwareOrderComparator.sort(discoveryClientEvents);
	}
	return Reflection.newProxy(DiscoveryClientProxy.class,
		new DiscoveryClientInvocationHandler(target, discoveryClientEvents));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy