ReentrantLock - Errors

I only edited typo, no changes on code or something like that.

Well, there’s only three places involving .name You can isolate them with logInfo(“blah”,“here”) or something to figure out the offender, I can’t see it.

addition

 import org.eclipse.smarthome.core.library.items.*

not required for OH 1.8. you want
import org.openhab.core.library.items.*

might just be it?

I believe this is the error. I do some more tests, but the first try was very promising…

Edit:

[enhab.model.script.rule.lambda] - buhahuha
[.script.rule.error.lambda.test] - We are here A
[.script.rule.error.lambda.test] - We are here B
[.script.rule.error.lambda.test] - We are here C
[.script.rule.error.lambda.test] - We are here D
[.script.rule.error.lambda.test] - We are here E
[.script.rule.error.lambda.test] - We are here F
[enhab.model.script.rule.lambda] - Begin Try
[.script.rule.error.lambda.test] - We are here G
[.script.rule.error.lambda.test] - We are here H
[.script.rule.error.lambda.test] - We are here J
[enhab.model.script.rule.lambda] - finally in lambda:
[.script.rule.error.lambda.test] - We are here M

Fullcode

import org.openhab.core.library.types.*
import org.openhab.core.types.*
import org.eclipse.xtext.xbase.lib.*
// import org.eclipse.smarthome.core.library.items.*
import org.openhab.core.library.items.*
import java.util.Locale
import java.util.concurrent.locks.ReentrantLock


var java.util.concurrent.locks.ReentrantLock lock_rollo_lambda  = new java.util.concurrent.locks.ReentrantLock()



val Functions$Function4 rollo_lambda = 
[
    RollershutterItem rsiRollershutterItem,
    org.openhab.core.types.Command receivedCommand,
    SwitchItem rsiStatusItem,
    java.util.concurrent.locks.ReentrantLock lockThatLambda
|
	//lockThatLambda.lock
logError("rule.error.lambda.test", "We are here A")


	// ardu02_out_20_13_P_06_07
	val int		_threadSleepTime	= 250
	var int		_whileExitCounter	= 0
	val int		_whileExitCountMax	= 20

	val _NameArray				= rsiRollershutterItem.name.split("_")
	
logError("rule.error.lambda.test", "We are here B")

	val String	_rsiNodeName	= _NameArray.get(0)
	val String	_rsiDirecion	= _NameArray.get(1)
	val int		_rsiExpAddress	= Integer::parseInt(_NameArray.get(2))
	val int		_rsiExpBank		= Integer::parseInt(_NameArray.get(3))
	val String	_rsiPinIdent	= _NameArray.get(4) // ignore it
	val int		_rsiRelPower	= Integer::parseInt(_NameArray.get(5))
	val int		_rsiRelDirec	= Integer::parseInt(_NameArray.get(6))

	val String _strRelaisPower_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelPower)
	val String _strRelaisPower_Off	= String::format("pinout:%1$d:%2$d:%3$d:0", _rsiExpAddress, _rsiExpBank, _rsiRelPower)

	val String _strRelaisDirec_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelDirec)
	val String _strRelaisDirec_Off	= String::format("pinout:%1$d:%2$d:%3$d:0", _rsiExpAddress, _rsiExpBank, _rsiRelDirec)

logError("rule.error.lambda.test", "We are here C")

	logInfo("rule.info", rsiRollershutterItem.name)

logError("rule.error.lambda.test", "We are here D")

	logInfo("rule.info", rsiStatusItem.name)

logError("rule.error.lambda.test", "We are here E")

	logInfo("rule.info", _strRelaisPower_On)
	logInfo("rule.info", _strRelaisPower_Off)
	logInfo("rule.info", _strRelaisDirec_On)
	logInfo("rule.info", _strRelaisDirec_Off)

