Class: Bio::MAF::CompletionTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/maf/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fetch_list) ⇒ CompletionTracker

Returns a new instance of CompletionTracker.



1018
1019
1020
1021
1022
1023
# File 'lib/bio/maf/parser.rb', line 1018

def initialize(fetch_list)
  @offsets = fetch_list.collect { |e| e[0] }
  @queue = java.util.concurrent.LinkedBlockingQueue.new(128)
  @delayed = {}
  @sem = Mutex.new
end

Instance Attribute Details

#delayedObject (readonly)



1016
1017
1018
# File 'lib/bio/maf/parser.rb', line 1016

def delayed
  @delayed
end

#offsetsObject (readonly)



1016
1017
1018
# File 'lib/bio/maf/parser.rb', line 1016

def offsets
  @offsets
end

#queueObject (readonly)



1016
1017
1018
# File 'lib/bio/maf/parser.rb', line 1016

def queue
  @queue
end

Instance Method Details

#<<(blocks) ⇒ Object



1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/bio/maf/parser.rb', line 1029

def <<(blocks)
  @sem.synchronize do
    f_offset = blocks.first.offset
    if f_offset == next_expected
      offsets.shift
      queue.put(blocks)
      drain_delayed
    else
      # out of order
      delayed[f_offset] = blocks
    end
  end
end

#drain_delayedObject



1043
1044
1045
1046
1047
1048
# File 'lib/bio/maf/parser.rb', line 1043

def drain_delayed
  while e = delayed.delete(next_expected)
    offsets.shift
    queue.put(e)
  end
end

#next_expectedObject



1025
1026
1027
# File 'lib/bio/maf/parser.rb', line 1025

def next_expected
  offsets.first
end