shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

Using Visitor pattern to decouple the Selector and Rule from doExecute() method.

Open lmhmhl opened this issue 5 years ago • 10 comments

Feature Request

Due to the basic data structure in Soul(Selector, Rule) are stable and immune to change, visitor design pattern is very suitable for this scenario, and different Plugins play roles as Visitor, providing different visit method implementation. I plan to use this pattern to decouple the Selector and Rule from doExecute() method, and Improve the expansibility of program。

Example in divide plugin

public Mono execute(final ServerWebExchange exchange, final SoulPluginChain chain) { ........ ........ //return doExecute(exchange, chain, selectorData, rule);
// rewriting example selectorData.accept(this); rule.accept(this); return doExecute(exchange,chain); ..... }

lmhmhl avatar Dec 11 '20 09:12 lmhmhl

good

yu199195 avatar Dec 11 '20 10:12 yu199195

@lmhmhl Is this mission in progress? you can join us in weixin group

yu199195 avatar Dec 17 '20 13:12 yu199195

@lmhmhl Is this mission in progress? you can join us in weixin group

how join,i want join

yangzhiw avatar Dec 31 '20 09:12 yangzhiw

@lmhmhl Is this mission in progress? you can join us in weixin group

Hello, I have tried to refractor the code, but some new questions occurred, when I decouple the rule and selector in doExecute method, and invoke visit() method in every single plugin to visit selector and rule, I suddenly aware that some thread-safe problem may happen, because visit() and doExecute() are different method, and visit method return void, when some visit operation happpens in visit, It should keep a global variable to pass the selector and rule in doExecute method doing message passing, I come up with a solution that we can use ThreadLocal variable to store selector and rule and can be passed to deExecute() method, but It is not so elegant, so I stuck there for a long time, I will be very happy if you can offer me some advices. Thx. @yu199195 @yangzhiw

lmhmhl avatar Dec 31 '20 13:12 lmhmhl

If it's hard to change or if you don't understand how it works, don't do it

yu199195 avatar Jan 01 '21 02:01 yu199195

This senerio is suitable for visitor, may be u can add a discuss to gather more solutions.

lmhmhl avatar Jan 01 '21 09:01 lmhmhl

@yangzhiw Can you leave your wechat here? I can invite you to join. : )

dengliming avatar Jan 01 '21 15:01 dengliming

@yangzhiw Can you leave your wechat here? I can invite you to join. : )

lmh8899000 thx.

lmhmhl avatar Jan 01 '21 16:01 lmhmhl

@yangzhiw Can you leave your wechat here? I can invite you to join. : ) wechat: juzi222666
thx!

yangzhiw avatar Jan 02 '21 09:01 yangzhiw

No progress. Closing it and please feel free to reopen it if you have any question.

dengliming avatar Feb 26 '21 03:02 dengliming