jpos/jPOS — pull request #14 by wcurrie (2012-08-17 13:16:28+00:00)
Title: Add wait-for-workers-on-stop option to ChannelAdaptor.

Allows stop() to block until the Sender and Receiver threads are completely shut down.

This change might require a bit of back and forth or you might just reject it outright. No worries either way. The problem this change solves for Tyro is integration testing. We stop() and start() ChannelAdaptors like you wouldn't believe (or have dealt with in other ways) in our tests. If the adaptors don't stop cleanly our tests fail intermittently or just plain old fail. The latter is preferable. The former a nightmare.

I have tried to isolate the change behind a configuration property "wait-for-workers-on-stop" to avoid causing problems for other folks. Two things have escaped though:
1. stopService() always disconnect() on the channel regardless of channel.isConnected(). The reason for this is (intended to be) highlighted by the test case stopCanWaitForWorkersEvenWhenSenderBlockedTryingToConnect().
2. disconnect() is protected by a lock on something other than the ChannelAdaptor itself. The deadlock tests show this. I hope they are at least somewhat readable.

If you don't want this code in the jPOS codebase that's understandable but for us to maintain it means it can be something that slows us down when upgrading. For you to maintain it might slow you down but perhaps others will find "wait-for-workers-on-stop" useful.

Let me know if you need more words to explain the intent of the change or the tests. Criticism or any other feedback is welcome.

Thanks.