logError("rule.error.lambda.test", "We are here F")
	
	try
	{
		logError("rule.lambda", "Begin Try")

		publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)

		while (rsiStatusItem.state == "1" && receivedCommand != STOP && _whileExitCounter < _whileExitCountMax)
		{
			logInfo("rule.info", "Warteschleife")
			Thread::sleep(500)
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)
			_whileExitCounter++
		}
		
logError("rule.error.lambda.test", "We are here G")
		
		if (rsiStatusItem.state == "0" && receivedCommand != STOP)
		{
			if (receivedCommand == UP)				//  UP
			{
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_On)
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_On)			
		
logError("rule.error.lambda.test", "We are here H")
		
			}
			else if (receivedCommand == DOWN)		//  DOWN
			{
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_Off)
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_On)			
		
logError("rule.error.lambda.test", "We are here I")
		
			}

logError("rule.error.lambda.test", "We are here J")

		}
		else										// STOP
		{
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)
			Thread::sleep(_threadSleepTime)
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_Off)			

logError("rule.error.lambda.test", "We are here K")

		} 
	}
	catch(Throwable t)
	{
		logError("rule.lambda", "catch error in lambda: " + t.localizedMessage.toString())
		//lockThatLambda.unlock

logError("rule.error.lambda.test", "We are here L")

	}
	finally 
	{
		logError("rule.lambda", "finally in lambda: ")
		//lockThatLambda.unlock

logError("rule.error.lambda.test", "We are here M")

	}

	true
]

OMG, I went crazy …

First run, looks nice. It goes trough til finally.

[.script.rule.error.lambda.test] - We are here 0
[.script.rule.error.lambda.test] - We are here A
[.script.rule.error.lambda.test] - We are here B
[.script.rule.error.lambda.test] - We are here C
[.script.rule.error.lambda.test] - ardu02_out_20_12_P_00_01
[.script.rule.error.lambda.test] - We are here D
[.script.rule.error.lambda.test] - ardu02_out_20_12_00_stat
[.script.rule.error.lambda.test] - We are here E
[.script.rule.error.lambda.test] - pinout:20:12:0:1
[.script.rule.error.lambda.test] - pinout:20:12:0:0
[.script.rule.error.lambda.test] - pinout:20:12:1:1
[.script.rule.error.lambda.test] - pinout:20:12:1:0
[.script.rule.error.lambda.test] - We are here F
[enhab.model.script.rule.lambda] - Begin Try
[.script.rule.error.lambda.test] - We are here G
[.script.rule.error.lambda.test] - We are here H
[.script.rule.error.lambda.test] - We are here J
[enhab.model.script.rule.lambda] - finally in lambda:
[.script.rule.error.lambda.test] - We are here M

But than, 2nd-run, same button, same command:

[.script.rule.error.lambda.test] - We are here 0
[.script.rule.error.lambda.test] - We are here A
[.script.rule.error.lambda.test] - We are here B
[.script.rule.error.lambda.test] - We are here C
[.script.rule.error.lambda.test] - ardu02_out_20_12_P_00_01
[.script.rule.error.lambda.test] - We are here D
[.script.rule.error.lambda.test] - ardu02_out_20_12_00_stat
[.script.rule.error.lambda.test] - We are here E
[.script.rule.error.lambda.test] - pinout:20:12:0:1
[.script.rule.error.lambda.test] - pinout:20:12:0:0
[.script.rule.error.lambda.test] - pinout:20:12:1:1
[.script.rule.error.lambda.test] - pinout:20:12:1:0
[.script.rule.error.lambda.test] - We are here F
[enhab.model.script.rule.lambda] - Begin Try
[.script.rule.error.lambda.test] - We are here WS A
[.script.rule.error.lambda.test] - Warteschleife
[.script.rule.error.lambda.test] - We are here WS B
[.script.rule.error.lambda.test] - We are here WS C
[.script.rule.error.lambda.test] - We are here WS D
[.script.rule.error.lambda.test] - We are here WS E
[o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'rule_ardu02_out_20_12_P_00_01_received_command': The name '+ <XFeatureCallImplCustom>' cannot be resolved to an item or type.

That’s the “Warteschleife”

    	publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)

		while (rsiStatusItem.state == "1" && receivedCommand != STOP && _whileExitCounter < _whileExitCountMax)
		{

logError("rule.error.lambda.test", "We are here WS A")
	
			logError("rule.error.lambda.test", "Warteschleife")

logError("rule.error.lambda.test", "We are here WS B")
	
			Thread::sleep(500)

logError("rule.error.lambda.test", "We are here WS C")
	
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)

