// If cache behavior is observation register a hierarchy listener which is
// notified about all changes. Otherwise just add a hierarchy listener which
// is only notified on changes for which client event listeners have been
// installed. Note: this listener has to be the first one called in order
// for the hierarchy to be consistent with the event (See JCR-2293).
InternalEventListener listener = createHierarchyListener(hierarchyManager);
if (cacheBehaviour == CacheBehaviour.OBSERVATION) {
addEventListener(listener);
} else {
listeners.add(listener);
}