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



867
868
869
870
871
872
# File 'lib/bio/maf/parser.rb', line 867

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)



865
866
867
# File 'lib/bio/maf/parser.rb', line 865

def delayed
  @delayed
end

#offsetsObject (readonly)



865
866
867
# File 'lib/bio/maf/parser.rb', line 865

def offsets
  @offsets
end

#queueObject (readonly)



865
866
867
# File 'lib/bio/maf/parser.rb', line 865

def queue
  @queue
end

Instance Method Details

#<<(blocks) ⇒ Object



878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/bio/maf/parser.rb', line 878

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



892
893
894
895
896
897
# File 'lib/bio/maf/parser.rb', line 892

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

#next_expectedObject



874
875
876
# File 'lib/bio/maf/parser.rb', line 874

def next_expected
  offsets.first
end