From 47869b3b1942f9004d5ba9ff1d29b1effb99d8e4 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 10 Feb 2016 14:31:23 +0900 Subject: [PATCH 1/3] Extract OutputChain --- lib/fluent/load.rb | 1 + lib/fluent/output.rb | 42 +--------------------------- lib/fluent/output_chain.rb | 56 ++++++++++++++++++++++++++++++++++++++ test/test_output.rb | 1 + 4 files changed, 59 insertions(+), 41 deletions(-) create mode 100644 lib/fluent/output_chain.rb diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 200f09c8ec..1c8508a228 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -32,6 +32,7 @@ require 'fluent/event' require 'fluent/buffer' require 'fluent/input' +require 'fluent/output_chain' require 'fluent/output' require 'fluent/filter' require 'fluent/match' diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index 65f0445040..5589dcdf65 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -20,50 +20,11 @@ require 'fluent/configurable' require 'fluent/engine' require 'fluent/log' +require 'fluent/output_chain' require 'fluent/plugin' require 'fluent/timezone' module Fluent - class OutputChain - def initialize(array, tag, es, chain=NullOutputChain.instance) - @array = array - @tag = tag - @es = es - @offset = 0 - @chain = chain - end - - def next - if @array.length <= @offset - return @chain.next - end - @offset += 1 - result = @array[@offset-1].emit(@tag, @es, self) - result - end - end - - class CopyOutputChain < OutputChain - def next - if @array.length <= @offset - return @chain.next - end - @offset += 1 - es = @array.length > @offset ? @es.dup : @es - result = @array[@offset-1].emit(@tag, es, self) - result - end - end - - class NullOutputChain - require 'singleton' - include Singleton - - def next - end - end - - class Output include Configurable include PluginId @@ -622,4 +583,3 @@ class MultiOutput < Output #end end end - diff --git a/lib/fluent/output_chain.rb b/lib/fluent/output_chain.rb new file mode 100644 index 0000000000..80470455fc --- /dev/null +++ b/lib/fluent/output_chain.rb @@ -0,0 +1,56 @@ +# +# 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. +# + +module Fluent + class OutputChain + def initialize(array, tag, es, chain=NullOutputChain.instance) + @array = array + @tag = tag + @es = es + @offset = 0 + @chain = chain + end + + def next + if @array.length <= @offset + return @chain.next + end + @offset += 1 + result = @array[@offset-1].emit(@tag, @es, self) + result + end + end + + class CopyOutputChain < OutputChain + def next + if @array.length <= @offset + return @chain.next + end + @offset += 1 + es = @array.length > @offset ? @es.dup : @es + result = @array[@offset-1].emit(@tag, es, self) + result + end + end + + class NullOutputChain + require 'singleton' + include Singleton + + def next + end + end +end diff --git a/test/test_output.rb b/test/test_output.rb index dda1ca3c5d..21ba75c5ff 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -1,6 +1,7 @@ require_relative 'helper' require 'fluent/test' require 'fluent/output' +require 'fluent/output_chain' require 'timecop' require 'flexmock' From d247f7f452445ad11c02ef95b0894e3f55c2a3c7 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 10 Feb 2016 14:56:50 +0900 Subject: [PATCH 2/3] Add a comment in output_chain --- lib/fluent/output_chain.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fluent/output_chain.rb b/lib/fluent/output_chain.rb index 80470455fc..3883d62d8e 100644 --- a/lib/fluent/output_chain.rb +++ b/lib/fluent/output_chain.rb @@ -14,6 +14,7 @@ # limitations under the License. # +# OutputChain will be removed since v0.14. module Fluent class OutputChain def initialize(array, tag, es, chain=NullOutputChain.instance) From 5a1e5449f41c0017dad8dd6fafbc655dacf43a2d Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 12 Feb 2016 11:10:00 +0900 Subject: [PATCH 3/3] Remove needless require --- lib/fluent/load.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 1c8508a228..200f09c8ec 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -32,7 +32,6 @@ require 'fluent/event' require 'fluent/buffer' require 'fluent/input' -require 'fluent/output_chain' require 'fluent/output' require 'fluent/filter' require 'fluent/match'