Class: Fluent::CallLater_EX

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_tail_multiline_ex.rb

Instance Method Summary collapse

Constructor Details

#initializeCallLater_EX

Returns a new instance of CallLater_EX.



287
288
289
290
291
# File 'lib/fluent/plugin/in_tail_multiline_ex.rb', line 287

def initialize
  @locker = Monitor::new
  initExecBlock()
  @thread = Thread.new(&method(:run))
end

Instance Method Details

#call_later(delay, &block) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/fluent/plugin/in_tail_multiline_ex.rb', line 293

def call_later(delay,&block)
  @locker.synchronize do
    @exec_time = Engine.now + delay
    @exec_block = block
  end
  @thread.run
end

#cancelObject



326
327
328
# File 'lib/fluent/plugin/in_tail_multiline_ex.rb', line 326

def cancel()
  initExecBlock()
end

#runObject



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/fluent/plugin/in_tail_multiline_ex.rb', line 301

def run
  @running = true
  while true
    sleepSec = -1
    @locker.synchronize do
      now = Engine.now
      if @exec_block && @exec_time <= now
        @exec_block.call()
        initExecBlock()
      end          
      return unless @running
      unless(@exec_time == -1)
        sleepSec = @exec_time - now 
      end
    end
    if (sleepSec == -1)
      sleep()
    else
      sleep(sleepSec)
    end
  end
rescue => e
  puts e
end

#shutdownObject



330
331
332
333
334
335
336
337
338
339
# File 'lib/fluent/plugin/in_tail_multiline_ex.rb', line 330

def shutdown()
  @locker.synchronize do
    @running = false
  end
  if(@thread)
    @thread.run
    @thread.join
    @thread = nil
  end
end