技术标签: Dubbo+Zookeeper dubbo
Dubbo编解码(一)-原理
Dubbo编解码(二)-Codec2和AbstractCodec
Dubbo编解码(三)-TransportCodec
Dubbo编解码(五)-Dubbo协议编码器
Dubbo编解码(六)-Dubbo协议解码器
在Dubbo-SPI(六)-各层扩展点中已经有相关介绍,根据URL中的codec参数决定使用哪一种编解码实现方式,扩展点实现如下:
传输层编解码实现
transport=org.apache.dubbo.remoting.transport.codec.TransportCodec
telnet=org.apache.dubbo.remoting.telnet.codec.TelnetCodec
交换层编解码实现
exchange=org.apache.dubbo.remoting.exchange.codec.ExchangeCodec
protected static Codec2 getChannelCodec(URL url) {
// 编解码器扩展名 必须与 协议名 保持相同
String codecName = url.getProtocol(); // codec extension name must stay the same with protocol name
if (ExtensionLoader.getExtensionLoader(Codec2.class).hasExtension(codecName)) {
return ExtensionLoader.getExtensionLoader(Codec2.class).getExtension(codecName);
} else {
return new CodecAdapter(ExtensionLoader.getExtensionLoader(Codec.class)
.getExtension(codecName));
}
}
实现了Codec2接口,但是没有去具体实现Codec2#encode和Codec2#decode方法
主要提供了检验报文长度 和 获取 具体编解码器的方法
protected static void checkPayload(Channel channel, long size) throws IOException {
// 获取报文长度
int payload = getPayload(channel);
// 判断报文长度是否超限
boolean overPayload = isOverPayload(payload, size);
if (overPayload) {
ExceedPayloadLimitException e = new ExceedPayloadLimitException(
"Data length too large: " + size + ", max payload: " + payload + ", channel: " + channel);
logger.error(e);
throw e;
}
}
int DEFAULT_PAYLOAD = 8 * 1024 * 1024;
protected static int getPayload(Channel channel) {
// payload=8M
int payload = Constants.DEFAULT_PAYLOAD;
if (channel != null && channel.getUrl() != null) {
// 获取url中的payload参数值
payload = channel.getUrl().getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD);
}
return payload;
}
protected static boolean isOverPayload(int payload, long size) {
if (payload > 0 && size > payload) {
return true;
}
return false;
}
protected Serialization getSerialization(Channel channel, Request req) {
return CodecSupport.getSerialization(channel.getUrl());
}
protected Serialization getSerialization(Channel channel, Response res) {
return CodecSupport.getSerialization(channel.getUrl());
}
protected Serialization getSerialization(Channel channel) {
return CodecSupport.getSerialization(channel.getUrl());
}
String SERIALIZATION_KEY = "serialization";
String DEFAULT_REMOTING_SERIALIZATION = "hessian2";
// CodecSupport#getSerialization
public static Serialization getSerialization(URL url) {
// 获取扩展接口(Serialization)的扩展实例,根据url的serialization参数获取,默认是hessian2
return ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(
url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION));
}
String SIDE_KEY = "side";
protected boolean isClientSide(Channel channel) {
String side = (String) channel.getAttribute(SIDE_KEY);
if (CLIENT_SIDE.equals(side)) {
return true;
} else if (SERVER_SIDE.equals(side)) {
return false;
} else {
// side属性值既不是client也不是server
InetSocketAddress address = channel.getRemoteAddress();
URL url = channel.getUrl();
// 使用InetSocketAddress 和 URL 进行判断
boolean isClient = url.getPort() == address.getPort()
&& NetUtils.filterLocalHost(url.getIp()).equals(
NetUtils.filterLocalHost(address.getAddress()
.getHostAddress()));
channel.setAttribute(SIDE_KEY, isClient ? CLIENT_SIDE
: SERVER_SIDE);
return isClient;
}
}
protected boolean isServerSide(Channel channel) {
return !isClientSide(channel);
}
多频外差:需要拍摄多幅图片,对于动态的三维重建不友好二值码亮区域-编码0,暗区域-编码1假设投射三幅图案,则编码方式如下:二值码和格雷码比较相机拍摄–一个像素点正好在黑白相间的边界点–容易发生解码错误格雷码生成1.生成步骤:(1)生成0,1–>0,1(2)每一个前面+0–>00,01,翻转首个元素、其余取对称–>11,10(3)每一个前面+0–>000,001,011,010,翻转首个元素,其余取对称–>110,111,101,100(4)递归2.ma
(一部分图片来源于网络)1.下载下载地址:mysql下载地址1.1.选择community,我下载的是社区的社区版本,见红色方框 1.2.下载并解压后,配置环境变量,mysql_home然后在path加入解压路径之中bin的路径ps:path里添加:%MYSQL_HOME%\bin; 1.3.这里有两种做法,个人感觉第二种好一点 (1...
定义最大团:点数最多的极大团。极大团:不是其他团的子团的团。团:原图的完全子图。最大独立集:一个点数最多的点集,且满足集合内的点互不相邻性质一个图的最大独立集的集合大小等于该图的补图的最大团大小用于解决最大团问题的Bron–Kerbosch算法简书上的图解博客园的三种优化CSDN上的原理#define N 1010/*最大团 = 补图G的最大独立集数———>最大独...
离散数学是当代数学的一个重要分支,也是计算机科学的数学基础。它包括数理逻辑、集合论、图论和近世代数四个分支。数理逻辑基于布尔运算,我们已经介绍过了。这里我们介绍图论和互联网自动下载工具网络爬虫 (Web Crawlers) 之间的关系。顺便提一句,我们用 Google Trends 来搜索一下“离散数学”这个词,可以发现不少有趣的现象。比如,武汉、哈尔滨、合肥和长沙市对这一数学题目最有兴趣的城市...
题目链接: https://vjudge.net/problem/HDU-2101题目分析:把输入a,b放进while循环条件里,然后判断a,b是否符合条件。This problem is also a A + B problem,but it has a little difference,you should determine does (a+b) could be divided wi...
在业务里用到了PHP header导出doc文档,GET传值到页面,读出相应数据输出doc文件下载。用户提出需要批量,于是设计成js循环出对应数量的window.open(),向页面传入不同的值,批量输出相应的文件。简单的说,就是我需要循环出多个window.open()。js代码为:var outCode = JSON.parse();for(var i=0; i<outCode.
xcode5 如果切换开发者账号,老的provisioning 还会在生成ipa时选择provisioning看到(很讨厌吧),需要手动删除xcode5 provisioning profile path: ~/Library/MobileDevice/Provisioning Profiles打开并日期排序,删除老的 provisioning profile 文件即可
现在年轻人听音乐都喜欢用蓝牙耳机,不仅便于携带而且少了线的束缚。目前,大多数电脑已支持蓝牙设备连接功能,部分用户不知道蓝牙耳机怎么连接电脑,其实操作方法很简单,本文教你给电脑连接蓝牙耳机的方法。具体方法如下:1、首先确认电脑的蓝牙开启,蓝牙灯正常,并开启蓝牙耳机的开关。点击系统右下角蓝牙图标,选择“添加设备” 。2、选择要添加的蓝牙耳机 。3、系统会提示正在与蓝牙适配器连接 。4、然后提示成功添加...
oniguruma是一个处理正则表达式的库,在编译安装php时,如果使用–enable-mbstring 参数, 开启mbstring扩展,则会出现这个错误。原因:mbstring的正则功能需要oniguruma的支持,系统中却没有oniguruma库。解决方法:1、在’–enable-mbstring’参数后添加’–disable-mbregex’参数,意为不使用mbstring的正则功能,不再需要oniguruma库。2、使用源码安装oniguruma库wget https://github
IBM Red Hat本周宣布将整合其自动化平台Ansible和Kubernetes平台(Advanced Cluster Management for Kubernetes),以实现混...
bing图片每日更新,对于这一点感觉挺不错的,如果能够把bing每日图片作为博客背景是不是很不错呢?首先我们进入Bing首页,会发现自动转到中国版。不过这没关系,中国版更符合国情,速度也比国际版快一些。下面分享bing图片接口api,通过抓包,可以发现http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1这里可...