Sha256: 5e03f46bce00d575ce8ee762a4fec6225df1cef861723598378fa0307dee6563

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

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

require 'woodchuck/output'

class Woodchuck::Agent

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

  def initialize(options={})
    @paths = options[:paths]
    @logger = Woodchuck::Logger.new(::STDOUT)
    @mutex = Mutex.new
    @output = case options[:output]
                 when :stdout 
                   Woodchuck::Output::STDOUT.new
                 when :zeromq
                   Woodchuck::Output::ZeroMQ.new
                 when :redis
                   Woodchuck::Output::Redis.new
                 else
                   Woodchuck::Output::STDOUT.new
                 end
    @watcher = Woodchuck::Watcher.new(self, @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

1 entries across 1 versions & 1 rubygems

Version Path
woodchuck-0.0.1 lib/woodchuck/agent.rb