spring-projects/spring-xd — pull request #762 by pperalta (2014-04-17 16:51:52+00:00)
Title: XD-1580: Undeploy modules when ZK disconnects

In method `registerWithZooKeeper`, the module deployments cache is started before saving the container attributes. This way if there is an exception thrown while saving the attributes, the deployments cache is not affected.

At some point we may want to consider trapping exceptions from this method, or perhaps even shutting down the ZK connection if an exception occurs. I was seeing a `NodeExists` exception for the ephemeral node created by this method, but that exception seems to have gone away with the other changes in this commit.

In method `onDisconnect` the modules are now undeployed when the connection to ZK is lost. This is desirable because the admin leader will try to redeploy those modules on another container.

In `StreamModuleWatcher` and `JobModuleWatcher`, instead of blindly setting the watch on every non-delete event, the watch is only set if the connection to ZK is established. This change seems to prevent the exception described above in `registerWithZooKeeper` although I don't understand how they are related.