dana-i2cat/opennaas — pull request #29 by gbehrmann (2012-02-29 09:28:33+00:00)
Title: Feature/make wonesys command listener thread safe

The Wonesys protocol implementation uses a transport abstraction
for communicating with the device or with a mock transport. In
either case a CommandResponseListener is registerd as an OSGi
service for receiving the reply as an event from the transport.

The CommandResponseListener is however not thread safe: If
the reply is generated before WonesysProtocolSession calls
wait, wait will block until timing out. Java's notify/wait
mechanism doesn't "remember" a notify call.

This patch resolves the issue by using a CountDownLatch to
signal the response. The patch also removes some of the cruft
from the implementation, simplifying both CommandResponseListener
and the class using it.

Finally, the patch ensures that the CommandResponseListener is
unregistered after use. Otherwise instances will accumulate for
every command sent to the device.

Testing done: Unit and integration tests pass. I did not run
against a physical device.