【代码优化】IoT:移除 ServiceRegistry,使用 SpringUtils 替代
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.module.iot.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// TODO 芋艿:纠结下
|
||||
/**
|
||||
* 服务注册表 - 插架模块使用,无法使用 Spring 注入
|
||||
*/
|
||||
public class ServiceRegistry {
|
||||
|
||||
private static final Map<Class<?>, Object> services = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 注册服务
|
||||
*
|
||||
* @param serviceClass 服务类
|
||||
* @param serviceImpl 服务实现
|
||||
* @param <T> 服务类
|
||||
*/
|
||||
public static <T> void registerService(Class<T> serviceClass, T serviceImpl) {
|
||||
services.put(serviceClass, serviceImpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得服务
|
||||
*
|
||||
* @param serviceClass 服务类
|
||||
* @param <T> 服务类
|
||||
* @return 服务实现
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getService(Class<T> serviceClass) {
|
||||
return (T) services.get(serviceClass);
|
||||
}
|
||||
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// TODO @芋艿:要不要加个 mqtt 值了的前缀
|
||||
/**
|
||||
* MQTT RPC 请求
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RpcRequest {
|
||||
|
||||
/**
|
||||
* 方法名
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
// TODO @haohao:object 对象会不会不好序列化?
|
||||
private Object[] params;
|
||||
|
||||
/**
|
||||
* 关联 ID
|
||||
*/
|
||||
private String correlationId;
|
||||
|
||||
/**
|
||||
* 回复地址
|
||||
*/
|
||||
private String replyTo;
|
||||
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* MQTT RPC 响应
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RpcResponse {
|
||||
|
||||
/**
|
||||
* 关联 ID
|
||||
*/
|
||||
private String correlationId;
|
||||
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
// TODO @haohao:object 对象会不会不好反序列化?
|
||||
private Object result;
|
||||
|
||||
/**
|
||||
* 错误
|
||||
*/
|
||||
private String error;
|
||||
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
/**
|
||||
* 序列化工具类
|
||||
*
|
||||
*/
|
||||
public class SerializationUtils {
|
||||
|
||||
public static String serialize(Object obj) {
|
||||
return JSONUtil.toJsonStr(obj);
|
||||
}
|
||||
|
||||
public static <T> T deserialize(String json, Class<T> clazz) {
|
||||
return JSONUtil.toBean(json, clazz);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user