BUG-509: Encapsulate ListenerTree

This patch encapsulates the ListenerTree. This provides the
infrastructure needed to make listener registration/unregistration scale
and work in face of asynchronous commits.

Whenever a listener is about to be registered, the tree is write-locked,
the apropriate structure is created and the registration is enqueued.
When a registration is closed, the removeListener() callback re-takes
the appropriate lock and removes the listener.

When the last listener is removed from a node, and that node is unused,
it is cascaded up to its parent for removal, which recursively does the
same. This means that the tree is of unused nodes as soon as they are
freed. The backreference to parent is kept weak, which makes sure we are
able to finalize as much as we can in case of funky references lying
around.

Write locks are never leaked outside of the ListenerTree class, e.g.
they are always released before we return to the caller.

When a transaction is being committed, the ListenerTree is asked for a
Walker, which is an AutoCloseable resource. A Walker is the only way how
foreign code can get hold of a listener tree root node. Each walker is
backed by a reference to a read-lock, e.g. listener
registration/unregistration cannot occur while such a lock is held. This
makes sure the commit process sees a point-in-time view of the listener
tree. When a Walker is closed, the tree lock is read-unlocked. The
close() method is idempotent.

Change-Id: I6ea9b2e00f8ab21a5d8bd3b8c82c193c2069d683
Signed-off-by: Robert Varga <rovarga@cisco.com>
Merge "BUG-509: Encapsulate ListenerTree"