首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在drools-fusion中编写动态时态规则

如何在drools-fusion中编写动态时态规则
EN

Stack Overflow用户
提问于 2013-09-30 14:47:12
回答 1查看 482关注 0票数 1

我正在尝试为一个事件编写一条规则,该规则需要检查在其他事件发生后的某个时间窗口内是否发生了某些事情。目前,代码看起来像这样(它可以正常工作):

代码语言:javascript
复制
    rule "Detect BPM reseed not starting when requested from Mart"
        when
            $martDailyRefreshRequestedEvent: MessageSentEvent(
                $correlationId: correlationId,
                $when: timestamp,
                messageTypeName == "MartDailyRefreshCompletedEvent")
                    from entry-point "mart"
            not ( MessageHandleStartedEvent(
                    this after[0ms, 30s] $martDailyRefreshRequestedEvent, 
                    correlationId == $correlationId,
                    messageTypeName == "MartDailyRefreshCompletedEvent") 
                            from entry-point "bpm")
        then
            notifier.notify("BPM not responding to MartDailyRefreshCompletedEvent quick enough", 
                String.format(
                    "At **%s** Mart sent out a **MartDailyRefreshCompletedEvent**.\n\n**BPM** was supposed to react to it within **30 seconds**.",
                    $when));
    end

目前,30s实际上是硬编码的。我读到,如果你想参数化规则,你需要使用在知识库中断言的其他事实,但我不知道如何为时态规则做到这一点。

那么:如何在此规则中“配置”30s,以便可以在应用程序外部更改该值?如下所示:MessageHandleStartedEvent(this after [ $duration ] ...

EN

回答 1

Stack Overflow用户

发布于 2015-02-20 00:53:06

您可以使用模板从外部Drools提供硬编码的30。

代码语言:javascript
复制
template dynamicTimer
rule "Detect BPM reseed not starting when requested from Mart"
    when
        $martDailyRefreshRequestedEvent: MessageSentEvent(
            $correlationId: correlationId,
            $when: timestamp,
            messageTypeName == "MartDailyRefreshCompletedEvent")
                from entry-point "mart"
        not ( MessageHandleStartedEvent(
                this after[0ms, @{timeout}s] $martDailyRefreshRequestedEvent, 
                correlationId == $correlationId,
                messageTypeName == "MartDailyRefreshCompletedEvent") 
                        from entry-point "bpm")
    then
        notifier.notify("BPM not responding to MartDailyRefreshCompletedEvent quick enough", 
            String.format(
                "At **%s** Mart sent out a **MartDailyRefreshCompletedEvent**.\n\n**BPM** was supposed to react to it within **@{timeout} seconds**.",
                $when));
end
end template

然后,您只需要提供30作为模板参数:

代码语言:javascript
复制
ObjectDataCompiler converter = new ObjectDataCompiler();
InputStream templateStream = getClass().getResourceAsStream(resource.getFilePath());
Collection<Map<String, String>> paramMaps = new ArrayList<>();
Map<String,String> param = new HashMap<>();
param.put("timeout", "30");
paramMaps.add(param);
String drl = converter.compile(paramMaps, templateStream);
Reader rdr = new StringReader(drl);
kbuilder.add(ResourceFactory.newReaderResource(rdr), ResourceType.DRL);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19087996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档