Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract OutputChain #800

Merged
merged 3 commits into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/fluent/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require 'fluent/event'
require 'fluent/buffer'
require 'fluent/input'
require 'fluent/output_chain'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This require seems not needed because 'fluent/output' requires 'fluent/output_chain'.
If any code were broken, it depends on that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've confirmed that this require is needless.
Thank you!

require 'fluent/output'
require 'fluent/filter'
require 'fluent/match'
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