BUG-509: Fix thread safety of listener registration

This commit fixes the race condition where a listener is registered
after preCommit() and before commit(). This is done by moving the
collection into the commit() where it is protected by the
commit/listener synchronized block.

The unregistration safety is handled by wrapping the returned
registration and invoking the equivalent synchronized block.

Change-Id: Ie9abc81b2a773418b34c3051f7665b0dcf047f76
Signed-off-by: Robert Varga <rovarga@cisco.com>