public final AbstractItem removeFirstMatching ( final Filter filter , PersistentTransaction transaction ) throws MessageStoreException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( this , tc , "removeFirstMatching" , new Object [ ] { filter , transaction } ) ; AbstractItem found = null ; Link link = getHead ( ) ; while ( link != null && found == null ) { found = ( ( AbstractItemLink ) link ) . removeIfMatches ( filter , transaction ) ; if ( found == null ) { // Defect 493652/PK59872 // We need to lock on the list at this point as our current link // may have been unlinked by another thread during the matches() // call. In that case we need to start at the head of the list again // as the next/previous pointers for the unlinked link will not be // set. synchronized ( this ) { if ( link . isPhysicallyUnlinked ( ) ) { // We have been unlinked while we were doing the match. // Start again at the beginning of the list. link = getHead ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "Current link is PhysicallyUnlinked so returning to beginning of list." ) ; } else { link = link . getNextLogicalLink ( ) ; } } } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( this , tc , "removeFirstMatching" , found ) ; return found ; }
Method removes the first unlocked matching object on the list destructively under transactional control .