-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
binghe001
committed
Sep 30, 2024
1 parent
1147207
commit 3c993fd
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: 第10节:网关上下文属性工厂与实现类设计 | ||
pay: https://articles.zsxq.com/id_nfsida8av2j0.html | ||
--- | ||
|
||
# 《高性能Polaris网关》通用模型-第10节:网关上下文属性工厂与实现类设计 | ||
|
||
作者:冰河 | ||
<br/>星球:[http://m6z.cn/6aeFbs](http://m6z.cn/6aeFbs) | ||
<br/>博客:[https://binghe.gitcode.host](https://binghe.gitcode.host) | ||
<br/>文章汇总:[https://binghe.gitcode.host/md/all/all.html](https://binghe.gitcode.host/md/all/all.html) | ||
<br/>源码获取地址:[https://t.zsxq.com/0dhvFs5oR](https://t.zsxq.com/0dhvFs5oR) | ||
|
||
> 沉淀,成长,突破,帮助他人,成就自我。 | ||
* 本章难度:★★☆☆☆ | ||
* 本节重点:对高性能Polaris网关的上下文属性工厂与实现类进行设计,从全局角度掌握高性能Polaris网关上下文属性工厂与实现类的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
**大家好,我是冰河~~** | ||
|
||
在网关的上下文属性设计中,已经完成了网关上下文属性顶层接口和抽象类的设计。可以说,已经完成了网关上下文属性最核心的设计。但是,目前,网关上下文属性的方法只能在同一个Java包下调用,并且除了接口和抽象类外,也并未实现具体的类来最终实例化属性对象。为了,需要设计网关的上下文属性工厂类和具体实现类来满足网关对上下文属性的需求。 | ||
|
||
## 一、前言 | ||
|
||
在前面的文章中,已经对高性能Polaris网关的请求与响应模型的顶层接口和实现进行了设计,对调用链路的顶层接口与抽象类模型进行了设计和实现,又对网关服务的定义与实例模型和服务配置的缓存接口与实现类进行了设计。随后,从网关上下文的角度,又对网关上下文的顶层接口和抽象类进行了设计。接下来,就对网关上下文属性工厂和实现类进行设计。 | ||
|
||
## 二、本节诉求 | ||
|
||
对高性能Polaris网关的上下文属性工厂与实现类进行设计,从全局角度掌握高性能Polaris网关上下文属性工厂与实现类的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
## 三、类结构设计 | ||
|
||
网关的上下文属性工厂与实现类进行设计如图10-1所示。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-30-001.png?raw=true" width="70%"> | ||
<br/> | ||
</div> | ||
|
||
可以看到,类结构设计上,在《[第09节:网关上下文属性顶层接口与抽象类设计](https://articles.zsxq.com/id_uagjqbe799kd.html)》的基础上,新增了AttributeKeyFactory工厂类和ContextAttributeKey实现类。具体说明如下所示。 | ||
|
||
**(1)AttributeKeyFactory工厂类** | ||
|
||
AttributeKeyFactory类是网关上下文属性的工厂类,其他模块最终会通过调用AttributeKeyFactory工厂的方法获取数据,包含的方法如下: | ||
|
||
* getHttpInvoker()方法:获取HttpInvoker类型的AttributeKey对象。 | ||
* getRpcInvoker()方法:获取RpcInvoker类型的AttributeKey对象。 | ||
* getWebSocketInvoker()方法:获取WebSocketInvoker类型的AttributeKey对象。 | ||
* getMatchInstances()方法:获取匹配到的所有服务实例列表,后续可用于负载均衡。 | ||
* getLoadInstance()方法:获取通过负载均衡后选出的服务实例。 | ||
* getAttachment()方法:获取通过RPC透传的参数。 | ||
* getAttributeKey(String name):通过传入的name获取指定的AttributeKey对象。 | ||
|
||
**(2)ContextAttributeKey类** | ||
|
||
ContextAttributeKey类是网关上下文属性的最终实现类,包含的字段和方法如下: | ||
|
||
* valueClass常量:Class<T>类型,主要用于将Object类型的数据转换成泛型T类型。 | ||
* ContextAttributeKey():Java包级别的构造方法,用于创建ContextAttributeKey类的对象。 | ||
* cast()方法:将Object类型的对象转换成泛型T类型。 | ||
* toString()方法:输出ContextAttributeKey类的信息。 | ||
|
||
## 四、编码实现 | ||
|
||
接下来,就对网关上下文属性工厂与实现类进行编码实现。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 | ||
|