public void addListener ( AgentRosterListener listener ) { synchronized ( listeners ) { if ( ! listeners . contains ( listener ) ) { listeners . add ( listener ) ; // Fire events for the existing entries and presences in the roster for ( EntityBareJid jid : getAgents ( ) ) { // Check again in case the agent is no longer in the roster (highly unlikely // but possible) if ( entries . contains ( jid ) ) { // Fire the agent added event listener . agentAdded ( jid ) ; Jid j ; try { j = JidCreate . from ( jid ) ; } catch ( XmppStringprepException e ) { throw new IllegalStateException ( e ) ; } Map < Resourcepart , Presence > userPresences = presenceMap . get ( j ) ; if ( userPresences != null ) { Iterator < Presence > presences = userPresences . values ( ) . iterator ( ) ; while ( presences . hasNext ( ) ) { // Fire the presence changed event listener . presenceChanged ( presences . next ( ) ) ; } } } } } } }
Adds a listener to this roster . The listener will be fired anytime one or more changes to the roster are pushed from the server .