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..3883d62d8e --- /dev/null +++ b/lib/fluent/output_chain.rb @@ -0,0 +1,57 @@ +# +# 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. +# + +# OutputChain will be removed since v0.14. +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'