Skip to content

Commit

Permalink
Merge pull request #800 from cosmo0920/extract-output_chain
Browse files Browse the repository at this point in the history
Extract OutputChain
  • Loading branch information
tagomoris committed Mar 9, 2016
2 parents f7d6ef7 + 5a1e544 commit d417f58
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 41 deletions.
42 changes: 1 addition & 41 deletions lib/fluent/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -622,4 +583,3 @@ class MultiOutput < Output
#end
end
end

57 changes: 57 additions & 0 deletions lib/fluent/output_chain.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/test_output.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'helper'
require 'fluent/test'
require 'fluent/output'
require 'fluent/output_chain'
require 'timecop'
require 'flexmock'

Expand Down

0 comments on commit d417f58

Please sign in to comment.