Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

针对有界容器提供自动创建镜像容器的功能 #128

Open
Createsequence opened this issue Aug 9, 2023 · 0 comments
Open

针对有界容器提供自动创建镜像容器的功能 #128

Createsequence opened this issue Aug 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Createsequence
Copy link
Collaborator

基于 #119 ,我们应当基于 Container 接口提供一个新的子接口 LimitedContainer,它用于表示一个仅包含了固定的、有限个数数据源对象的容器。

针对该类型的容器,我们可以提供一个自动生成镜像的功能,即自动为其创建一个 key-value 翻转的版本,就像 Guava 中的 BiMap 那样。比如:

// 原始容器
Map<String, String> origin = new HashMap<>();
origin.put("one", "1");
origin.put("two", "2");
origin.put("three", "3");
LimitedContainer<String> contanier = Containers.forMap("test", origin);
containerManager.registerContanier(contanier);

// 当注册到容器之后,自动为其生成一个镜像容器(若有必要),该镜像容器的命名空间与原始的容器有所区别
imitedContainer<String> mirrorContainer = containerManager.getContainer("test_reverse");
mirrorContainer.getAll(); // [{"1"="one"}, {"2"="two"}, {"3"="three"}]

该功能需要考虑两方面的因素:

  • 在什么时候创建镜像容器?可以考虑基于 ContainerLifeProcessor 完成,在容器创建后自动为其创建,或者提供一个独立的 ContainerProvider 负责为所有的容器提供镜像版本;
  • 如何知道是否要创建镜像容器?考虑在向 ContainerManager 注册容器的时候就加以区分,或者想办法给个注解作为元数据用于区分;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant