Class: Droonga::MessagePusher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop) ⇒ MessagePusher



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

def initialize(loop)
  @loop = loop
end

Instance Attribute Details

#raw_receiverObject (readonly)

Returns the value of attribute raw_receiver.



26
27
28
# File 'lib/droonga/message_pusher.rb', line 26

def raw_receiver
  @raw_receiver
end

Instance Method Details

#push(message) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/droonga/message_pusher.rb', line 46

def push(message)
  logger.trace("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)
  logger.trace("push: done")
end

#shutdownObject



38
39
40
41
42
43
44
# File 'lib/droonga/message_pusher.rb', line 38

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

#start(base_path) ⇒ Object



31
32
33
34
35
36
# File 'lib/droonga/message_pusher.rb', line 31

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