Module: Fluent::PluginHelper::EventEmitter

Defined in:
lib/fluent/plugin_helper/event_emitter.rb

Instance Method Summary collapse

Instance Method Details

#after_shutdownObject



96
97
98
99
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 96

def after_shutdown
  @router = nil
  super
end

#closeObject

unset router many times to reduce test cost



101
102
103
104
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 101

def close # unset router many times to reduce test cost
  @router = nil
  super
end

#configure(conf) ⇒ Object



90
91
92
93
94
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 90

def configure(conf)
  require 'fluent/engine'
  super
  @router = event_emitter_router(conf['@label'])
end

#event_emitter_apply_source_onlyObject



54
55
56
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 54

def event_emitter_apply_source_only
  @_event_emitter_force_source_only_router = true
end

#event_emitter_cancel_source_onlyObject



58
59
60
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 58

def event_emitter_cancel_source_only
  @_event_emitter_force_source_only_router = false
end

#event_emitter_router(label_name) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 62

def event_emitter_router(label_name)
  if label_name
    if label_name == "@ROOT"
      Engine.root_agent.event_router
    else
      Engine.root_agent.find_label(label_name).event_router
    end
  elsif self.respond_to?(:as_secondary) && self.as_secondary
    if @primary_instance.has_router?
      @_event_emitter_lazy_init = true
      nil # primary plugin's event router is not initialized yet, here.
    else
      @primary_instance.context_router
    end
  else
    # `Engine.root_agent.event_router` is for testing
    self.context_router || Engine.root_agent.event_router
  end
end

#event_emitter_used_actually?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 50

def event_emitter_used_actually?
  @_event_emitter_used_actually
end

#has_router?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 46

def has_router?
  true
end

#initializeObject



82
83
84
85
86
87
88
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 82

def initialize
  super
  @_event_emitter_used_actually = false
  @_event_emitter_lazy_init = false
  @_event_emitter_force_source_only_router = false
  @router = nil
end

#routerObject

stop : [-] shutdown : disable @router close : [-] terminate: [-]



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 27

def router
  @_event_emitter_used_actually = true

  return Engine.root_agent.source_only_router if @_event_emitter_force_source_only_router

  if @_event_emitter_lazy_init
    @router = @primary_instance.router
  end
  if @router.respond_to?(:caller_plugin_id=)
    @router.caller_plugin_id = self.plugin_id
  end
  @router
end

#router=(r) ⇒ Object



41
42
43
44
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 41

def router=(r)
  # not recommended now...
  @router = r
end

#terminateObject



106
107
108
109
# File 'lib/fluent/plugin_helper/event_emitter.rb', line 106

def terminate
  @router = nil
  super
end