jiazx0107@163.com
2023-10-25 dfb8e7111399231421ffa13b3c060de2283df5e1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.fzzy.gateway.sc2023.api;
 
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;
 
 
@Component
public class GatewayRemoteManager implements ApplicationContextAware {
 
    public static Map<String, GatewayRemoteService> remoteMap = new HashMap<>();
 
    public static Map<String, GatewaySyncService> syncMap = new HashMap<>();
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, GatewayRemoteService> serviceMap1 = applicationContext.getBeansOfType(GatewayRemoteService.class);
 
        for (String key : serviceMap1.keySet()) {
            remoteMap.put(serviceMap1.get(key).getProtocol(), serviceMap1.get(key));
        }
 
 
        Map<String, GatewaySyncService> serviceMap2 = applicationContext.getBeansOfType(GatewaySyncService.class);
 
        for (String key : serviceMap2.keySet()) {
            syncMap.put(serviceMap2.get(key).getProtocol(), serviceMap2.get(key));
        }
 
 
    }
 
 
    /**
     * 根据实现协议获取当前实现方法
     *
     * @param protocol
     * @return
     */
    public GatewayRemoteService getRemoteService(String protocol) {
        return remoteMap.get(protocol);
    }
 
 
    /**
     * 根据实现协议获取当前实现方法
     *
     * @param protocol
     * @return
     */
    public GatewaySyncService getSyncService(String protocol) {
        return syncMap.get(protocol);
    }
 
}