Rules cycling despite reentrant.lock

Linux Intel i7-4770K 3.5 GHz 8 threads

Ouch :wink:

Posting for future ref - It seems the solution here is to use a structure like

boolean gotLock = lock.tryLock();
try{
    if(gotLock){
        // Do Stuff
    } else {
        // Don't do stuff
    }
}
finally{
    if(gotLock){
        lock.unlock();
    }
}

The .tryLock method allows for acquiring and testing the lock all in one go. It will grab the lock and return TRUE, or it will fail to get the lock and return FALSE. Then you can make a decision, in Nathan’s case to abort the rule altogether, and are not forced into a queue as with the simple .lock method.

By putting a sleep in the got-lock code, you can reject subsequent triggers for a period while it has possession of the lock. An effective (if complicated) debounce method.

1 Like

Hi, have several rules and i need to prevent it from firing for 3 seconds.
My switches receive state ON in 3 sec after power on.
Do i have to use lock1, lock2, lock3 for every my switch or ReentrantLock use only one instance?

Reentrant lock may not be what you want at all here. Depends what you mean by " prevent firing" - do not perform any action, like discarding that trigger? Or to wait, queue up to perform the action?

How many locks or other tests you might depends on the wanted behaviour too.
Guessing we are dealing with some kind of output switch? OpenHAB turns the switch on, 3 seconds later some Item gets a ready response?
Are you trying to get one switch sequence “in progress” to discard or delay action on other switches? Sounds a bit like a Group job.

I add esp8266 after one way RF module, and when RF module received command ON, it powerup light and ESP.
ESP boot up time is 3-4 seconds.
Im use proxy switches for this.
When i turn on light, proxy received comman ON, some times it immediately changing to OFF because of no ping from ESP.
And i want proxy switch do not react for 3 sec after switching and wait for ping.

Share your Items definitions, please

Here it is, it very complicated - measures current lightness and set dimmer to measured value, when i set brightness from wall switch.

Dimmer	Light_Kuhn2_DIM	"Kitchen table [%.0f %%]"	<slider>	(gDimmers)	{ mqtt="<[oh2agdisk:/esp/kuhn2/lwt:state:0], <[oh2agdisk:/esp/kuhn2/sensors/light:state:SCALE(kuhn2_lux_to_dim.scale)], >[oh2wb:/devices/noolite_tx_0x109/controls/level/on:command:*:SCALE(kuhn2_dim_to_mqtt.scale)]" }
String	Light_Kuhn2_DIM_CMD	"Kitchen table"	<light>	(gLights, gKitchen, gSoftAwake_OtherLights)	{ mqtt=">[oh2wb:/devices/noolite_tx_0x109/controls/state/on:command:OFF:0], >[oh2wb:/devices/noolite_tx_0x109/controls/state/on:command:ON:1], >[oh2wb:/devices/noolite_tx_0x109/controls/switch/on:command:SWITCH:1], >[oh2wb:/devices/noolite_tx_0x109/controls/slowdown/on:command:SLOWDOWN:0], >[oh2wb:/devices/noolite_tx_0x109/controls/slowup/on:command:SLOWUP:1], >[oh2wb:/devices/noolite_tx_0x109/controls/slowswitch/on:command:SLOWSWITCH:1]  ", autoupdate="false" }
Number	ESP_Kuhn2_Uptime	"Uptime [%.0f сек]"	<clock>	{ mqtt="<[oh2agdisk:/esp/kuhn2/sensors/uptime:state:default]" }
Switch	ESP_Kuhn2_Switch	"Kitchen table"	<light>	{ channel="network:device:192_168_1_27:online", mqtt="<[oh2agdisk:/esp/kuhn2/lwt:state:OFF], <[oh2agdisk:/esp/kuhn2/sensors/uptime:state:ON]" } 
Number	ESP_Kuhn2_Lightness	"Kitchen table Lighness [%.0f Lux]" 	{ mqtt="<[oh2agdisk:/esp/kuhn2/sensors/light:state:default]" }
//Proxy Switch
Switch	Light_Kuhn2_Switch	"Kitchen table"	<light>
rule "Light_Kuhn2_Switch" 
when
	Item Light_Kuhn2_Switch received command
then
	if (!lock_kuhn2.isLocked) {
		lock_kuhn2.lock
		try {
			Light_Kuhn2_DIM_CMD.sendCommand(receivedCommand)
			Thread::sleep(3000)
		} finally {
			lock_kuhn2.unlock
			logInfo ("   ---> Lighting", Light_Kuhn2_Switch.label + " - " + receivedCommand)		
		}
	}
end


rule "ESP_Kuhn2_Switch" 
when
	Item ESP_Kuhn2_Switch changed
then
	if (!lock_kuhn2.isLocked) {
		Light_Kuhn2_Switch.postUpdate(ESP_Kuhn2_Switch.state)
		logInfo ("   ---> Lighting", Light_Kuhn2_Switch.label + " - " + ESP_Kuhn2_Switch.state)
	}
end

Something change with 2.1? I now get:

java.lang.RuntimeException: The name '<XFeatureCallImplCustom>.lastUpdate(<XStringLiteralImpl>)' cannot be resolved to an item or type.