public interface Command {
public void execute();
}
public class TurnOnCommand implements Command {
public void execute() {
System.out.println("Trun on....");
}
}
public class TurnOffCommand implements Command {
public void execute() {
System.out.println("Trun off....");
}
}
com.abc.spi.TurnOnCommand com.abc.spi.TurnOffCommand
public class Test {
public static void main(String[] args) {
// 加载jdk的spi接口Command.class
ServiceLoader<Command> serviceLoader=ServiceLoader.load(Command.class);
// 遍历加载的jdk的接口
for(Command command:serviceLoader){
command.execute();
}
}
}
package com.xxx;
import org.apache.dubbo.rpc.Protocol;
public class XxxProtocol implements Protocol {
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
return new XxxExporter(invoker);
}
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
return new XxxInvoker(type, url);
}
}
package com.xxx;
import org.apache.dubbo.rpc.support.AbstractExporter;
public class XxxExporter<T> extends AbstractExporter<T> {
public XxxExporter(Invoker<T> invoker) throws RemotingException{
super(invoker);
// ...
}
public void unexport() {
super.unexport();
// ...
}
}
package com.xxx;
import org.apache.dubbo.rpc.support.AbstractInvoker;
public class XxxInvoker<T> extends AbstractInvoker<T> {
public XxxInvoker(Class<T> type, URL url) throws RemotingException{
super(type, url);
}
protected abstract Object doInvoke(Invocation invocation) throws Throwable {
// ...
}
}
<dubbo:protocol name=”XxxProtocol” port=”20000” />
END 题外推荐 十期推荐 【281期】滴滴二面:try-catch-finally 和 return 是什么顺序执行的? 【282期】面试官:你能说说 Nacos 的实现原理吗? 【283期】熊大同学的面试回忆录(2.5年开发经验) 【284期】共享锁、排他锁、互斥锁、悲观锁、乐观锁、行锁、表锁、页面锁、不可重复读、丢失修改、读脏数据 【285期】Spring的@Transactional如何实现的(必考) 【286期】面试时被问到Flutter/Dart的HashMap怎么办? 【287期】ArrayList使用forEach遍历的时候删除元素会报错吗? 【288期】面试官:什么是CAP 定理,为什么CAP不能同时被满足? 【289期】面试官:说一下JVM常用垃圾回收器的特点、优劣势、使用场景和参数设置 【290期】为什么不建议使用Java序列化? ? ~