Skip to content

Commit

Permalink
add do_stop and do_close to avoid using super
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvd committed Sep 18, 2015
1 parent 0be3994 commit 140a456
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 10 additions & 2 deletions lib/logstash/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ def tag(newtag)
@tags << newtag
end # def tag

# if you override stop, don't forget to call super
# as the first action
public
# override stop if you need to do more than do_stop to
# enforce the input plugin to return from `run`.
# e.g. a tcp plugin might need to close the tcp socket
# so blocking read operation aborts
def stop
# override if necessary
end

public
def do_stop
@logger.debug("stopping", :plugin => self)
@stop_called.make_true
stop
end

# stop? should never be overriden
Expand Down
8 changes: 4 additions & 4 deletions lib/logstash/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def inputworker(plugin)
sleep(1)
retry
ensure
plugin.close
plugin.do_close
end
end # def inputworker

Expand Down Expand Up @@ -214,7 +214,7 @@ def filterworker
@logger.error("Exception in filterworker", "exception" => e, "backtrace" => e.backtrace)
end

@filters.each(&:close)
@filters.each(&:do_close)
end # def filterworker

def outputworker
Expand All @@ -228,7 +228,7 @@ def outputworker
end
ensure
@outputs.each do |output|
output.worker_plugins.each(&:close)
output.worker_plugins.each(&:do_close)
end
end # def outputworker

Expand All @@ -245,7 +245,7 @@ def shutdown
InflightEventsReporter.logger = @logger
InflightEventsReporter.start(@input_to_filter, @filter_to_output, @outputs)

@inputs.each(&:stop)
@inputs.each(&:do_stop)
end # def shutdown

def plugin(plugin_type, name, *args)
Expand Down
11 changes: 9 additions & 2 deletions lib/logstash/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ def initialize(params=nil)
@logger = Cabin::Channel.get(LogStash)
end

# close is called during shutdown, after the plugin worker
# main task terminates
public
def do_close
@logger.debug("closing", :plugin => self)
close
end

# Subclasses should implement this close method if you need to perform any
# special tasks during shutdown (like flushing, etc.)
# if you override close, don't forget to call super
public
def close
@logger.debug("closing", :plugin => self)
# ..
end

def to_s
Expand Down

0 comments on commit 140a456

Please sign in to comment.