24 changed files with 291 additions and 111 deletions
@ -1,10 +1,13 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.base.Rpc; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-11 21:05 |
||||
*/ |
||||
public interface IUserService { |
||||
|
||||
@Rpc(async = true,callback = UserCallback.class) |
||||
String say(String sb); |
||||
} |
||||
|
@ -0,0 +1,15 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.common.AbstractRpcCallBack; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-15 07:32 |
||||
*/ |
||||
public class UserCallback extends AbstractRpcCallBack { |
||||
@Override |
||||
public void run(Object object) { |
||||
String msg= (String) object; |
||||
System.out.println("我是异步回调"+msg); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.base; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.common.AbstractRpcCallBack; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Rpc |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface Rpc { |
||||
|
||||
int retries() default 3; |
||||
|
||||
boolean async() default false; |
||||
|
||||
boolean isOneway() default true; |
||||
|
||||
Class<? extends AbstractRpcCallBack> callback() default AbstractRpcCallBack.class; |
||||
|
||||
} |
@ -0,0 +1,61 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.client; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.common.AbstractRpcCallBack; |
||||
import org.apache.dolphinscheduler.remote.rpc.common.ConsumerConfigConstants; |
||||
|
||||
/** |
||||
* ConsumerConfig |
||||
*/ |
||||
public class ConsumerConfig { |
||||
|
||||
private Class<? extends AbstractRpcCallBack> callBackClass; |
||||
|
||||
private String serviceName; |
||||
|
||||
private Boolean async = ConsumerConfigConstants.DEFAULT_SYNC; |
||||
|
||||
private Boolean isOneway = ConsumerConfigConstants.DEFAULT_IS_ONEWAY; |
||||
|
||||
private Integer retries = ConsumerConfigConstants.DEFAULT_RETRIES; |
||||
|
||||
|
||||
public Class<? extends AbstractRpcCallBack> getCallBackClass() { |
||||
return callBackClass; |
||||
} |
||||
|
||||
public void setCallBackClass(Class<? extends AbstractRpcCallBack> callBackClass) { |
||||
this.callBackClass = callBackClass; |
||||
} |
||||
|
||||
public String getServiceName() { |
||||
return serviceName; |
||||
} |
||||
|
||||
public void setServiceName(String serviceName) { |
||||
this.serviceName = serviceName; |
||||
} |
||||
|
||||
public Boolean getAsync() { |
||||
return async; |
||||
} |
||||
|
||||
public void setAsync(Boolean async) { |
||||
this.async = async; |
||||
} |
||||
|
||||
public Boolean getOneway() { |
||||
return isOneway; |
||||
} |
||||
|
||||
public void setOneway(Boolean oneway) { |
||||
isOneway = oneway; |
||||
} |
||||
|
||||
public Integer getRetries() { |
||||
return retries; |
||||
} |
||||
|
||||
public void setRetries(Integer retries) { |
||||
this.retries = retries; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.client; |
||||
|
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
/** |
||||
* ConsumerConfigCache |
||||
*/ |
||||
public class ConsumerConfigCache { |
||||
|
||||
private static ConcurrentHashMap<String, ConsumerConfig> consumerMap=new ConcurrentHashMap<>(); |
||||
|
||||
public static ConsumerConfig getConfigByServersName(String serviceName){ |
||||
return consumerMap.get(serviceName); |
||||
} |
||||
|
||||
public static void putConfig(String serviceName,ConsumerConfig consumerConfig){ |
||||
consumerMap.putIfAbsent(serviceName,consumerConfig); |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.client; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.future.RpcFuture; |
||||
|
||||
/** |
||||
* RpcRequestCache |
||||
*/ |
||||
public class RpcRequestCache { |
||||
|
||||
private RpcFuture rpcFuture; |
||||
|
||||
private String serviceName; |
||||
|
||||
public RpcFuture getRpcFuture() { |
||||
return rpcFuture; |
||||
} |
||||
|
||||
public void setRpcFuture(RpcFuture rpcFuture) { |
||||
this.rpcFuture = rpcFuture; |
||||
} |
||||
|
||||
public String getServiceName() { |
||||
return serviceName; |
||||
} |
||||
|
||||
public void setServiceName(String serviceName) { |
||||
this.serviceName = serviceName; |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.common; |
||||
|
||||
/** |
||||
* AbstractRpcCallBack |
||||
*/ |
||||
public abstract class AbstractRpcCallBack { |
||||
|
||||
public abstract void run(Object object); |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.common; |
||||
|
||||
/** |
||||
* ConsumerConfigConstants |
||||
*/ |
||||
public class ConsumerConfigConstants { |
||||
|
||||
|
||||
public static final Boolean DEFAULT_SYNC = false; |
||||
|
||||
public static final Boolean DEFAULT_IS_ONEWAY = false; |
||||
|
||||
public static final Integer DEFAULT_RETRIES = 3; |
||||
} |
Loading…
Reference in new issue