概述
Dubbo版本:2.7.8
项目名称:dubbo-compatible
目的:在Dubbo包名从"com.alibaba.dubbo"变为"org.apache.dubbo"后,用于升级Dubbo版本后提供一定的兼容性
主要包含以下接口或类
com.alibaba.dubbo.rpc.Filter / Invocation / Invoker / Result / RpcContext / RpcException com.alibaba.dubbo.config.annotation.Reference / Service com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo com.alibaba.dubbo.common.Constants / URL com.alibaba.dubbo.common.extension.ExtensionFactory com.alibaba.dubbo.common.serialize.Serialization / ObjectInput / ObjectOutput com.alibaba.dubbo.cache.CacheFactory / Cache com.alibaba.dubbo.rpc.service.EchoService / GenericService
说明
1. 这些兼容类或接口都会标记为@Deprecated
2. 这些兼容类或接口主要继承于对应的"org.apache.dubbo"包下的接口或类,一般无多余代码,都是使用父类代码。
比如:
package com.alibaba.dubbo.config; import org.apache.dubbo.config.annotation.Service; @Deprecated public class ServiceConfig<T> extends org.apache.dubbo.config.ServiceConfig<T> { public ServiceConfig() { } public ServiceConfig(Service service) { super(service); } }
- 3. 这些兼容类或接口后续版本可能会删除,所以除非用于版本升级兼容,否则不建议用
代码
1. ServiceConfig
package com.alibaba.dubbo.config; import org.apache.dubbo.config.annotation.Service; @Deprecated public class ServiceConfig<T> extends org.apache.dubbo.config.ServiceConfig<T> { public ServiceConfig() { } public ServiceConfig(Service service) { super(service); } }
2. ReferenceConfig
package com.alibaba.dubbo.config; import org.apache.dubbo.config.annotation.Reference; @Deprecated public class ReferenceConfig<T> extends org.apache.dubbo.config.ReferenceConfig<T> { public ReferenceConfig() { }
public ReferenceConfig(Reference reference) { super(reference); } }
3. Invoker
package com.alibaba.dubbo.rpc; import com.alibaba.dubbo.common.URL; @Deprecated public interface Invoker<T> extends org.apache.dubbo.rpc.Invoker<T> { Result invoke(Invocation invocation) throws RpcException; @Override URL getUrl(); default org.apache.dubbo.rpc.Invoker<T> getOriginal() { return null; } // This method will never be called for a legacy invoker. @Override default org.apache.dubbo.rpc.Result invoke(org.apache.dubbo.rpc.Invocation invocation) throws org.apache.dubbo.rpc.RpcException { return null; } class CompatibleInvoker<T> implements Invoker<T> { private org.apache.dubbo.rpc.Invoker<T> invoker; public CompatibleInvoker(org.apache.dubbo.rpc.Invoker<T> invoker) { this.invoker = invoker; } @Override public Class<T> getInterface() { return invoker.getInterface(); } @Override public Result invoke(Invocation invocation) throws RpcException { return new Result.CompatibleResult(invoker.invoke(invocation.getOriginal())); } @Override public URL getUrl() { return new URL(invoker.getUrl()); } @Override public boolean isAvailable() { return invoker.isAvailable(); } @Override public void destroy() { invoker.destroy(); } @Override public org.apache.dubbo.rpc.Invoker<T> getOriginal() { return invoker; } } }
4. Exporter
package com.alibaba.dubbo.rpc; @Deprecated public interface Exporter<T> extends org.apache.dubbo.rpc.Exporter<T> { @Override Invoker<T> getInvoker(); class CompatibleExporter<T> implements Exporter<T> { private org.apache.dubbo.rpc.Exporter<T> delegate; public CompatibleExporter(org.apache.dubbo.rpc.Exporter<T> delegate) { this.delegate = delegate; } @Override public Invoker<T> getInvoker() { return new Invoker.CompatibleInvoker<>(delegate.getInvoker()); } @Override public void unexport() { delegate.unexport(); } }