Commit 498723ab authored by 汪清城's avatar 汪清城
Browse files

1. 修改客户端请求的处理方式

parent 58e04c15
......@@ -240,7 +240,7 @@ public class IotServeBootstrap implements InitializingBean,DisposableBean
}
@Bean({"deviceManager", "devicePipelineManager"})
@ConditionalOnMissingBean(name = "devicePipelineManager")
@ConditionalOnMissingBean(name = {"devicePipelineManager", "deviceManager"})
public DevicePipelineManager devicePipelineManager() {
return DevicePipelineManager.getInstance();
}
......
package com.iteaj.network.client.handle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 声明目标类是一个客户端处理器
*/
@Target(ElementType.TYPE)
public @interface Handle {
@Retention(RetentionPolicy.RUNTIME)
public @interface ClientHandle {
String name();
String value() default "";
/**
* 序列化
*/
Class<?> deserializer() default Void.class;
}
package com.iteaj.network.client.handle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ClientHandleBeanPostProcessor implements BeanPostProcessor {
private final Map<String, Method> clientMapping = new ConcurrentHashMap();
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
final ClientHandle clientHandle = bean.getClass().getAnnotation(ClientHandle.class);
if(clientHandle != null) {
final String value = clientHandle.value();
ReflectionUtils.doWithMethods(bean.getClass(), item -> {
final IotMapping iotMapping = item.getAnnotation(IotMapping.class);
String tradeType = value;
if(iotMapping != null || iotMapping.value() != null) {
tradeType += iotMapping.value();
}
if(StringUtils.hasText(tradeType)) {
final Method method = clientMapping.get(tradeType);
if(method == null) {
clientMapping.put(tradeType, item);
} else {
throw new BeanInitializationException("错误的映射名称["+tradeType+"]" +
", 和方法冲突["+method.getDeclaringClass().getName()+method.getName()+"]");
}
} else {
throw new BeanInitializationException("错误的映射名称["+tradeType+"], 必须不能空");
}
});
}
return bean;
}
}
package com.iteaj.network.client.handle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.METHOD, ElementType.TYPE})
public @interface IotMapping {
String value();
/**
* 是否同步
* @return
*/
boolean sync() default false;
}
package com.iteaj.network.client.handle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
public @interface Mapper {
// Class<>
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment