@ Override public void addNotificationsToQueue ( NamespaceEvent event , long txId , Queue < NamespaceNotification > notifications ) throws TransactionIdTooOldException { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Got addNotificationsToQueue for: " + NotifierUtils . asString ( event ) + " and txId: " + txId ) ; } historyLock . readLock ( ) . lock ( ) ; try { if ( orderedHistoryList == null || orderedHistoryList . size ( ) == 0 ) { throw new TransactionIdTooOldException ( "No data in history." ) ; } if ( orderedHistoryList . get ( 0 ) . txnId > txId || orderedHistoryList . get ( orderedHistoryList . size ( ) - 1 ) . txnId < txId ) { throw new TransactionIdTooOldException ( "No data in history for txId " + txId ) ; } int index = Collections . binarySearch ( orderedHistoryList , new HistoryTreeEntry ( 0 , txId , event . type ) , comparatorByID ) ; if ( index < 0 ) { // If we got here, there are 2 possibilities: // * The client gave us a bad transaction id. // * We missed one (or more) transaction(s) LOG . error ( "Potential corrupt history. Got request for: " + NotifierUtils . asString ( event ) + " and txId: " + txId ) ; throw new TransactionIdTooOldException ( "Potentially corrupt server history" ) ; } String dirFormatPath = event . path ; if ( ! dirFormatPath . endsWith ( Path . SEPARATOR ) ) { dirFormatPath += Path . SEPARATOR ; } for ( int i = index + 1 ; i < orderedHistoryList . size ( ) ; i ++ ) { HistoryTreeEntry entry = orderedHistoryList . get ( i ) ; if ( event . type != entry . type ) { continue ; } String entryPath = entry . getFullPath ( ) ; if ( entryPath . startsWith ( dirFormatPath ) ) { notifications . add ( new NamespaceNotification ( entryPath , entry . type , entry . txnId ) ) ; } } } finally { historyLock . readLock ( ) . unlock ( ) ; } }
Checks what notifications are saved in history for the given event and adds those notifications in the given queue . Only the notifications which happened strictly after the edit log operations with the given transaction id are put in the queue . The notifications are put in the queue in the order of their transaction id .