Class: Woodchuck::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/woodchuck/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Agent

Returns a new instance of Agent.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/woodchuck/agent.rb', line 14

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

Instance Attribute Details

#input_formatObject

Returns the value of attribute input_format.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def input_format
  @input_format
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def logger
  @logger
end

#outputObject

Returns the value of attribute output.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def output
  @output
end

#pathsObject

Returns the value of attribute paths.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def paths
  @paths
end

#watcherObject

Returns the value of attribute watcher.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def watcher
  @watcher
end

#watcher_threadObject

Returns the value of attribute watcher_thread.



12
13
14
# File 'lib/woodchuck/agent.rb', line 12

def watcher_thread
  @watcher_thread
end

Instance Method Details

#inspectObject



55
56
57
# File 'lib/woodchuck/agent.rb', line 55

def inspect
  to_s
end

#start(blocking = false) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/woodchuck/agent.rb', line 38

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

#stopObject



47
48
49
50
51
52
53
# File 'lib/woodchuck/agent.rb', line 47

def stop
  @mutex.synchronize do
    return if @stop == true
    @stop = true
  end
  Thread.kill(@watcher_thread) if @watcher_thread
end