dubbo学习笔记 十 dubbo-rpc
来源:互联网 发布:农村淘宝开业计划书 编辑:程序博客网 时间:2024/06/06 11:04
通过前面的dubbo-common之动态扩展,我们明白了会加载META-INF 目录下的文件。
接着来学习dubbo-rpc吧
Invoker
rpc调用远程实习类叫Invoker
public interface Invoker<T> extends Node { /** * get service interface. * * @return service interface. */ Class<T> getInterface(); /** * invoke. * * @param invocation * @return result * @throws RpcException */ Result invoke(Invocation invocation) throws RpcException;}
Exporter
用来获取invoker
public interface Exporter<T> { /** * get invoker. * * @return invoker */ Invoker<T> getInvoker(); /** * unexport. * * <code> * getInvoker().destroy(); * </code> */ void unexport();}
Protocol
描述远程协议,定义远程操作
/* * Copyright 1999-2011 Alibaba Group. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.alibaba.dubbo.rpc;import com.alibaba.dubbo.common.URL;import com.alibaba.dubbo.common.extension.Adaptive;import com.alibaba.dubbo.common.extension.SPI;/** * Protocol. (API/SPI, Singleton, ThreadSafe) * * @author william.liangf */@SPI("dubbo")public interface Protocol { /** * 获取缺省端口,当用户没有配置端口时使用。 * * @return 缺省端口 */ int getDefaultPort(); /** * 暴露远程服务:<br> * 1. 协议在接收请求时,应记录请求来源方地址信息:RpcContext.getContext().setRemoteAddress();<br> * 2. export()必须是幂等的,也就是暴露同一个URL的Invoker两次,和暴露一次没有区别。<br> * 3. export()传入的Invoker由框架实现并传入,协议不需要关心。<br> * * @param <T> 服务的类型 * @param invoker 服务的执行体 * @return exporter 暴露服务的引用,用于取消暴露 * @throws RpcException 当暴露服务出错时抛出,比如端口已占用 */ @Adaptive <T> Exporter<T> export(Invoker<T> invoker) throws RpcException; /** * 引用远程服务:<br> * 1. 当用户调用refer()所返回的Invoker对象的invoke()方法时,协议需相应执行同URL远端export()传入的Invoker对象的invoke()方法。<br> * 2. refer()返回的Invoker由协议实现,协议通常需要在此Invoker中发送远程请求。<br> * 3. 当url中有设置check=false时,连接失败不能抛出异常,并内部自动恢复。<br> * * @param <T> 服务的类型 * @param type 服务的类型 * @param url 远程服务的URL地址 * @return invoker 服务的本地代理 * @throws RpcException 当连接服务提供方失败时抛出 */ @Adaptive <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException; /** * 释放协议:<br> * 1. 取消该协议所有已经暴露和引用的服务。<br> * 2. 释放协议所占用的所有资源,比如连接和端口。<br> * 3. 协议在释放后,依然能暴露和引用新的服务。<br> */ void destroy();}
Result
invoke结果
public interface Result {/** * Get invoke result. * * @return result. if no result return null. */Object getValue();/** * Get exception. * * @return exception. if no exception return null. */Throwable getException(); /** * Has exception. * * @return has exception. */ boolean hasException(); /** * Recreate. * * <code> * if (hasException()) { * throw getException(); * } else { * return getValue(); * } * </code> * * @return result. * @throws if has exception throw it. */ Object recreate() throws Throwable; /** * @deprecated Replace to getValue() * @see com.alibaba.dubbo.rpc.Result#getValue() */ @Deprecated Object getResult(); /** * get attachments. * * @return attachments. */ Map<String, String> getAttachments(); /** * get attachment by key. * * @return attachment value. */ String getAttachment(String key); /** * get attachment by key with default value. * * @return attachment value. */ String getAttachment(String key, String defaultValue);}
Invocation
远程调用入参
public interface Invocation {/** * get method name. * * @serial * @return method name. */String getMethodName();/** * get parameter types. * * @serial * @return parameter types. */Class<?>[] getParameterTypes();/** * get arguments. * * @serial * @return arguments. */Object[] getArguments();/** * get attachments. * * @serial * @return attachments. */Map<String, String> getAttachments();/** * get attachment by key. * * @serial * @return attachment value. */String getAttachment(String key);/** * get attachment by key with default value. * * @serial * @return attachment value. */String getAttachment(String key, String defaultValue); /** * get the invoker in current context. * * @transient * @return invoker. */ Invoker<?> getInvoker();}
0 0
- dubbo学习笔记 十 dubbo-rpc
- dubbo学习笔记 十一 dubbo-rpc之模块
- Dubbo学习(十):异步调用
- dubbo学习笔记
- 阿里Dubbo学习笔记
- dubbo-学习笔记
- dubbo入门学习笔记
- dubbo学习笔记
- dubbo 学习笔记
- dubbo学习笔记
- dubbo学习概要笔记
- Dubbo入门学习笔记
- Dubbo 学习笔记
- DUBBO学习笔记
- dubbo 学习笔记
- dubbo学习笔记
- Dubbo框架学习笔记
- Dubbo的学习笔记
- 基于Python的Selenium自动化— 实现验证码截取并识别
- 七大排序算法之快速排序
- swoole深入学习 2. tcp Server和tcp Client
- 图片资源
- PHP实现的QQ空间g_tk加密算法
- dubbo学习笔记 十 dubbo-rpc
- swift语言的学习笔记四(类对象,函数)
- LeetCode #173 - Binary Search Tree Iterator - Medium
- BitmapFactory.decodeFile 加载失败 在部分安卓机器的BUG
- Java 的GroupLayout布局
- (4.6.22.5)来吧,是时候撸一份自己的RxJava框架啦:强撸为eventbus
- dubbo学习笔记 十二 dubbo-cluster
- 寻找非共有数字
- 软件项目管理流程总结