tlaukkan / zigbee4java

Zigbee API for Java provides simple Java interface to ZigBee network.
Apache License 2.0
144 stars 68 forks source link

Invoking commands from ClusterListener thread causes timeout #32

Closed smulikHakipod closed 8 years ago

smulikHakipod commented 9 years ago

Hey, I noticed something strange, if I listen for cluster messages, process them and invoking command in response I get timeout issues. If I invoke the response on the main thread instead of the ClusterListener thread its working fine. Debugging the issue I saw that zigbee4java got the response.. its just some threading issue. Am I missing something? Anyone have an Idea how to fix the issue?

cdjackson commented 9 years ago

Interesting - do you think this might be related to #31?

I'm seeing a number of strange issues, so it might be all related.

smulikHakipod commented 9 years ago

Further investigation shows that every thread other than ZToolPacketParser thread (the cluster listener thread) is working fine.

tlaukkan commented 9 years ago

Hi

I suspect that invoking any ZigBee stack request response messaging from ZToolPacketParser thread will cause deadlock as your ZToolPacketParser thread will be waiting for response instead of parsing the response packet. We could add check for this somewhere in the ZigBeeApi and throw exception with appropriate error message. Another alternative would be to have another thread for invoking cluster listeners. What do you think?

Best regards, Tommi

smulikHakipod commented 9 years ago

I put the notifyClusterListener function in a new thread and everything is working fine. https://github.com/smulikHakipod/zigbee4java/commit/45336411bb7e24d34ddeb26b862ceb23e3d10d4c