Commit fa323143 by guo_minglei@163.com

Merge remote-tracking branch 'origin/developer' into developer

parents 4d4ebfde dd74a46b
...@@ -25,6 +25,10 @@ public class AdminRegisterConfig { ...@@ -25,6 +25,10 @@ public class AdminRegisterConfig {
// @Value("${myth-rpc.registry.port}") // @Value("${myth-rpc.registry.port}")
// private int port; // private int port;
/**
* 初始化 rpc客户端 属于消费者
* @return
*/
@Bean @Bean
public RpcSpringInvokerFactory invokerFactory(){ public RpcSpringInvokerFactory invokerFactory(){
RpcSpringInvokerFactory invokerFactory = new RpcSpringInvokerFactory(); RpcSpringInvokerFactory invokerFactory = new RpcSpringInvokerFactory();
...@@ -39,6 +43,10 @@ public class AdminRegisterConfig { ...@@ -39,6 +43,10 @@ public class AdminRegisterConfig {
return invokerFactory; return invokerFactory;
} }
/**
* 设置对外提供服务的接口 这个其实是配合网关调用的方式 属于生产者
* @return
*/
@Bean @Bean
public RpcSpringProviderFactory rpcSpringProviderFactory() { public RpcSpringProviderFactory rpcSpringProviderFactory() {
RpcSpringProviderFactory providerFactory = new RpcSpringProviderFactory(); RpcSpringProviderFactory providerFactory = new RpcSpringProviderFactory();
......
...@@ -87,7 +87,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor ...@@ -87,7 +87,7 @@ public class RpcSpringInvokerFactory extends InstantiationAwareBeanPostProcessor
null, null,
rpcInvokerFactory rpcInvokerFactory
); );
//获取一个代理对象
Object serviceProxy = referenceBean.getObject(); Object serviceProxy = referenceBean.getObject();
// set bean // set bean
......
...@@ -136,154 +136,151 @@ public class RpcReferenceBean { ...@@ -136,154 +136,151 @@ public class RpcReferenceBean {
public Object getObject() { public Object getObject() {
return Proxy.newProxyInstance(Thread.currentThread() return Proxy.newProxyInstance(Thread.currentThread()
.getContextClassLoader(), new Class[] { iface }, .getContextClassLoader(), new Class[] { iface },
new InvocationHandler() { (proxy, method, args) -> {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // method param
String className = method.getDeclaringClass().getName(); // iface.getName()
// method param String varsion_ = version;
String className = method.getDeclaringClass().getName(); // iface.getName() String methodName = method.getName();
String varsion_ = version; Class<?>[] parameterTypes = method.getParameterTypes();
String methodName = method.getName(); Object[] parameters = args;
Class<?>[] parameterTypes = method.getParameterTypes();
Object[] parameters = args; // filters for generic
if (className.equals(RpcGenericService.class.getName()) && methodName.equals("invoke")) {
// filters for generic
if (className.equals(RpcGenericService.class.getName()) && methodName.equals("invoke")) { Class<?>[] paramTypes = null;
if (args[3]!=null) {
Class<?>[] paramTypes = null; String[] paramTypes_str = (String[]) args[3];
if (args[3]!=null) { if (paramTypes_str.length > 0) {
String[] paramTypes_str = (String[]) args[3]; paramTypes = new Class[paramTypes_str.length];
if (paramTypes_str.length > 0) { for (int i = 0; i < paramTypes_str.length; i++) {
paramTypes = new Class[paramTypes_str.length]; paramTypes[i] = ClassUtil.resolveClass(paramTypes_str[i]);
for (int i = 0; i < paramTypes_str.length; i++) {
paramTypes[i] = ClassUtil.resolveClass(paramTypes_str[i]);
}
} }
} }
className = (String) args[0];
varsion_ = (String) args[1];
methodName = (String) args[2];
parameterTypes = paramTypes;
parameters = (Object[]) args[4];
} }
// filters method like "Object.toString()" className = (String) args[0];
if (className.equals(Object.class.getName())) { varsion_ = (String) args[1];
logger.info(">>>>>>>>>>> myth-rpc proxy class-method not support [{}#{}]", className, methodName); methodName = (String) args[2];
throw new RpcException("myth-rpc proxy class-method not support"); parameterTypes = paramTypes;
} parameters = (Object[]) args[4];
}
// address // filters method like "Object.toString()"
String finalAddress = address; if (className.equals(Object.class.getName())) {
if (finalAddress==null || finalAddress.trim().length()==0) { logger.info(">>>>>>>>>>> myth-rpc proxy class-method not support [{}#{}]", className, methodName);
if (invokerFactory!=null && invokerFactory.getServiceRegistry()!=null) { throw new RpcException("myth-rpc proxy class-method not support");
// discovery }
String serviceKey = RpcProviderFactory.makeServiceKey(className, varsion_);
TreeSet<String> addressSet = invokerFactory.getServiceRegistry().discovery(serviceKey);
// load balance
if (addressSet==null || addressSet.size()==0) {
// pass
} else if (addressSet.size()==1) {
//TODO 这里就是根据路由规则选出的路由地址
finalAddress = addressSet.first();
} else {
finalAddress = loadBalance.rpcInvokerRouter.route(serviceKey, addressSet);
}
// address
String finalAddress = address;
if (finalAddress==null || finalAddress.trim().length()==0) {
if (invokerFactory!=null && invokerFactory.getServiceRegistry()!=null) {
// discovery
String serviceKey = RpcProviderFactory.makeServiceKey(className, varsion_);
TreeSet<String> addressSet = invokerFactory.getServiceRegistry().discovery(serviceKey);
// load balance
if (addressSet==null || addressSet.size()==0) {
// pass
} else if (addressSet.size()==1) {
//TODO 这里就是根据路由规则选出的路由地址
finalAddress = addressSet.first();
} else {
finalAddress = loadBalance.rpcInvokerRouter.route(serviceKey, addressSet);
} }
} }
if (finalAddress==null || finalAddress.trim().length()==0) { }
throw new RpcException("myth-rpc reference bean["+ className +"] address empty"); if (finalAddress==null || finalAddress.trim().length()==0) {
} throw new RpcException("myth-rpc reference bean["+ className +"] address empty");
}
// request // request
RpcRequest rpcRequest = new RpcRequest(); RpcRequest rpcRequest = new RpcRequest();
rpcRequest.setRequestId(UUID.randomUUID().toString()); rpcRequest.setRequestId(UUID.randomUUID().toString());
rpcRequest.setCreateMillisTime(System.currentTimeMillis()); rpcRequest.setCreateMillisTime(System.currentTimeMillis());
rpcRequest.setAccessToken(accessToken); rpcRequest.setAccessToken(accessToken);
rpcRequest.setClassName(className); rpcRequest.setClassName(className);
rpcRequest.setMethodName(methodName); rpcRequest.setMethodName(methodName);
rpcRequest.setParameterTypes(parameterTypes); rpcRequest.setParameterTypes(parameterTypes);
rpcRequest.setParameters(parameters); rpcRequest.setParameters(parameters);
// send // send
if (CallType.SYNC == callType) { if (CallType.SYNC == callType) {
// future-response set // future-response set
RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, null); RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, null);
try { try {
// do invoke // do invoke
client.asyncSend(finalAddress, rpcRequest); client.asyncSend(finalAddress, rpcRequest);
// future get // future get
RpcResponse rpcResponse = futureResponse.get(timeout, TimeUnit.MILLISECONDS); RpcResponse rpcResponse = futureResponse.get(timeout, TimeUnit.MILLISECONDS);
if (rpcResponse.getErrorMsg() != null) { if (rpcResponse.getErrorMsg() != null) {
throw new RpcException(rpcResponse.getErrorMsg()); throw new RpcException(rpcResponse.getErrorMsg());
}
return rpcResponse.getResult();
} catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
throw (e instanceof RpcException)?e:new RpcException(e);
} finally{
// future-response remove
futureResponse.removeInvokerFuture();
}
} else if (CallType.FUTURE == callType) {
// future-response set
RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, null);
try {
// invoke future set
RpcInvokeFuture invokeFuture = new RpcInvokeFuture(futureResponse);
RpcInvokeFuture.setFuture(invokeFuture);
// do invoke
client.asyncSend(finalAddress, rpcRequest);
return null;
} catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
// future-response remove
futureResponse.removeInvokerFuture();
throw (e instanceof RpcException)?e:new RpcException(e);
}
} else if (CallType.CALLBACK == callType) {
// get callback
RpcInvokeCallback finalInvokeCallback = invokeCallback;
RpcInvokeCallback threadInvokeCallback = RpcInvokeCallback.getCallback();
if (threadInvokeCallback != null) {
finalInvokeCallback = threadInvokeCallback;
}
if (finalInvokeCallback == null) {
throw new RpcException("myth-rpc RpcInvokeCallback(CallType="+ CallType.CALLBACK.name() +") cannot be null.");
} }
return rpcResponse.getResult();
} catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
throw (e instanceof RpcException)?e:new RpcException(e);
} finally{
// future-response remove
futureResponse.removeInvokerFuture();
}
} else if (CallType.FUTURE == callType) {
// future-response set
RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, null);
try {
// invoke future set
RpcInvokeFuture invokeFuture = new RpcInvokeFuture(futureResponse);
RpcInvokeFuture.setFuture(invokeFuture);
// future-response set // do invoke
RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, finalInvokeCallback); client.asyncSend(finalAddress, rpcRequest);
try {
client.asyncSend(finalAddress, rpcRequest);
} catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
// future-response remove return null;
futureResponse.removeInvokerFuture(); } catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
throw (e instanceof RpcException)?e:new RpcException(e); // future-response remove
} futureResponse.removeInvokerFuture();
throw (e instanceof RpcException)?e:new RpcException(e);
}
} else if (CallType.CALLBACK == callType) {
return null; // get callback
} else if (CallType.ONEWAY == callType) { RpcInvokeCallback finalInvokeCallback = invokeCallback;
client.asyncSend(finalAddress, rpcRequest); RpcInvokeCallback threadInvokeCallback = RpcInvokeCallback.getCallback();
return null; if (threadInvokeCallback != null) {
} else { finalInvokeCallback = threadInvokeCallback;
throw new RpcException("myth-rpc callType["+ callType +"] invalid"); }
if (finalInvokeCallback == null) {
throw new RpcException("myth-rpc RpcInvokeCallback(CallType="+ CallType.CALLBACK.name() +") cannot be null.");
} }
// future-response set
RpcFutureResponse futureResponse = new RpcFutureResponse(invokerFactory, rpcRequest, finalInvokeCallback);
try {
client.asyncSend(finalAddress, rpcRequest);
} catch (Exception e) {
logger.info(">>>>>>>>>>> myth-rpc, invoke error, address:{}, RpcRequest{}", finalAddress, rpcRequest);
// future-response remove
futureResponse.removeInvokerFuture();
throw (e instanceof RpcException)?e:new RpcException(e);
}
return null;
} else if (CallType.ONEWAY == callType) {
client.asyncSend(finalAddress, rpcRequest);
return null;
} else {
throw new RpcException("myth-rpc callType["+ callType +"] invalid");
} }
}); });
} }
......
...@@ -82,7 +82,7 @@ public abstract class ConnectClient { ...@@ -82,7 +82,7 @@ public abstract class ConnectClient {
if (connectClient!=null && connectClient.isValidate()) { if (connectClient!=null && connectClient.isValidate()) {
return connectClient; return connectClient;
} }
//获取对应地址的锁对象
// lock // lock
Object clientLock = connectClientLockMap.get(address); Object clientLock = connectClientLockMap.get(address);
if (clientLock == null) { if (clientLock == null) {
......
...@@ -19,7 +19,7 @@ public class AddComplexPy { ...@@ -19,7 +19,7 @@ public class AddComplexPy {
runNode.setNodeId("2"); runNode.setNodeId("2");
runNode.setNodeName("lijkki"); runNode.setNodeName("lijkki");
runNode.setRunCmd("python ${biz_file}"); runNode.setRunCmd("python ${biz_file}");
JobUtils.setRequestUrl("http://127.0.0.1:8081/myth-job-admin"); JobUtils.setRequestUrl("http://10.0.120.208:8081/myth-job-admin/");
JobUtils.setTOKEN("test"); JobUtils.setTOKEN("test");
JobUtils.realExectNode(runNode); JobUtils.realExectNode(runNode);
/* PluginPackage pluginPackage = new PluginPackage(); /* PluginPackage pluginPackage = new PluginPackage();
......
...@@ -16,7 +16,7 @@ public class AddComplexPy1 { ...@@ -16,7 +16,7 @@ public class AddComplexPy1 {
PluginPackage pluginPackage = new PluginPackage(); PluginPackage pluginPackage = new PluginPackage();
pluginPackage.setWorkspaceName("test"); pluginPackage.setWorkspaceName("test");
pluginPackage.setFlow(createFlow()); pluginPackage.setFlow(createFlow());
JobUtils.setRequestUrl("http://127.0.0.1:8081/myth-job-admin"); JobUtils.setRequestUrl("http://10.0.120.208:8081/myth-job-admin");
JobUtils.setTOKEN("test"); JobUtils.setTOKEN("test");
JobUtils.publish(pluginPackage); JobUtils.publish(pluginPackage);
} }
......
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