Class: Droonga::MessagePusher

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/message_pusher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop) ⇒ MessagePusher

Returns a new instance of MessagePusher.



23
24
25
# File 'lib/droonga/message_pusher.rb', line 23

def initialize(loop)
  @loop = loop
end

Instance Attribute Details

#raw_receiverObject (readonly)

Returns the value of attribute raw_receiver.



22
23
24
# File 'lib/droonga/message_pusher.rb', line 22

def raw_receiver
  @raw_receiver
end

Instance Method Details

#push(message) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/droonga/message_pusher.rb', line 42

def push(message)
  $log.trace("#{log_tag}: push: start")
  packed_message = message.to_msgpack
  path = @raw_receiver.path
  sender = Coolio::UNIXSocket.connect(path)
  sender.write(message.to_msgpack)
  sender.on_write_complete do
    close
  end
  @loop.attach(sender)
  $log.trace("#{log_tag}: push: done")
end

#shutdownObject



34
35
36
37
38
39
40
# File 'lib/droonga/message_pusher.rb', line 34

def shutdown
  $log.trace("#{log_tag}: shutdown: start")
  socket_path = @raw_receiver.path
  @raw_receiver.close
  FileUtils.rm_f(socket_path)
  $log.trace("#{log_tag}: shutdown: done")
end

#start(base_path) ⇒ Object



27
28
29
30
31
32
# File 'lib/droonga/message_pusher.rb', line 27

def start(base_path)
  socket_path = "#{base_path}.sock"
  FileUtils.rm_f(socket_path)
  @raw_receiver = UNIXServer.new(socket_path)
  FileUtils.chmod(0600, socket_path)
end