Class FileEventStreamSearch


  • public class FileEventStreamSearch
    extends Object
    This is a variant of binary search that searches for an event in a event stream file. We assume a time-sorted PB file separated by unix newlines as outlined in the archiver appliance design doc. We pass in file channel and a function that compares an event line (most likely a PB) to the desired time t1. The fileChannels position is moved to a spot where this constraint is satisfied s1 ≤ t1 < s2 That is
    1. Search the file for a time t1
    2. Do a LineByteStream.seekToFirstNewLine
    3. LineByteStream.readLine's after this should give events that satisfy getData's requirements.
    4. Remember to terminate appropriately
    Author:
    mshankar
    • Constructor Detail

      • FileEventStreamSearch

        public FileEventStreamSearch​(Path path,
                                     long startPosn)
        Parameters:
        path - Path
        startPosn - a starting position of search PB files
    • Method Detail

      • getFoundPosition

        public long getFoundPosition()
      • seekToTime

        public boolean seekToTime​(ArchDBRTypes dbrtype,
                                  int secondsIntoYear)
                           throws IOException
        Set the fileChannels position to a point that best satisfies the requirements for getData(t1,...). If found (return value is true), the file's position is set such that LineByteStream lis = new LineByteStream(fchannel); lis.seekToFirstNewLine(); byte[] line = lis.readLine(); starts returning events that satisfy getData's requirements
        Parameters:
        dbrtype - ArchDBRType the enumeration type
        secondsIntoYear - Search seconds into year
        Returns:
        true or false
        Throws:
        IOException -  
        See Also:
        ComparePBEvent
      • seekToTime

        public boolean seekToTime​(CompareEventLine comparefunction)
                           throws IOException
        This should only be used by the unit tests.
        Parameters:
        comparefunction - CompareEventLine
        Returns:
        true or false
        Throws:
        IOException - when parsing the absolute path