Class: Droonga::JobPusher

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/droonga/job_pusher.rb

Defined Under Namespace

Classes: JobQueue, WorkerConnection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop, base_path) ⇒ JobPusher

Returns a new instance of JobPusher.



26
27
28
29
30
31
# File 'lib/droonga/job_pusher.rb', line 26

def initialize(loop, base_path)
  @loop = loop
  @socket_path = "#{base_path}.#{Process.pid}.#{object_id}.sock"
  @job_queue = JobQueue.new(@loop)
  @server = nil
end

Instance Attribute Details

#socket_pathObject (readonly)

Returns the value of attribute socket_path.



25
26
27
# File 'lib/droonga/job_pusher.rb', line 25

def socket_path
  @socket_path
end

Instance Method Details

#broadcast(message) ⇒ Object



66
67
68
69
70
# File 'lib/droonga/job_pusher.rb', line 66

def broadcast(message)
  logger.trace("broadcast start")
  @job_queue.broadcast(message)
  logger.trace("broadcast done")
end

#closeObject



45
46
47
48
49
50
# File 'lib/droonga/job_pusher.rb', line 45

def close
  return unless @server
  @server.close
  logger.trace("close: socket watcher detached",
               :watcher => @socket)
end

#push(message) ⇒ Object



60
61
62
63
64
# File 'lib/droonga/job_pusher.rb', line 60

def push(message)
  logger.trace("push: start")
  @job_queue.push(message)
  logger.trace("push: done")
end

#shutdownObject



52
53
54
55
56
57
58
# File 'lib/droonga/job_pusher.rb', line 52

def shutdown
  logger.trace("shutdown: start")
  close
  @job_queue.close
  FileUtils.rm_f(@socket_path)
  logger.trace("shutdown: done")
end

#startObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/droonga/job_pusher.rb', line 33

def start
  FileUtils.rm_f(@socket_path)
  @server = Coolio::UNIXServer.new(@socket_path) do |connection|
    @job_queue.add_worker(WorkerConnection.new(connection))
  end
  FileUtils.chmod(0600, @socket_path)
  @loop.attach(@server)
  logger.trace("connect: socket watcher attached",
               :watcher     => @socket,
               :socket_path => @socket_path)
end