<NME> plugin.rb
<BEF> ADDFILE
<MSG> - Add LogStash::Plugin for generalizing threads/workers involved in the
  pipeline. This allows us to do cascading shutdowns of inputs then
  filters then outputs.

  - If all inputs finish, start shtdown.
  - If all plugins are finished, then exit.
  - A special 'event' gets passed down during shutdown
  (LogStash::SHUTDOWN)

  At this point, doing 'echo "foo" | logstash -f foo.conf' will result
  in a shutdown after the "foo" line has been fully processed. As
  intended!

- Refactored the input/filter/output thread launchers to separate
  methods.
- Have 'stdin' finish if it reads EOF
- Currently only stdout and amqp outputs support shutdown properly.

<DFF> @@ -0,0 +1,50 @@
+require "logstash/namespace"
+require "logstash/logging"
+require "logstash/config/mixin"
+
+class LogStash::Plugin
+
+  # This method is called when someone or something wants this plugin to shut
+  # down. When you successfully shutdown, you must call 'finished'
+  # You must also call 'super' in any subclasses.
+  public
+  def shutdown(queue)
+    # By default, shutdown is assumed a no-op for all plugins.
+    # If you need to take special efforts to shutdown (like waiting for
+    # an operation to complete, etc)
+    @logger.info("Got shutdown signal for #{self}")
+
+    @shutdown_queue = queue
+    if @plugin_state == :finished
+      finished
+    else
+      @plugin_state = :terminating
+    end
+  end # def shutdown
+
+  # You should call this method when you (the plugin) are done with work
+  # forever.
+  public
+  def finished
+    if @shutdown_queue
+      @logger.info("Sending shutdown event to agent queue. (plugin #{to_s})")
+      @shutdown_queue << self
+    end
+
+    if @plugin_state != :finished
+      @logger.info("Plugin #{to_s} is finished")
+      @plugin_state = :finished
+    end
+  end # def finished
+
+  public
+  def finished?
+    return @plugin_state == :finished
+  end # def finished?
+
+  public
+  def running?
+    return @plugin_state != :finished
+  end # def finished?
+
+end # class LogStash::Plugin

- Add LogStash::Plugin for generalizing threads/workers involved in the   pipeline. This allows us to do cascading shutdowns of inputs then   filters then outputs.