代码位置:
motan-core的目录下
motan中使用spring管理配置对象。motan利用Spring的spi机制创建了自定义标签和相应的标签处理代码。具体使用方法见这篇。本文以motan为例,探讨如何扩展spring的schema.
1.首先,如果要自定义标签,不得不加上响应的xsd文件,这个文件可以对xml的格式进行约束。可以看到以下的自定义标签应该遵循的格式。对于新增的xsd文件,还要建立一个spring.schemas文件,加上这个xsd文件。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- 3 ~ Copyright 2009-2016 Weibo, Inc. 4 ~ 5 ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 ~ you may not use this file except in compliance with the License. 7 ~ You may obtain a copy of the License at 8 ~ 9 ~ http://www.apache.org/licenses/LICENSE-2.0 10 ~ 11 ~ Unless required by applicable law or agreed to in writing, software 12 ~ distributed under the License is distributed on an "AS IS" BASIS, 13 ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ~ See the License for the specific language governing permissions and 15 ~ limitations under the License. 16 --> 17 18 <xsd:schema xmlns="http://api.weibo.com/schema/motan" 19 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 20 xmlns:tool="http://www.springframework.org/schema/tool" 21 xmlns:beans="http://www.springframework.org/schema/beans" 22 targetNamespace="http://api.weibo.com/schema/motan"> 23 24 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> 25 <xsd:import namespace="http://www.springframework.org/schema/tool"/> 26 <xsd:import namespace="http://www.springframework.org/schema/beans"/> 27 28 <xsd:complexType name="abstractConfig"> 29 <xsd:choice minOccurs="0" maxOccurs="unbounded"> 30 <xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" /> 31 </xsd:choice> 32 <xsd:anyAttribute namespace="##other" processContents="lax" /> 33 </xsd:complexType> 34 <xsd:complexType name="abstractRegistryConfig" > 35 <xsd:complexContent> 36 <xsd:extension base="abstractConfig"> 37 <xsd:attribute name="id" type="xsd:ID" /> 38 <xsd:attribute name="name" type="xsd:string" use="optional"> 39 <xsd:annotation> 40 <xsd:documentation><![CDATA[ 注册名称. ]]></xsd:documentation> 41 </xsd:annotation> 42 </xsd:attribute> 43 <xsd:attribute name="regProtocol" type="xsd:string" use="optional"> 44 <xsd:annotation> 45 <xsd:documentation><![CDATA[ 注册协议. ]]></xsd:documentation> 46 </xsd:annotation> 47 </xsd:attribute> 48 <xsd:attribute name="address" type="xsd:string" use="optional"> 49 <xsd:annotation> 50 <xsd:documentation><![CDATA[ 注册中心地址. ]]></xsd:documentation> 51 </xsd:annotation> 52 </xsd:attribute> 53 <xsd:attribute name="username" type="xsd:string" use="optional"> 54 <xsd:annotation> 55 <xsd:documentation><![CDATA[ 注册中心登录用户名. ]]></xsd:documentation> 56 </xsd:annotation> 57 </xsd:attribute> 58 <xsd:attribute name="password" type="xsd:string" use="optional"> 59 <xsd:annotation> 60 <xsd:documentation><![CDATA[ 注册中心登录密码. ]]></xsd:documentation> 61 </xsd:annotation> 62 </xsd:attribute> 63 <xsd:attribute name="port" type="xsd:string" use="optional"> 64 <xsd:annotation> 65 <xsd:documentation><![CDATA[ 注册中心缺省端口. ]]></xsd:documentation> 66 </xsd:annotation> 67 </xsd:attribute> 68 <xsd:attribute name="connectTimeout" type="xsd:integer" use="optional"> 69 <xsd:annotation> 70 <xsd:documentation><![CDATA[ 注册中心连接超时时间(毫秒). ]]></xsd:documentation> 71 </xsd:annotation> 72 </xsd:attribute> 73 <xsd:attribute name="requestTimeout" type="xsd:string" use="optional"> 74 <xsd:annotation> 75 <xsd:documentation><![CDATA[ 注册中心请求超时时间(毫秒). ]]></xsd:documentation> 76 </xsd:annotation> 77 </xsd:attribute> 78 <xsd:attribute name="registrySessionTimeout" type="xsd:integer" use="optional"> 79 <xsd:annotation> 80 <xsd:documentation><![CDATA[ 注册中心会话超时时间(毫秒). ]]></xsd:documentation> 81 </xsd:annotation> 82 </xsd:attribute> 83 <xsd:attribute name="registryRetryPeriod" type="xsd:integer" use="optional"> 84 <xsd:annotation> 85 <xsd:documentation><![CDATA[ registryRetryPeriod. ]]></xsd:documentation> 86 </xsd:annotation> 87 </xsd:attribute> 88 <xsd:attribute name="check" type="xsd:string" use="optional"> 89 <xsd:annotation> 90 <xsd:documentation><![CDATA[ 启动时检查注册中心是否存在. ]]></xsd:documentation> 91 </xsd:annotation> 92 </xsd:attribute> 93 <xsd:attribute name="dynamic" type="xsd:boolean" use="optional"> 94 <xsd:annotation> 95 <xsd:documentation><![CDATA[ 在该注册中心是否自动注册. ]]></xsd:documentation> 96 </xsd:annotation> 97 </xsd:attribute> 98 <xsd:attribute name="register" type="xsd:boolean" use="optional"> 99 <xsd:annotation> 100 <xsd:documentation><![CDATA[ 在该注册中心上服务是否暴露. ]]></xsd:documentation> 101 </xsd:annotation> 102 </xsd:attribute> 103 <xsd:attribute name="subscribe" type="xsd:boolean" use="optional"> 104 <xsd:annotation> 105 <xsd:documentation><![CDATA[ 在该注册中心上服务是否引用. ]]></xsd:documentation> 106 </xsd:annotation> 107 </xsd:attribute> 108 <xsd:attribute name="excise" type="xsd:string" use="optional"> 109 <xsd:annotation> 110 <xsd:documentation><![CDATA[ 注册中心移除策略,仅对vitage生效. ]]></xsd:documentation> 111 </xsd:annotation> 112 </xsd:attribute> 113 <xsd:attribute name="default" type="xsd:boolean" use="optional"> 114 <xsd:annotation> 115 <xsd:documentation><![CDATA[ is default protocol ]]></xsd:documentation> 116 </xsd:annotation> 117 </xsd:attribute> 118 119 </xsd:extension> 120 </xsd:complexContent> 121 </xsd:complexType> 122 <xsd:complexType name="abstractInterfaceConfig" > 123 <xsd:complexContent> 124 <xsd:extension base="abstractConfig"> 125 <xsd:attribute name="proxy" type="xsd:string" use="optional"> 126 <xsd:annotation> 127 <xsd:documentation><![CDATA[ 代理类型. ]]></xsd:documentation> 128 </xsd:annotation> 129 </xsd:attribute> 130 131 <xsd:attribute name="group" type="xsd:string" use="optional"> 132 <xsd:annotation> 133 <xsd:documentation><![CDATA[ 服务分组. ]]></xsd:documentation> 134 </xsd:annotation> 135 </xsd:attribute> 136 137 <xsd:attribute name="version" type="xsd:string" use="optional"> 138 <xsd:annotation> 139 <xsd:documentation><![CDATA[ version. ]]></xsd:documentation> 140 </xsd:annotation> 141 </xsd:attribute> 142 <xsd:attribute name="throwException" type="xsd:string" use="optional"> 143 <xsd:annotation> 144 <xsd:documentation><![CDATA[ throwException. ]]></xsd:documentation> 145 </xsd:annotation> 146 </xsd:attribute> 147 <xsd:attribute name="requestTimeout" type="xsd:string" use="optional"> 148 <xsd:annotation> 149 <xsd:documentation><![CDATA[ requestTimeout. ]]></xsd:documentation> 150 </xsd:annotation> 151 </xsd:attribute> 152 <xsd:attribute name="connectTimeout" type="xsd:string" use="optional"> 153 <xsd:annotation> 154 <xsd:documentation><![CDATA[ 连接请求超时时间(毫秒). ]]></xsd:documentation> 155 </xsd:annotation> 156 </xsd:attribute> 157 <xsd:attribute name="retries" type="xsd:integer" use="optional"> 158 <xsd:annotation> 159 <xsd:documentation><![CDATA[ retries ]]></xsd:documentation> 160 </xsd:annotation> 161 </xsd:attribute> 162 <xsd:attribute name="filter" type="xsd:string" use="optional"> 163 <xsd:annotation> 164 <xsd:documentation><![CDATA[ 过滤器配置. ]]></xsd:documentation> 165 </xsd:annotation> 166 </xsd:attribute> 167 <xsd:attribute name="listener" type="xsd:string" use="optional"> 168 <xsd:annotation> 169 <xsd:documentation><![CDATA[ 监听器配置. ]]></xsd:documentation> 170 </xsd:annotation> 171 </xsd:attribute> 172 <xsd:attribute name="connections" type="xsd:integer" use="optional"> 173 <xsd:annotation> 174 <xsd:documentation><![CDATA[ 连接数限制,0表示共享连接,否则为该服务独享连接数;默认共享. ]]></xsd:documentation> 175 </xsd:annotation> 176 </xsd:attribute> 177 <xsd:attribute name="application" type="xsd:string" use="optional"> 178 <xsd:annotation> 179 <xsd:documentation><![CDATA[ 应用信息. ]]></xsd:documentation> 180 </xsd:annotation> 181 </xsd:attribute> 182 <xsd:attribute name="module" type="xsd:string" use="optional"> 183 <xsd:annotation> 184 <xsd:documentation><![CDATA[ 模块信息. ]]></xsd:documentation> 185 </xsd:annotation> 186 </xsd:attribute> 187 <xsd:attribute name="shareChannel" type="xsd:boolean" use="optional"> 188 <xsd:annotation> 189 <xsd:documentation><![CDATA[ 是否共享channel. ]]></xsd:documentation> 190 </xsd:annotation> 191 </xsd:attribute> 192 <xsd:attribute name="timeout" type="xsd:integer" use="optional"> 193 <xsd:annotation> 194 <xsd:documentation><![CDATA[ The method invoke timeout. ]]></xsd:documentation> 195 </xsd:annotation> 196 </xsd:attribute> 197 <xsd:attribute name="actives" type="xsd:integer" use="optional"> 198 <xsd:annotation> 199 <xsd:documentation><![CDATA[ The max active requests. ]]></xsd:documentation> 200 </xsd:annotation> 201 </xsd:attribute> 202 <xsd:attribute name="async" type="xsd:boolean" use="optional"> 203 <xsd:annotation> 204 <xsd:documentation><![CDATA[ The method does async. ]]></xsd:documentation> 205 </xsd:annotation> 206 </xsd:attribute> 207 <xsd:attribute name="mock" type="xsd:string" use="optional"> 208 <xsd:annotation> 209 <xsd:documentation><![CDATA[ Use service mock implemention. ]]></xsd:documentation> 210 </xsd:annotation> 211 </xsd:attribute> 212 <xsd:attribute name="check" type="xsd:string" use="optional"> 213 <xsd:annotation> 214 <xsd:documentation><![CDATA[ 检查服务提供者是否存在 ]]></xsd:documentation> 215 </xsd:annotation> 216 </xsd:attribute> 217 <xsd:attribute name="registry" type="xsd:string" use="optional"> 218 <xsd:annotation> 219 <xsd:documentation><![CDATA[ 注册中心的id列表,多个用“,”分隔,如果为空,则使用所有的配置中心. ]]></xsd:documentation> 220 </xsd:annotation> 221 </xsd:attribute> 222 <xsd:attribute name="register" type="xsd:boolean" use="optional"> 223 <xsd:annotation> 224 <xsd:documentation><![CDATA[ 在该注册中心上服务是否暴露. ]]></xsd:documentation> 225 </xsd:annotation> 226 </xsd:attribute> 227 <xsd:attribute name="subscribe" type="xsd:boolean" use="optional"> 228 <xsd:annotation> 229 <xsd:documentation><![CDATA[ 在该注册中心上服务是否引用. ]]></xsd:documentation> 230 </xsd:annotation> 231 </xsd:attribute> 232 <xsd:attribute name="accessLog" type="xsd:string" use="optional"> 233 <xsd:annotation> 234 <xsd:documentation><![CDATA[ accessLog ]]></xsd:documentation> 235 </xsd:annotation> 236 </xsd:attribute> 237 <xsd:attribute name="localServiceAddress" type="xsd:string" use="optional"> 238 <xsd:annotation> 239 <xsd:documentation><![CDATA[ 当使用VintageRetryLookupRegistry时,从config server同步三次失败并且feature.motanmcq.loadaddressfromfs开关打开时,把这个配置指定的地址作为服务地址,以逗号分割 ]]></xsd:documentation> 240 </xsd:annotation> 241 </xsd:attribute> 242 <xsd:attribute name="usegz" type="xsd:boolean" use="optional"> 243 <xsd:annotation> 244 <xsd:documentation><![CDATA[ 是否开启gzip压缩.只有compressMotan的codec才能支持 ]]></xsd:documentation> 245 </xsd:annotation> 246 </xsd:attribute> 247 <xsd:attribute name="mingzSize" type="xsd:integer" use="optional"> 248 <xsd:annotation> 249 <xsd:documentation><![CDATA[ 开启gzip压缩的阈值.usegz开关开启,且传输数据大于此阈值时,才会进行gzip压缩。只有compressMotan的codec才能支持 ]]></xsd:documentation> 250 </xsd:annotation> 251 </xsd:attribute> 252 <xsd:attribute name="codec" type="xsd:string" use="optional"> 253 <xsd:annotation> 254 <xsd:documentation><![CDATA[ 协议编码. ]]></xsd:documentation> 255 </xsd:annotation> 256 </xsd:attribute> 257 </xsd:extension> 258 </xsd:complexContent> 259 </xsd:complexType> 260 261 <xsd:complexType name="abstractProtocolConfig"> 262 <xsd:complexContent> 263 <xsd:extension base="abstractConfig"> 264 <xsd:attribute name="id" type="xsd:ID" /> 265 <xsd:attribute name="name" type="xsd:string" use="required"> 266 <xsd:annotation> 267 <xsd:documentation><![CDATA[ 服务协议 ]]></xsd:documentation> 268 </xsd:annotation> 269 </xsd:attribute> 270 <xsd:attribute name="serialization" type="xsd:string" use="optional"> 271 <xsd:annotation> 272 <xsd:documentation><![CDATA[ 序列化方式 ]]></xsd:documentation> 273 </xsd:annotation> 274 </xsd:attribute> 275 <xsd:attribute name="payload" type="xsd:integer" use="optional"> 276 <xsd:annotation> 277 <xsd:documentation><![CDATA[ 最大请求数据长度 ]]></xsd:documentation> 278 </xsd:annotation> 279 </xsd:attribute> 280 <xsd:attribute name="buffer" type="xsd:integer" use="optional"> 281 <xsd:annotation> 282 <xsd:documentation><![CDATA[ 缓存区大小 ]]></xsd:documentation> 283 </xsd:annotation> 284 </xsd:attribute> 285 <xsd:attribute name="heartbeat" type="xsd:integer" use="optional"> 286 <xsd:annotation> 287 <xsd:documentation><![CDATA[ 心跳间隔 ]]></xsd:documentation> 288 </xsd:annotation> 289 </xsd:attribute> 290 <xsd:attribute name="transporter" type="xsd:string" use="optional"> 291 <xsd:annotation> 292 <xsd:documentation><![CDATA[ 网络传输方式 ]]></xsd:documentation> 293 </xsd:annotation> 294 </xsd:attribute> 295 <xsd:attribute name="threads" type="xsd:integer" use="optional"> 296 <xsd:annotation> 297 <xsd:documentation><![CDATA[ 线程池大小 ]]></xsd:documentation> 298 </xsd:annotation> 299 </xsd:attribute> 300 <xsd:attribute name="iothreads" type="xsd:integer" use="optional"> 301 <xsd:annotation> 302 <xsd:documentation><![CDATA[ IO线程池大小 ]]></xsd:documentation> 303 </xsd:annotation> 304 </xsd:attribute> 305 <xsd:attribute name="requestTimeout" type="xsd:string" use="optional"> 306 <xsd:annotation> 307 <xsd:documentation><![CDATA[ 请求超时 ]]></xsd:documentation> 308 </xsd:annotation> 309 </xsd:attribute> 310 <xsd:attribute name="minClientConnection" type="xsd:integer" use="optional"> 311 <xsd:annotation> 312 <xsd:documentation><![CDATA[ minClientConnection ]]></xsd:documentation> 313 </xsd:annotation> 314 </xsd:attribute> 315 <xsd:attribute name="maxClientConnection" type="xsd:integer" use="optional"> 316 <xsd:annotation> 317 <xsd:documentation><![CDATA[ maxClientConnection ]]></xsd:documentation> 318 </xsd:annotation> 319 </xsd:attribute> 320 321 <xsd:attribute name="minWorkerThread" type="xsd:integer" use="optional"> 322 <xsd:annotation> 323 <xsd:documentation><![CDATA[ minWorkerThread ]]></xsd:documentation> 324 </xsd:annotation> 325 </xsd:attribute> 326 <xsd:attribute name="maxWorkerThread" type="xsd:integer" use="optional"> 327 <xsd:annotation> 328 <xsd:documentation><![CDATA[ maxWorkerThread ]]></xsd:documentation> 329 </xsd:annotation> 330 </xsd:attribute> 331 <xsd:attribute name="maxContentLength" type="xsd:integer" use="optional"> 332 <xsd:annotation> 333 <xsd:documentation><![CDATA[ maxContentLength ]]></xsd:documentation> 334 </xsd:annotation> 335 </xsd:attribute> 336 <xsd:attribute name="maxServerConnection" type="xsd:integer" use="optional"> 337 <xsd:annotation> 338 <xsd:documentation><![CDATA[ maxContentLength ]]></xsd:documentation> 339 </xsd:annotation> 340 </xsd:attribute> 341 <xsd:attribute name="poolLifo" type="xsd:boolean" use="optional"> 342 <xsd:annotation> 343 <xsd:documentation><![CDATA[ is poolLifo ]]></xsd:documentation> 344 </xsd:annotation> 345 </xsd:attribute> 346 <xsd:attribute name="lazyInit" type="xsd:boolean" use="optional"> 347 <xsd:annotation> 348 <xsd:documentation><![CDATA[ is lazyInit ]]></xsd:documentation> 349 </xsd:annotation> 350 </xsd:attribute> 351 <xsd:attribute name="endpointFactory" type="xsd:string" use="optional"> 352 <xsd:annotation> 353 <xsd:documentation><![CDATA[ endpointFactory ]]></xsd:documentation> 354 </xsd:annotation> 355 </xsd:attribute> 356 <xsd:attribute name="cluster" type="xsd:string" use="optional"> 357 <xsd:annotation> 358 <xsd:documentation><![CDATA[ cluster ]]></xsd:documentation> 359 </xsd:annotation> 360 </xsd:attribute> 361 <xsd:attribute name="loadbalance" type="xsd:string" use="optional"> 362 <xsd:annotation> 363 <xsd:documentation><![CDATA[ loadbalance ]]></xsd:documentation> 364 </xsd:annotation> 365 </xsd:attribute> 366 <xsd:attribute name="haStrategy" type="xsd:string" use="optional"> 367 <xsd:annotation> 368 <xsd:documentation><![CDATA[ haStrategy ]]></xsd:documentation> 369 </xsd:annotation> 370 </xsd:attribute> 371 <xsd:attribute name="workerQueueSize" type="xsd:integer" use="optional"> 372 <xsd:annotation> 373 <xsd:documentation><![CDATA[ workerQueueSize ]]></xsd:documentation> 374 </xsd:annotation> 375 </xsd:attribute> 376 <xsd:attribute name="acceptConnections" type="xsd:integer" use="optional"> 377 <xsd:annotation> 378 <xsd:documentation><![CDATA[ acceptConnections ]]></xsd:documentation> 379 </xsd:annotation> 380 </xsd:attribute> 381 382 <xsd:attribute name="proxy" type="xsd:string" use="optional"> 383 <xsd:annotation> 384 <xsd:documentation><![CDATA[ proxy ]]></xsd:documentation> 385 </xsd:annotation> 386 </xsd:attribute> 387 388 <xsd:attribute name="filter" type="xsd:string" use="optional"> 389 <xsd:annotation> 390 <xsd:documentation><![CDATA[ filter ]]></xsd:documentation> 391 </xsd:annotation> 392 </xsd:attribute> 393 <xsd:attribute name="retries" type="xsd:integer" use="optional"> 394 <xsd:annotation> 395 <xsd:documentation><![CDATA[ retries ]]></xsd:documentation> 396 </xsd:annotation> 397 </xsd:attribute> 398 <xsd:attribute name="async" type="xsd:boolean" use="optional"> 399 <xsd:annotation> 400 <xsd:documentation><![CDATA[ is async ]]></xsd:documentation> 401 </xsd:annotation> 402 </xsd:attribute> 403 <xsd:attribute name="queueSize" type="xsd:integer" use="optional"> 404 <xsd:annotation> 405 <xsd:documentation><![CDATA[ 线程池队列大小 ]]></xsd:documentation> 406 </xsd:annotation> 407 </xsd:attribute> 408 <xsd:attribute name="accepts" type="xsd:integer" use="optional"> 409 <xsd:annotation> 410 <xsd:documentation><![CDATA[ 最大接收连接数 ]]></xsd:documentation> 411 </xsd:annotation> 412 </xsd:attribute> 413 <xsd:attribute name="dispatcher" type="xsd:string" use="optional"> 414 <xsd:annotation> 415 <xsd:documentation><![CDATA[ 信息线程模型派发方式 ]]></xsd:documentation> 416 </xsd:annotation> 417 </xsd:attribute> 418 <xsd:attribute name="server" type="xsd:string" use="optional"> 419 <xsd:annotation> 420 <xsd:documentation><![CDATA[ 服务器端实现 ]]></xsd:documentation> 421 </xsd:annotation> 422 </xsd:attribute> 423 <xsd:attribute name="client" type="xsd:string" use="optional"> 424 <xsd:annotation> 425 <xsd:documentation><![CDATA[ 客户端端实现 ]]></xsd:documentation> 426 </xsd:annotation> 427 </xsd:attribute> 428 429 <xsd:attribute name="codec" type="xsd:string" use="optional"> 430 <xsd:annotation> 431 <xsd:documentation><![CDATA[ codec ]]></xsd:documentation> 432 </xsd:annotation> 433 </xsd:attribute> 434 <xsd:attribute name="default" type="xsd:boolean" use="optional"> 435 <xsd:annotation> 436 <xsd:documentation><![CDATA[ is default protocol ]]></xsd:documentation> 437 </xsd:annotation> 438 </xsd:attribute> 439 <xsd:attribute name="switcherService" type="xsd:string" use="optional"> 440 <xsd:annotation> 441 <xsd:documentation><![CDATA[ switcherService ]]></xsd:documentation> 442 </xsd:annotation> 443 </xsd:attribute> 444 <xsd:attribute name="heartbeatFactory" type="xsd:string" use="optional"> 445 <xsd:annotation> 446 <xsd:documentation><![CDATA[ heartbeatFactory ]]></xsd:documentation> 447 </xsd:annotation> 448 </xsd:attribute> 449 </xsd:extension> 450 </xsd:complexContent> 451 </xsd:complexType> 452 453 <xsd:element name="protocol" type="abstractProtocolConfig"> 454 <xsd:annotation> 455 <xsd:documentation><![CDATA[ Service provider config ]]></xsd:documentation> 456 </xsd:annotation> 457 </xsd:element> 458 <xsd:element name="registry" type="abstractRegistryConfig"> 459 <xsd:annotation> 460 <xsd:documentation><![CDATA[ Registry config ]]></xsd:documentation> 461 </xsd:annotation> 462 </xsd:element> 463 <xsd:element name="method"> 464 <xsd:complexType> 465 <xsd:attribute name="name" type="xsd:string" use="required"> 466 <xsd:annotation> 467 <xsd:documentation><![CDATA[ The method name (method.toString()). ]]></xsd:documentation> 468 </xsd:annotation> 469 </xsd:attribute> 470 <xsd:attribute name="argumentTypes" type="xsd:string" use="optional"> 471 <xsd:annotation> 472 <xsd:documentation><![CDATA[ 参数类型(逗号分隔), 无参数用void. 如果方法无重载,则可不写 ]]></xsd:documentation> 473 </xsd:annotation> 474 </xsd:attribute> 475 <xsd:attribute name="requestTimeout" type="xsd:string" use="optional"> 476 <xsd:annotation> 477 <xsd:documentation><![CDATA[ The method invoke timeout. ]]></xsd:documentation> 478 </xsd:annotation> 479 </xsd:attribute> 480 <xsd:attribute name="retries" type="xsd:string" use="optional"> 481 <xsd:annotation> 482 <xsd:documentation><![CDATA[ The method retry times. ]]></xsd:documentation> 483 </xsd:annotation> 484 </xsd:attribute> 485 </xsd:complexType> 486 </xsd:element> 487 <xsd:element name="service"> 488 <xsd:complexType> 489 <xsd:complexContent> 490 <xsd:extension base="abstractInterfaceConfig"> 491 <xsd:choice minOccurs="0" maxOccurs="unbounded"> 492 <xsd:element ref="method" minOccurs="0" maxOccurs="unbounded" /> 493 <xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" /> 494 </xsd:choice> 495 <xsd:attribute name="id" type="xsd:ID" /> 496 <xsd:attribute name="export" type="xsd:string" use="optional"> 497 <xsd:annotation> 498 <xsd:documentation><![CDATA[ 服务暴露的方式,包含协议及端口号,多个协议端口用"," 分隔. ]]></xsd:documentation> 499 </xsd:annotation> 500 </xsd:attribute> 501 <xsd:attribute name="basicService" type="xsd:string" use="optional"> 502 <xsd:annotation> 503 <xsd:documentation><![CDATA[ 基本service配置 ]]></xsd:documentation> 504 </xsd:annotation> 505 </xsd:attribute> 506 <xsd:attribute name="host" type="xsd:string" use="optional"> 507 <xsd:annotation> 508 <xsd:documentation><![CDATA[ 如果有多个ip,但只想暴露指定的某个ip,设置该参数 ]]></xsd:documentation> 509 </xsd:annotation> 510 </xsd:attribute> 511 <xsd:attribute name="interface" type="xsd:token"> 512 <xsd:annotation> 513 <xsd:documentation><![CDATA[ Defines the interface to advertise for this service in the service registry. ]]></xsd:documentation> 514 <xsd:appinfo> 515 <tool:annotation> 516 <tool:expected-type type="java.lang.Class"/> 517 </tool:annotation> 518 </xsd:appinfo> 519 </xsd:annotation> 520 </xsd:attribute> 521 522 <xsd:attribute name="ref" type="xsd:string" use="optional"> 523 <xsd:annotation> 524 <xsd:documentation><![CDATA[ The service implementation instance bean id. ]]></xsd:documentation> 525 </xsd:annotation> 526 </xsd:attribute> 527 <xsd:attribute name="class" type="xsd:string" use="optional"> 528 <xsd:annotation> 529 <xsd:documentation><![CDATA[ The service implementation class name. ]]></xsd:documentation> 530 </xsd:annotation> 531 </xsd:attribute> 532 533 <xsd:attribute name="path" type="xsd:string" use="optional"> 534 <xsd:annotation> 535 <xsd:documentation><![CDATA[ The service path. ]]></xsd:documentation> 536 </xsd:annotation> 537 </xsd:attribute> 538 <xsd:attribute name="serialization" type="xsd:string" use="optional"> 539 <xsd:annotation> 540 <xsd:documentation><![CDATA[ 序列化方式. ]]></xsd:documentation> 541 </xsd:annotation> 542 </xsd:attribute> 543 <xsd:attribute name="extConfig" type="xsd:string" use="optional"> 544 <xsd:annotation> 545 <xsd:documentation><![CDATA[ 扩展配置. ]]></xsd:documentation> 546 </xsd:annotation> 547 </xsd:attribute> 548 </xsd:extension> 549 </xsd:complexContent> 550 </xsd:complexType> 551 </xsd:element> 552 <xsd:element name="referer"> 553 <xsd:complexType> 554 <xsd:complexContent> 555 <xsd:extension base="abstractInterfaceConfig"> 556 <xsd:choice minOccurs="0" maxOccurs="unbounded"> 557 <xsd:element ref="method" minOccurs="0" maxOccurs="unbounded" /> 558 <xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" /> 559 </xsd:choice> 560 <xsd:attribute name="id" type="xsd:ID" /> 561 <xsd:attribute name="protocol" type="xsd:string" use="optional"> 562 <xsd:annotation> 563 <xsd:documentation><![CDATA[ 使用的协议 ]]></xsd:documentation> 564 </xsd:annotation> 565 </xsd:attribute> 566 <xsd:attribute name="interface" type="xsd:token" use="required"> 567 <xsd:annotation> 568 <xsd:documentation><![CDATA[ The service interface class name. ]]></xsd:documentation> 569 <xsd:appinfo> 570 <tool:annotation> 571 <tool:expected-type type="java.lang.Class"/> 572 </tool:annotation> 573 </xsd:appinfo> 574 </xsd:annotation> 575 </xsd:attribute> 576 <xsd:attribute name="client" type="xsd:string" use="optional"> 577 <xsd:annotation> 578 <xsd:documentation><![CDATA[ 客户端类型 ]]></xsd:documentation> 579 </xsd:annotation> 580 </xsd:attribute> 581 <xsd:attribute name="directUrl" type="xsd:string" use="optional"> 582 <xsd:annotation> 583 <xsd:documentation><![CDATA[点对点直连服务提供地址 ]]></xsd:documentation> 584 </xsd:annotation> 585 </xsd:attribute> 586 <xsd:attribute name="basicReferer" type="xsd:string" use="optional"> 587 <xsd:annotation> 588 <xsd:documentation><![CDATA[ 基本referer配置 ]]></xsd:documentation> 589 </xsd:annotation> 590 </xsd:attribute> 591 <xsd:attribute name="extConfig" type="xsd:string" use="optional"> 592 <xsd:annotation> 593 <xsd:documentation><![CDATA[ 扩展配置. ]]></xsd:documentation> 594 </xsd:annotation> 595 </xsd:attribute> 596 </xsd:extension> 597 </xsd:complexContent> 598 </xsd:complexType> 599 </xsd:element> 600 601 <xsd:element name="basicService"> 602 <xsd:complexType> 603 <xsd:complexContent> 604 <xsd:extension base="abstractInterfaceConfig"> 605 <xsd:attribute name="id" type="xsd:ID" /> 606 <xsd:attribute name="export" type="xsd:string" use="optional"> 607 <xsd:annotation> 608 <xsd:documentation><![CDATA[ 暴露的协议及端口,多个协议端口之间用","分隔 ]]></xsd:documentation> 609 </xsd:annotation> 610 </xsd:attribute> 611 <xsd:attribute name="host" type="xsd:string" use="optional"> 612 <xsd:annotation> 613 <xsd:documentation><![CDATA[ 如果有多个ip,但只想暴露指定的某个ip,设置该参数 ]]></xsd:documentation> 614 </xsd:annotation> 615 </xsd:attribute> 616 </xsd:extension> 617 </xsd:complexContent> 618 </xsd:complexType> 619 </xsd:element> 620 621 <xsd:element name="basicReferer"> 622 <xsd:complexType> 623 <xsd:complexContent> 624 <xsd:extension base="abstractInterfaceConfig"> 625 <xsd:attribute name="id" type="xsd:ID" /> 626 <xsd:attribute name="protocol" type="xsd:string" use="optional"> 627 <xsd:annotation> 628 <xsd:documentation><![CDATA[ 使用的协议 ]]></xsd:documentation> 629 </xsd:annotation> 630 </xsd:attribute> 631 <xsd:attribute name="mean" type="xsd:string" use="optional"> 632 <xsd:annotation> 633 <xsd:documentation><![CDATA[ SLA平均响应时间 ]]></xsd:documentation> 634 </xsd:annotation> 635 </xsd:attribute> 636 <xsd:attribute name="p90" type="xsd:string" use="optional"> 637 <xsd:annotation> 638 <xsd:documentation><![CDATA[ SLA90%的响应时间 ]]></xsd:documentation> 639 </xsd:annotation> 640 </xsd:attribute> 641 <xsd:attribute name="p99" type="xsd:string" use="optional"> 642 <xsd:annotation> 643 <xsd:documentation><![CDATA[ SLA99%的响应时间 ]]></xsd:documentation> 644 </xsd:annotation> 645 </xsd:attribute> 646 <xsd:attribute name="p999" type="xsd:string" use="optional"> 647 <xsd:annotation> 648 <xsd:documentation><![CDATA[ SLA999%的响应时间 ]]></xsd:documentation> 649 </xsd:annotation> 650 </xsd:attribute> 651 <xsd:attribute name="errorRate" type="xsd:string" use="optional"> 652 <xsd:annotation> 653 <xsd:documentation><![CDATA[ SLA错误率 ]]></xsd:documentation> 654 </xsd:annotation> 655 </xsd:attribute> 656 </xsd:extension> 657 </xsd:complexContent> 658 </xsd:complexType> 659 </xsd:element> 660 661 <xsd:element name="spi"> 662 <xsd:complexType> 663 <xsd:complexContent> 664 <xsd:extension base="abstractConfig"> 665 <xsd:attribute name="interfaceClass" type="xsd:token"> 666 <xsd:annotation> 667 <xsd:documentation><![CDATA[ spi interface ]]></xsd:documentation> 668 <xsd:appinfo> 669 <tool:annotation> 670 <tool:expected-type type="java.lang.Class" /> 671 </tool:annotation> 672 </xsd:appinfo> 673 </xsd:annotation> 674 </xsd:attribute> 675 <xsd:attribute name="spiClass" type="xsd:token"> 676 <xsd:annotation> 677 <xsd:documentation><![CDATA[ spi impl ]]></xsd:documentation> 678 <xsd:appinfo> 679 <tool:annotation> 680 <tool:expected-type type="java.lang.Class" /> 681 </tool:annotation> 682 </xsd:appinfo> 683 </xsd:annotation> 684 </xsd:attribute> 685 </xsd:extension> 686 </xsd:complexContent> 687 </xsd:complexType> 688 </xsd:element> 689 690 </xsd:schema>
2.有个标签的格式,还需要标签的处理器,标签的处理器只要简单的继承NamespaceHandlerSupport这个类,具体的类如下,其中在init方法中,定义了标签和对应的解析器。motan中的对XML的解析起都是MotanBeanDefinitionParser,最终一对标签,最终转化为相应的BeanDefination.并放在一个并发的hashMap中,key为id,value是相应的beanDefination.
public class MotanNamespaceHandler extends NamespaceHandlerSupport {
public final static Set<String> protocolDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> registryDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> basicServiceConfigDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> basicRefererConfigDefineNames = new ConcurrentHashSet<String>();
@Override
public void init() {
registerBeanDefinitionParser("referer", new MotanBeanDefinitionParser(RefererConfigBean.class, false));
registerBeanDefinitionParser("service", new MotanBeanDefinitionParser(ServiceConfigBean.class, true));
registerBeanDefinitionParser("protocol", new MotanBeanDefinitionParser(ProtocolConfig.class, true));
registerBeanDefinitionParser("registry", new MotanBeanDefinitionParser(RegistryConfig.class, true));
registerBeanDefinitionParser("basicService", new MotanBeanDefinitionParser(BasicServiceInterfaceConfig.class, true));
registerBeanDefinitionParser("basicReferer", new MotanBeanDefinitionParser(BasicRefererInterfaceConfig.class, true));
registerBeanDefinitionParser("spi", new MotanBeanDefinitionParser(SpiConfigBean.class, true));
}
}