ing
This commit is contained in:
parent
11e08c8e9a
commit
d9e0810ba9
|
@ -9,7 +9,6 @@ import com.google.gson.Gson;
|
|||
import com.loafle.commons.rpc.protocol.RPCServerCodec;
|
||||
import com.loafle.commons.rpc.protocol.json.JSONRPCServerCodec;
|
||||
import com.loafle.commons.rpc.registry.RPCRegistry;
|
||||
import com.loafle.commons.rpc.registry.pojo.POJORPCRegistry;
|
||||
import com.loafle.commons.server.Server;
|
||||
import com.loafle.commons.server.socket.handler.codec.SocketServerProtocolHandler;
|
||||
import com.loafle.overflow.container.Container;
|
||||
|
@ -72,7 +71,7 @@ public class ContainerConfiguration {
|
|||
|
||||
@Bean
|
||||
public RPCRegistry rpcRegistry() {
|
||||
return new POJORPCRegistry();
|
||||
return new RPCRegistry();
|
||||
}
|
||||
|
||||
@Bean(Server.CHANNEL_INITIALIZER)
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.loafle.overflow.container.service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loafle.commons.rpc.RPCException;
|
||||
import com.loafle.commons.rpc.registry.RPCRegistry;
|
||||
import com.loafle.overflow.core.annotation.ProbeAPI;
|
||||
import com.loafle.overflow.core.annotation.RPCService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -41,12 +44,44 @@ public class Service implements InitializingBean, ApplicationContextAware {
|
|||
}
|
||||
|
||||
services.forEach((name, bean) -> {
|
||||
logger.debug("bean {}", bean.getClass().getName());
|
||||
this.registerRPCService(bean, name);
|
||||
});
|
||||
}
|
||||
|
||||
private void registerRPCService(Object bean, String name) {
|
||||
try {
|
||||
this.rpcRegistry.registerService(bean, bean.getClass(), name);
|
||||
Class<?> clazz = bean.getClass();
|
||||
Method[] methods = clazz.getMethods();
|
||||
|
||||
Map<String, Method> methodMap = new HashMap<>();
|
||||
|
||||
for (Method method : methods) {
|
||||
String methodName = this.getRPCMethodName(method);
|
||||
if (null == methodName) {
|
||||
continue;
|
||||
}
|
||||
methodMap.put(methodName, method);
|
||||
}
|
||||
|
||||
if (0 == methodMap.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.rpcRegistry.registerService(bean, name, methodMap);
|
||||
} catch (RPCException e) {
|
||||
logger.error("RPCRegistry", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getRPCMethodName(Method method) {
|
||||
ProbeAPI a = method.getAnnotation(ProbeAPI.class);
|
||||
if (null == a) {
|
||||
return null;
|
||||
}
|
||||
String name = a.value();
|
||||
if ("" == name.trim()) {
|
||||
name = method.getName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user