Drools:为什么要进行无状态会话? [英] Drools: Why stateless sessions?

查看:312
本文介绍了Drools:为什么要进行无状态会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Drools使用会话来存储运行时数据。为此目的,有两种会话:无状态会话和有状态会话。与无状态会话相比,有状态会话允许迭代调用,并且似乎比无状态会话具有所有优势。

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?

谢谢。

推荐答案

对于许多其他一般的无状态场景,Drools无状态会话可能有助于过滤或数据预处理或数据验证。

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

对于不同的用例,我已经经历了在Drools中进行有状态和无状态会话的需求;对于无状态用例,例如:

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

在这些示例中,您注意到在根据规则评估对象之后,会话无需保持任何状态。在这些示例中,最好丢弃该会话并为下一个消息/对象创建一个新会话,因为可以分别评估它们是否完整。从技术上讲,如果规则定义明确,则行为将是幂等的,这意味着如果(无意间?)再次循环同一对象/消息,结果将是相同的。最后,当我说对象/消息不一定表示一个Pojo时,它可能是对象的集合。

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.

这篇关于Drools:为什么要进行无状态会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