Class: Fluent::Plugin::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable, SystemConfig::Mixin
Defined in:
lib/fluent/plugin/base.rb

Defined Under Namespace

Classes: State

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type

Constructor Details

#initializeBase

Returns a new instance of Base.



31
32
33
34
35
36
37
# File 'lib/fluent/plugin/base.rb', line 31

def initialize
  super
  @_state = State.new(false, false, false, false, false, false, false, false, false)
  @_context_router = nil
  @_fluentd_worker_id = nil
  @under_plugin_development = false
end

Instance Attribute Details

#under_plugin_developmentObject

Returns the value of attribute under_plugin_development.



29
30
31
# File 'lib/fluent/plugin/base.rb', line 29

def under_plugin_development
  @under_plugin_development
end

Instance Method Details

#after_shutdownObject



105
106
107
108
# File 'lib/fluent/plugin/base.rb', line 105

def after_shutdown
  @_state.after_shutdown = true
  self
end

#after_shutdown?Boolean

Returns:



144
145
146
# File 'lib/fluent/plugin/base.rb', line 144

def after_shutdown?
  @_state.after_shutdown
end

#after_startObject



85
86
87
88
# File 'lib/fluent/plugin/base.rb', line 85

def after_start
  @_state.after_start = true
  self
end

#after_started?Boolean

Returns:



128
129
130
# File 'lib/fluent/plugin/base.rb', line 128

def after_started?
  @_state.after_start
end

#before_shutdownObject



95
96
97
98
# File 'lib/fluent/plugin/base.rb', line 95

def before_shutdown
  @_state.before_shutdown = true
  self
end

#before_shutdown?Boolean

Returns:



136
137
138
# File 'lib/fluent/plugin/base.rb', line 136

def before_shutdown?
  @_state.before_shutdown
end

#closeObject



110
111
112
113
# File 'lib/fluent/plugin/base.rb', line 110

def close
  @_state.close = true
  self
end

#closed?Boolean

Returns:



148
149
150
# File 'lib/fluent/plugin/base.rb', line 148

def closed?
  @_state.close
end

#configure(conf) ⇒ Object



53
54
55
56
57
58
# File 'lib/fluent/plugin/base.rb', line 53

def configure(conf)
  super
  @_state ||= State.new(false, false, false, false, false, false, false, false, false)
  @_state.configure = true
  self
end

#configured?Boolean

Returns:



120
121
122
# File 'lib/fluent/plugin/base.rb', line 120

def configured?
  @_state.configure
end

#context_routerObject



76
77
78
# File 'lib/fluent/plugin/base.rb', line 76

def context_router
  @_context_router
end

#context_router=(router) ⇒ Object



72
73
74
# File 'lib/fluent/plugin/base.rb', line 72

def context_router=(router)
  @_context_router = router
end

#fluentd_worker_idObject



47
48
49
50
51
# File 'lib/fluent/plugin/base.rb', line 47

def fluentd_worker_id
  return @_fluentd_worker_id if @_fluentd_worker_id
  @_fluentd_worker_id = (ENV['SERVERENGINE_WORKER_ID'] || 0).to_i
  @_fluentd_worker_id
end

#has_router?Boolean

Returns:



39
40
41
# File 'lib/fluent/plugin/base.rb', line 39

def has_router?
  false
end

#inspectObject



156
157
158
159
160
161
162
# File 'lib/fluent/plugin/base.rb', line 156

def inspect
  # Plugin instances are sometimes too big to dump because it may have too many thins (buffer,storage, ...)
  # Original commit comment says that:
  #   To emulate normal inspect behavior `ruby -e'o=Object.new;p o;p (o.__id__<<1).to_s(16)'`.
  #   https://github.com/ruby/ruby/blob/trunk/gc.c#L788
  "#<%s:%014x>" % [self.class.name, '0x%014x' % (__id__ << 1)]
end

#multi_workers_ready?Boolean

Returns:



60
61
62
# File 'lib/fluent/plugin/base.rb', line 60

def multi_workers_ready?
  true
end

#plugin_root_dirObject



43
44
45
# File 'lib/fluent/plugin/base.rb', line 43

def plugin_root_dir
  nil # override this in plugin_id.rb
end

#shutdownObject



100
101
102
103
# File 'lib/fluent/plugin/base.rb', line 100

def shutdown
  @_state.shutdown = true
  self
end

#shutdown?Boolean

Returns:



140
141
142
# File 'lib/fluent/plugin/base.rb', line 140

def shutdown?
  @_state.shutdown
end

#startObject



80
81
82
83
# File 'lib/fluent/plugin/base.rb', line 80

def start
  @_state.start = true
  self
end

#started?Boolean

Returns:



124
125
126
# File 'lib/fluent/plugin/base.rb', line 124

def started?
  @_state.start
end

#stopObject



90
91
92
93
# File 'lib/fluent/plugin/base.rb', line 90

def stop
  @_state.stop = true
  self
end

#stopped?Boolean

Returns:



132
133
134
# File 'lib/fluent/plugin/base.rb', line 132

def stopped?
  @_state.stop
end

#string_safe_encoding(str) {|str| ... } ⇒ Object

Yields:

  • (str)


64
65
66
67
68
69
70
# File 'lib/fluent/plugin/base.rb', line 64

def string_safe_encoding(str)
  unless str.valid_encoding?
    log.info "invalid byte sequence is replaced in `#{str}`" if self.respond_to?(:log)
    str = str.scrub('?')
  end
  yield str
end

#terminateObject



115
116
117
118
# File 'lib/fluent/plugin/base.rb', line 115

def terminate
  @_state.terminate = true
  self
end

#terminated?Boolean

Returns:



152
153
154
# File 'lib/fluent/plugin/base.rb', line 152

def terminated?
  @_state.terminate
end