Class FileEventStreamSearch

java.lang.Object
edu.stanford.slac.archiverappliance.PB.search.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 Details

    • FileEventStreamSearch

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

    • getFoundPosition

      public long getFoundPosition()
    • seekToTime

      public boolean seekToTime(ArchDBRTypes dbrtype, YearSecondTimestamp yearSecondTimestamp) 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
      yearSecondTimestamp - Search seconds into year
      Returns:
      true or false
      Throws:
      IOException -  
      See Also:
    • 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