@ SuppressWarnings ( "unchecked" ) public < T extends ObjectAttachableListener > ListenerManager < T > addObjectListener ( Class < ? > objectClass , long objectId , Class < T > listenerClass , T listener ) { Map < ObjectAttachableListener , ListenerManagerImpl < ? extends ObjectAttachableListener > > listeners = objectListeners . computeIfAbsent ( objectClass , key -> new ConcurrentHashMap <> ( ) ) . computeIfAbsent ( objectId , key -> new ConcurrentHashMap <> ( ) ) . computeIfAbsent ( listenerClass , c -> Collections . synchronizedMap ( new LinkedHashMap <> ( ) ) ) ; return ( ListenerManager < T > ) listeners . computeIfAbsent ( listener , key -> new ListenerManagerImpl <> ( this , listener , listenerClass , objectClass , objectId ) ) ; }
Adds an object listener . Adding a listener multiple times to the same object will only add it once and return the same listener manager on each invocation . The order of invocation is according to first addition .