Class: Fluent::CallLater

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

Instance Method Summary collapse

Constructor Details

#initializeCallLater

Returns a new instance of CallLater.



169
170
171
172
173
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 169

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

Instance Method Details

#call_later(delay, &block) ⇒ Object



175
176
177
178
179
180
181
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 175

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

#cancelObject



208
209
210
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 208

def cancel()
  initExecBlock()
end

#runObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 183

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



212
213
214
215
216
217
218
219
220
221
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 212

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