Class: CWlogsIO::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/cwlogs_io/handler.rb

Direct Known Subclasses

LogEventHandler

Constant Summary collapse

DEFAULT_POLLING_PERIOD_IN_SECONDS =
1
TERMINATION_TIMEOUT_IN_SECONDS =
5

Instance Method Summary collapse

Constructor Details

#initialize(logger, polling_period = nil) ⇒ Handler

Returns a new instance of Handler.



57
58
59
60
61
62
63
# File 'lib/cwlogs_io/handler.rb', line 57

def initialize(logger, polling_period = nil)
  @queue = Queue.new
  @logger = logger
  @polling_period = polling_period || DEFAULT_POLLING_PERIOD_IN_SECONDS

  initialize_executor
end

Instance Method Details

#<<(event) ⇒ Object



71
72
73
# File 'lib/cwlogs_io/handler.rb', line 71

def <<(event)
  enq(event)
end

#closeObject



75
76
77
78
79
80
81
# File 'lib/cwlogs_io/handler.rb', line 75

def close
  return if closed?

  @queue.close

  shutdown_executor
end

#closed?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/cwlogs_io/handler.rb', line 83

def closed?
  @queue.closed?
end

#enq(event) ⇒ Object



65
66
67
68
69
# File 'lib/cwlogs_io/handler.rb', line 65

def enq(event)
  return if closed?

  @queue << event
end

#respawnObject

should be called in child process, not parent. or, you may lose some events.



89
90
91
92
93
94
# File 'lib/cwlogs_io/handler.rb', line 89

def respawn
  return if closed?

  @queue.clear
  initialize_executor
end