-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #843 from fluent/introduce-plugin-helpers
add new Plugin::Base class and PluginHelper modules
- Loading branch information
Showing
17 changed files
with
1,696 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin' | ||
require 'fluent/configurable' | ||
require 'fluent/plugin_id' | ||
require 'fluent/log' | ||
require 'fluent/plugin_helper' | ||
|
||
module Fluent | ||
module Plugin | ||
class Base | ||
include Configurable | ||
include PluginId | ||
include PluginLoggerMixin | ||
include PluginHelper::Mixin | ||
|
||
State = Struct.new(:configure, :start, :stop, :shutdown, :close, :terminate) | ||
|
||
def initialize | ||
super | ||
@state = State.new(false, false, false, false, false, false) | ||
end | ||
|
||
def has_router? | ||
false | ||
end | ||
|
||
def configure(conf) | ||
super | ||
@state.configure = true | ||
self | ||
end | ||
|
||
def start | ||
@log.reset | ||
@state.start = true | ||
self | ||
end | ||
|
||
def stop | ||
@state.stop = true | ||
self | ||
end | ||
|
||
def shutdown | ||
@state.shutdown = true | ||
self | ||
end | ||
|
||
def close | ||
@state.close = true | ||
self | ||
end | ||
|
||
def terminate | ||
@state.terminate = true | ||
@log.reset | ||
self | ||
end | ||
|
||
def configured? | ||
@state.configure | ||
end | ||
|
||
def started? | ||
@state.start | ||
end | ||
|
||
def stopped? | ||
@state.stop | ||
end | ||
|
||
def shutdown? | ||
@state.shutdown | ||
end | ||
|
||
def closed? | ||
@state.close | ||
end | ||
|
||
def terminated? | ||
@state.terminate | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin_helper/event_emitter' | ||
require 'fluent/plugin_helper/thread' | ||
require 'fluent/plugin_helper/event_loop' | ||
require 'fluent/plugin_helper/timer' | ||
require 'fluent/plugin_helper/child_process' | ||
|
||
module Fluent | ||
module PluginHelper | ||
module Mixin | ||
def self.included(mod) | ||
mod.extend(Fluent::PluginHelper) | ||
end | ||
end | ||
|
||
def helpers(*snake_case_symbols) | ||
helper_modules = snake_case_symbols.map{|name| Fluent::PluginHelper.const_get(name.to_s.split('_').map(&:capitalize).join) } | ||
include *helper_modules | ||
end | ||
end | ||
end |
Oops, something went wrong.