Sha256: 4f9858d2e752e32d0010d04a92acc3d786de1cee57330d7d5a45e2d7bbe4fb7e

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'yajl'
require 'socket'
require 'thread'

require 'woodchuck/output'
require 'woodchuck/input'
require 'woodchuck/input/plain'
require 'woodchuck/input/json_event'

class Woodchuck::Agent

  attr_accessor :logger, :watcher, :watcher_thread, :paths, :output, :input_format

  def initialize(options={})
    @paths = options[:paths]
		options[:log_level] ||= :info
    @logger = Woodchuck::Logger.new(::STDOUT)
		@logger.level = options[:log_level]
    @mutex = Mutex.new
    @output = case options[:output]
                 when :zeromq
                   Woodchuck::Output::ZeroMQ.new(options[:log_level])
                 when :redis
                   Woodchuck::Output::Redis.new(options[:log_level])
                 else
                   Woodchuck::Output::STDOUT.new(options[:log_level])
                 end
		@input_format = case options[:input_format]
			when :json_event
				Woodchuck::Input::JsonEvent.new
			else
				Woodchuck::Input::Plain.new
			end

    @watcher = Woodchuck::Watcher.new(self, options[:log_level], @input_format, @paths)
  end

  def start(blocking=false)
    @mutex.synchronize do
      return if @stop == false
      @stop = false
    end
    @watcher_thread = Thread.new { @watcher.start }
    @watcher_thread.join if blocking
  end
  
  def stop
    @mutex.synchronize do
      return if @stop == true
      @stop = true
    end
    Thread.kill(@watcher_thread) if @watcher_thread
  end
  
  def inspect
    to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
woodchuck-json-event-0.0.2 lib/woodchuck/agent.rb
woodchuck-json-event-0.0.1 lib/woodchuck/agent.rb