logError("rule.error.lambda.test", "We are here WS D")
	
			_whileExitCounter++

logError("rule.error.lambda.test", "We are here WS E")
	
		}

It come to WS E, but than it stops, without any more messages.
if there is an error, i believe that it has to jump to catch … but it didn’t.

It won’t jump to catch before you get to try. The log appears to show two runs of the lambda, one has got as far as “BEGIN TRY” and then another one starts and presumably hits an error (before it gets to try)

Isn’t that where we came in, needs a reentrant lock?
Addition - As this error was outside your current try-catch block, you will need to move that to include all the code

ok, i didn’t post the full code, but the while is in try!

I didn’t even see the “WS” text in the log, I thought I saw two “here A” and so on.

How do you know it doesn’t jump to catch? The only logInfo that might tell you that has a complex string in it.with concatenation (+). (If the code is still the same in that area)

The logged error message you do see has a “+” in it. This new WS code block doesn’t seem to have any + in it.

It’s all very difficult to follow, a moving target.

I’ll give up …

I get often (mostly when i switch to fast). The Lock istn’t working resp. it freeze locks …

[o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘rule_ardu02_out_21_12_P_02_03_received_command’: The name '+ ’ cannot be resolved to an item or type.

import org.openhab.core.library.types.*
import org.openhab.core.types.*
import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.library.items.*
import java.util.Locale
import java.util.concurrent.locks.ReentrantLock


var java.util.concurrent.locks.ReentrantLock lock_rollo_lambda  = new java.util.concurrent.locks.ReentrantLock()



val Functions$Function4 rollo_lambda = 
[
    RollershutterItem rsiRollershutterItem,
    org.openhab.core.types.Command receivedCommand,
    SwitchItem rsiStatusItem,
    java.util.concurrent.locks.ReentrantLock lockThatLambda
|
	try
	{
		//lockThatLambda.lock
	
	    // ardu02_out_20_13_P_06_07
		val int		_threadSleepTime	= 250
		var int		_whileExitCounter	= 0
		val int		_whileExitCountMax	= 20
		
		val _NameArray				= rsiRollershutterItem.name.split("_")
	    val String	_rsiNodeName	= _NameArray.get(0)
		val String	_rsiDirecion	= _NameArray.get(1)
		val int		_rsiExpAddress	= Integer::parseInt(_NameArray.get(2))
		val int		_rsiExpBank		= Integer::parseInt(_NameArray.get(3))
		val String	_rsiPinIdent	= _NameArray.get(4) // ignore it
		val int		_rsiRelPower	= Integer::parseInt(_NameArray.get(5))
		val int		_rsiRelDirec	= Integer::parseInt(_NameArray.get(6))
		
		val String _strRelaisPower_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelPower)
		val String _strRelaisPower_Off	= String::format("pinout:%1$d:%2$d:%3$d:0", _rsiExpAddress, _rsiExpBank, _rsiRelPower)
		
		val String _strRelaisDirec_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelDirec)
		val String _strRelaisDirec_Off	= String::format("pinout:%1$d:%2$d:%3$d:0", _rsiExpAddress, _rsiExpBank, _rsiRelDirec)
		
		val String lastRelPowerState	= rsiStatusItem.state.toString
	
		/*
		logError("rule.error.lambda.test", rsiRollershutterItem.name)
		logError("rule.error.lambda.test", rsiStatusItem.name)
		logError("rule.error.lambda.test", _strRelaisPower_On)
		logError("rule.error.lambda.test", _strRelaisPower_Off)
		logError("rule.error.lambda.test", _strRelaisDirec_On)
		logError("rule.error.lambda.test", _strRelaisDirec_Off)
		*/

		//logError("rule.rollo_lambda", "Begin Try")

    	publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)

		while (rsiStatusItem.state == "1" && receivedCommand != STOP && _whileExitCounter < _whileExitCountMax)
		{
			logError("rule.error.lambda.test", "Warteschleife")
			Thread::sleep(500)
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)
			_whileExitCounter++
		}

		if (rsiStatusItem.state == "0" && receivedCommand != STOP)
		{
			if (receivedCommand == UP)				//  UP
			{
				if (lastRelPowerState == "1")
				{
					Thread::sleep(_threadSleepTime)
				}
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_On)
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_On)			
			}
			else if (receivedCommand == DOWN)		//  DOWN
			{
				if (lastRelPowerState == "1")
				{
					Thread::sleep(_threadSleepTime)
				}
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_Off)
				Thread::sleep(_threadSleepTime)
				publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_On)			
			}
    	}
		else										// STOP
		{
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisPower_Off)
			Thread::sleep(_threadSleepTime)
			publish("mosquitto_cubie", "BB55/hctl/v1/ardu02/sub/i2c", _strRelaisDirec_Off)
    	} 
	}
	catch(Throwable t)
	{
		logError("rule.rollo_lambda", "catch error in lambda: " + t.localizedMessage.toString())
		//lockThatLambda.unlock
    }
	finally 
	{
		logError("rule.rollo_lambda", "finally in lambda: ")
		//lockThatLambda.unlock
    }
	
	true
]



