The problem is that the connection may have already been established by the time the registrar's context is refreshed. That does happen, in fact, when the ZooKeeperConnection is defined in the parent context. So, that means we risk "missing" the connection event the first time. Nevertheless we do still need to add the listener to support reconnect events (or for the case where the ZK connection is defined in the same context and would not necessarily be connected yet, so that the normal connected event would trigger registration).

The registration cannot happen more eagerly either... We need the context, because its ID is used as the container ID (the name of the ephemeral node).

SIDE NOTE: personally, I think the publishing of events could disappear in a subsequent commit. With that data now in ZK itself, there's no real need. Anyone could add a watch on the child nodes of /xd/containers, and so far the only use of the events has been to record state in Redis; that last bit will definitely go away.