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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/woodchuck/agent.rb', line 11

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

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/woodchuck/agent.rb', line 9

def logger
  @logger
end

#outputObject

Returns the value of attribute output.



9
10
11
# File 'lib/woodchuck/agent.rb', line 9

def output
  @output
end

#pathsObject

Returns the value of attribute paths.



9
10
11
# File 'lib/woodchuck/agent.rb', line 9

def paths
  @paths
end

#watcherObject

Returns the value of attribute watcher.



9
10
11
# File 'lib/woodchuck/agent.rb', line 9

def watcher
  @watcher
end

#watcher_threadObject

Returns the value of attribute watcher_thread.



9
10
11
# File 'lib/woodchuck/agent.rb', line 9

def watcher_thread
  @watcher_thread
end

Instance Method Details

#inspectObject



45
46
47
# File 'lib/woodchuck/agent.rb', line 45

def inspect
  to_s
end

#start(blocking = false) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/woodchuck/agent.rb', line 28

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



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

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