Class: Bio::MAF::JExecutor

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

Instance Method Summary collapse

Constructor Details

#initializeJExecutor

Returns a new instance of JExecutor.



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bio/maf/jobs.rb', line 119

def initialize
  queue = java.util.concurrent.LinkedBlockingQueue.new(8)
  policy = java.util.concurrent.ThreadPoolExecutor::CallerRunsPolicy.new
  @exec = java.util.concurrent.ThreadPoolExecutor.new(1, 1, 1,
                                                      java.util.concurrent.TimeUnit::MINUTES,
                                                      queue,
                                                      policy)
  @ecs = java.util.concurrent.ExecutorCompletionService.new(@exec)
  @submitted = 0
  @completed = 0
end

Instance Method Details

#check_for_errorsObject



137
138
139
140
141
142
# File 'lib/bio/maf/jobs.rb', line 137

def check_for_errors
  while f = @ecs.poll
    f.get
    @completed += 1
  end
end

#shutdownObject



144
145
146
147
148
149
150
151
# File 'lib/bio/maf/jobs.rb', line 144

def shutdown
  @exec.shutdown
  until @completed == @submitted
    f = @ecs.take
    f.get
    @completed += 1
  end
end

#submit(&blk) ⇒ Object



131
132
133
134
135
# File 'lib/bio/maf/jobs.rb', line 131

def submit(&blk)
  @ecs.submit(&blk)
  @submitted += 1
  check_for_errors
end