2021与蓝度共同重构项目,服务端
liuhaonan
2022-09-26 17e18047a47f43187f590a045b1aebe130459292
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.sandu.ximon.admin.manager.iot.rrpc.mainboard;
 
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.sandu.ximon.admin.manager.iot.amqp.MqttMainBoardConfig;
import com.sandu.ximon.admin.manager.iot.rrpc.BaseInvokeSyncService;
 
/**
 * @author chenjiantian
 * @date 2021/12/3 11:31
 * 主板rrpc通信实现类
 */
public class MainBoardInvokeSyncService extends BaseInvokeSyncService {
    private static volatile DefaultAcsClient client = null;
 
    private final static String PRODUCT_KEY = "a1JsfPG4iKW";
 
    @Override
    public String getProductKey() {
        return PRODUCT_KEY;
    }
 
//    @Override
//    public CommonFrame sendRRPC(String deviceName, IRequestFrame iRequestFrame) {
//        InvokeParam param = new InvokeParam();
//        param.setOperate("1001");
//        param.setFrame(iRequestFrame.getEncodeFrame());
//        InvokeThingServiceResponse.Data data = invokeThing(deviceName, param);
//        if (data == null) {
//            return null;
//        }
//        String result = data.getResult();
//        result = result.replace("\\", "");
//        Map map = JSON.parseObject(result, Map.class);
//        result = (String) map.get("msg");
//        CommonFrame connectFrame = FrameUtils.transformMessageToFrame(result);
//        return connectFrame;
//    }
//
//    @Override
//    public <T extends BaseResponseInnerFrame<T>> WrapResponseCommonFrame<T> sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class<T> clz) {
//        CommonFrame commonFrame = sendRRPC(deviceName, iRequestFrame);
//        if (commonFrame == null) {
//            throw new BusinessException("rrpc请求失败");
//        }
//        WrapResponseCommonFrame<T> responseCommonFrame = new WrapResponseCommonFrame<>();
//        BeanUtils.copyProperties(commonFrame, responseCommonFrame);
//        try {
//            responseCommonFrame.setResponseInnerFrame(clz.newInstance().transformFrame(responseCommonFrame.getPayload()));
//        } catch (InstantiationException | IllegalAccessException e) {
//            throw new BusinessException(String.format("找不到%s的构造函数", clz.getName()));
//        }
//        return responseCommonFrame;
//    }
 
 
    private static class SingletonClassInstance {
        private static final MainBoardInvokeSyncService INSTANCE = new MainBoardInvokeSyncService();
    }
 
    protected MainBoardInvokeSyncService() {
    }
 
    public static MainBoardInvokeSyncService getInstance() {
        return SingletonClassInstance.INSTANCE;
    }
 
    @Override
    public DefaultAcsClient getClient() {
        if (client == null) {
            synchronized (MainBoardInvokeSyncService.class) {
                if (client == null) {
                    IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", MqttMainBoardConfig.ACCESS_KEY, MqttMainBoardConfig.ACCESS_SECRET);
                    DefaultProfile.addEndpoint("cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");
                    client = new DefaultAcsClient(profile);
                }
            }
        }
        return client;
    }
 
 
}