@rlkoshak: I think there are a few mistakes (or missunderstandings on my side) in your timer based example:
- lambda function
timers.put(door.name, doorTimer.apply(door, timers, createDoorTimer))
shouldn’t that be
timers.put(door.name, createDoorTimer.apply(door, timers, createDoorTimer))
-
Missing closing bracket at the end of createTimer (lambda function)
-
rule “Front Door changed”
timers.put(FrontDoor.name, timers, createDoorTimer)
shouldn’t that be
timers.put(FrontDoor.name, createDoorTimer.apply(FrontDoor, timers, createDoorTimer))
to invoke your lambda function?
- rule “System started”
if(FrontDoor.state == OPEN) timers.put(doorTimers.apply(FrontDoor, timers, doorTimer))
shouldn’t that be
if(FrontDoor.state == OPEN) timers.put(FrontDoor.name, createDoorTimer.apply(FrontDoor, timers, createDoorTimer))
I’m picking up your timer example (instead of the Expire-Binding) because I’m trying to create an recursive timer with prolonged duration (first iteration time x, second 2x, third 3x…) - but for the time being I have no luck. Does someone have an idea what the problem is / a way to debug this code?
val Functions$Function5<ContactItem, Map<String, Timer>, Number, Number, Functions$Function5, Timer> createWindowTimer = [
windowItem,
timerMap,
warningTime,
repetitions,
createWindowTimer |
val String windowName = windowItem.name.toString
val int warningTimeInt = warningTime.intValue * repetitions.intValue
return createTimer(now.plusMinutes(warningTimeInt), [ |
if (windowItem.state == CLOSED || repetitions > 3) {
// reset the timer to null
timerMap.put(windowName, null)
} else {
// notify me
// Recreate the timer if the window is still OPEN
timerMap.put(windowName, createWindowTimer.apply(windowItem, timerMap, warningTime, repetitions + 1, createWindowTimer))
}
])
]
When the function is triggered I get the following error message:
Rule XXX: cannot invoke method public abstract java.lang.Object org.eclipse.xtext.xbase.lib.Functions$Function5.apply(java.lang.Object,java.lang.Object,java.lang.Object,java.lang.Object,java.lang.Object) on null
EDIT: Ok, found my mistake: I tried to call the function above from inside of another lambda function. Seems like that doesn’t work.