Drools: Why stateless sessions?

我是研究僧i 提交于 2019-12-12 09:01:08

问题


Drools uses sessions to store runtime data. For this purpose there are two kinds of sessions: stateless and stateful. In contrast to stateless sessions, stateful sessions allow iterative invocation and seem to have all advantages over stateless sessions.

So why are there even stateless sessions? What is the purpose they serve? And what are their advantage over stateful sessions?

Thank you.


回答1:


As for many other general stateless scenarios, a Drools stateless session could be helpful for filtering or data-preprocessing, or data validation.

I have experienced the need of both Stateful and Stateless sessions in Drools, for different use-cases; for stateless use case some examples:

  • Data validation: rules define the validation constraints, when a message / business object is received it is validated against the rule
  • Filtering: rules define if a given message is passed down/forward the data pipeline
  • Preprocessing: rules define how a message / business object is preformatted or adapted before being passed down/forward the data pipeline

In these example you notice how the session doesn't need to hold any state after the object have been evaluated against the rule. In these examples is better to just discard the session and create a new one for the next message/object, because they can be evaluated complete separately. Technically if the rule are well defined the behavior would be idempotent, meaning if you (inadvertently?) cycle the same object/message again, the result would be the same. Finally, when I say object/message it doesn't necessarily mean a single Pojo, it could be a Collection of objects.



来源:https://stackoverflow.com/questions/28710711/drools-why-stateless-sessions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!