jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.ld.igds.quantity.io;
 
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 接口Api所有协议的协议类,根据不同的协议配置调用不同的协议实现
 *
 * @author jiazx
 */
@Component(QuantityRemoteManager.BEAN_ID)
public class QuantityRemoteManager implements ApplicationContextAware {
 
    public static final String BEAN_ID = "quantity.remoteManager";
 
    public static Map<String, RemoteQuantityService> remoteQuantityMap = new HashMap<>();
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
 
        Map<String, RemoteQuantityService> quantityMap = applicationContext
                .getBeansOfType(RemoteQuantityService.class);
        for (String key : quantityMap.keySet()) {
            remoteQuantityMap.put(quantityMap.get(key).getProtocol(),
                    quantityMap.get(key));
        }
 
    }
 
    /**
     * 根据协议获取实现
     *
     * @param protocol
     * @return
     */
    public RemoteQuantityService getRemoteQuantityService(String protocol) {
        return remoteQuantityMap.get(protocol);
    }
 
}