// 0x20 - 0x12

rule "rule_ardu02_out_20_12_P_00_01_received_command"
when
    Item ardu02_out_20_12_P_00_01 received command
then
	rollo_lambda.apply(ardu02_out_20_12_P_00_01, receivedCommand, ardu02_out_20_12_00_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_12_P_02_03_received_command"
when
    Item ardu02_out_20_12_P_02_03 received command
then
	rollo_lambda.apply(ardu02_out_20_12_P_02_03, receivedCommand, ardu02_out_20_12_02_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_12_P_04_05_received_command"
when
    Item ardu02_out_20_12_P_04_05 received command
then
	rollo_lambda.apply(ardu02_out_20_12_P_04_05, receivedCommand, ardu02_out_20_12_04_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_12_P_06_07_received_command"
when
    Item ardu02_out_20_12_P_06_07 received command
then
	rollo_lambda.apply(ardu02_out_20_12_P_06_07, receivedCommand, ardu02_out_20_12_06_stat, lock_rollo_lambda)
end

// 0x20 - 0x13

rule "rule_ardu02_out_20_13_P_00_01_received_command"
when
    Item ardu02_out_20_13_P_00_01 received command
then
	rollo_lambda.apply(ardu02_out_20_13_P_00_01, receivedCommand, ardu02_out_20_13_00_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_13_P_02_03_received_command"
when
    Item ardu02_out_20_13_P_02_03 received command
then
	rollo_lambda.apply(ardu02_out_20_13_P_02_03, receivedCommand, ardu02_out_20_13_02_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_13_P_04_05_received_command"
when
    Item ardu02_out_20_13_P_04_05 received command
then
	rollo_lambda.apply(ardu02_out_20_13_P_04_05, receivedCommand, ardu02_out_20_13_04_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_20_13_P_06_07_received_command"
when
    Item ardu02_out_20_13_P_06_07 received command
then
	rollo_lambda.apply(ardu02_out_20_13_P_06_07, receivedCommand, ardu02_out_20_13_06_stat, lock_rollo_lambda)
end

// 0x21 - 0x12

rule "rule_ardu02_out_21_12_P_00_01_received_command"
when
    Item ardu02_out_21_12_P_00_01 received command
then
	rollo_lambda.apply(ardu02_out_21_12_P_00_01, receivedCommand, ardu02_out_21_12_00_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_12_P_02_03_received_command"
when
    Item ardu02_out_21_12_P_02_03 received command
then
	rollo_lambda.apply(ardu02_out_21_12_P_02_03, receivedCommand, ardu02_out_21_12_02_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_12_P_04_05_received_command"
when
    Item ardu02_out_21_12_P_04_05 received command
then
	rollo_lambda.apply(ardu02_out_21_12_P_04_05, receivedCommand, ardu02_out_21_12_04_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_12_P_06_07_received_command"
when
    Item ardu02_out_21_12_P_06_07 received command
then
	rollo_lambda.apply(ardu02_out_21_12_P_06_07, receivedCommand, ardu02_out_21_12_06_stat, lock_rollo_lambda)
end

// 0x21 - 0x13

rule "rule_ardu02_out_21_13_P_00_01_received_command"
when
    Item ardu02_out_21_13_P_00_01 received command
then
	rollo_lambda.apply(ardu02_out_21_13_P_00_01, receivedCommand, ardu02_out_21_13_00_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_13_P_02_03_received_command"
when
    Item ardu02_out_21_13_P_02_03 received command
then
	rollo_lambda.apply(ardu02_out_21_13_P_02_03, receivedCommand, ardu02_out_21_13_02_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_13_P_04_05_received_command"
when
    Item ardu02_out_21_13_P_04_05 received command
then
	rollo_lambda.apply(ardu02_out_21_13_P_04_05, receivedCommand, ardu02_out_21_13_04_stat, lock_rollo_lambda)
end

rule "rule_ardu02_out_21_13_P_06_07_received_command"
when
    Item ardu02_out_21_13_P_06_07 received command
then
	rollo_lambda.apply(ardu02_out_21_13_P_06_07, receivedCommand, ardu02_out_21_13_06_stat, lock_rollo_lambda)
end

the next most annoying thing are the slowed down rules on change of any rule file on first use.
it tooks a lot of time to click on all buttons and wait for execution.

I don’t know what switching to fast means.

Out of interest, does this trigger -

catch(Throwable t)
	{
		logInfo("rule.rollo_lambda", "catch error in lambda ")
		logError("rule.rollo_lambda", "catch error in lambda: " + t.localizedMessage.toString())
		//lockThatLambda.unlock
    }

this are the rollershutteritems on sitemap, if i actuate them fast(er) one after the other then this error message appears.
if i wait until the rule is finished and then wait for 1,2,3 seconds and actuate the next one, than this message doesn’t appears.

This happens with or without the lock, but with lock, the rule/lambda is freezed. so i have to re-save the file that OH reloads it. than the lock is gone.
I figured out - i think so - that the counter respect. the condition for the counter-exit in while could may be make some trouble. I commented it out, now the while is “used” til the state of the field changed to what i expected.
But sometimes, the main-break condition “state==1” will not ‘fired’ although i see in logs or on screen that the state is 0.
the error message is not effected, it comes up nevertheless on mentioned above “fast-actuating”-conditions.
the catch-clause will not be reached. i didn’t see any log-entry. (yes, also with yours).

Now I restarted everything … i didn’t changed anything to the code above ecept the additional logentry in catch as @rossko57 wrote !

[INFO ] [runtime.busevents ] - ardu02_out_20_12_P_00_01 received command UP
[INFO ] [runtime.busevents ] - ardu02_out_20_12_00_stat state updated to 0
[ERROR] [.script.rule.error.lambda.test] - Warteschleife
[INFO ] [runtime.busevents ] - ardu02_out_20_12_00_stat state updated to 0
[ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘rule_ardu02_out_20_12_P_00_01_received_command’: The name '+ ’ cannot be resolved to an item or type.

I only pressed one - and for the first time - rollershutteritem to go UP …

Humour me, replace

  _whileExitCounter++```

with
_whileExitCounter = _whileExitCounter + 1

I’ve read that Xtend does not support ++

i’ll try, but did not try catch this error?