Design Pattern: Gate Keeper

Thank you BK.

You are on the Milestone 6.
This is older than the 3.4.0 Release.

If you are on the release, the build string would say something like Release Build.

1 Like

In addition to what was suggested, you donā€™t have the JS Scripting add-on installed.

openhab_rules_tools does not work in Nashorn. In fact, require doesnā€™t exist as a special word in Nashorn.

But I have to say Iā€™ve never seen an error anything like that so if it persists after upgrading to the 3.4 release and installed the JS Scripting add-on and verifying that openhab_rules_tools is also installed come back and we can explore.

Hi Rich,
Sorry, it is my mistake, I forget to reply to this issue.

it was the solution to the problem below.

No problem at the moment.


I am currently facing some issues, but I would like to at least try to solve them myself first.
If I canā€™t do/solve those, I will inform to group.

Sorry again and thank you.

1 Like

Hello! Just a quick question, because I canā€™t get this to work in OH4: does it still work the same way?

In my .rules file I am defining a queue and a timer, but it seems they canā€™t be accessed in a single rule in the very same file. The log tells me: The field Tmp_gctl-controllerRules.queue refers to the missing type Object.

Additionally, in the WebUI, the rule can be viewed (obviously not edited, because I created it using a textual config file). There, the declaration of the queue and the timer is gone. What am I doing wrong?

What I want to achieve: I want to queue up commands (which the controller receives from other rules) and execute them one-by-one, only starting the next one when the previous finished.

The rule file in question:

import java.util.concurrent.ConcurrentLinkedQueue

val Queue<String> queue = new ConcurrentLinkedQueue()
var Timer timer = null

rule VolTargetController
when
    Item gctl_voltarget_controller received command
then
    queue.add(receivedCommand.toString)

    if(timer === null) {
        timer = createTimer(now, [ |
            if(queue.peek !== null) {
                if (gctl_voltarget_stat.state == CLOSED) {  // condition is met if the previous command finished             
                    val command = queue.poll

                    // just logging for degubbing purposes, instead executing the command
                    logInfo("VolTargetController","next cmd: " + command)
                }                 
                timer.reschedule(now.plusMillis(1000))
            }            
        ])
    }
end

I donā€™t know. I dropped Rules DSL years ago and have not kept all these old Rules DSL examples up to date. I probably should work the same but :person_shrugging: .

I know there have been changes in how Rules DSL rules are executed since OH 3 which could be a problem. Each rule gets itā€™s own thread but all the timers created in that rule also share a thread. So it might be possible that there might be a collision between the timer and the rule. I donā€™t know what would happen in that case.

You have to import Queue too.

For the latest maintained implementation of this see openHAB Rules Tools Announcements which provides a library implementation of most of the design patterns.