Navigation Menu

Skip to content

Commit

Permalink
Separate methods to send or reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 27, 2014
1 parent 1d909f6 commit 052fb3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
26 changes: 17 additions & 9 deletions lib/droonga/fluent_message_sender.rb
Expand Up @@ -47,20 +47,23 @@ def shutdown
logger.trace("shutdown: done")
end

def send(tag, data, options={})
def send(tag, data)
logger.trace("send: start")
fluent_message = [tag, Time.now.to_i, data]
packed_fluent_message = MessagePackPacker.pack(fluent_message)
packed_fluent_message = create_packed_fluent_message(tag, data)
connect unless connected?
if options[:reserve]
@socket.reserve_write(packed_fluent_message)
logger.trace("send: reserved")
else
@socket.write(packed_fluent_message)
logger.trace("send: done")
@socket.write(packed_fluent_message)
logger.trace("send: done")
end
end

def reserve_send(tag, data)
logger.trace("reserve_send: start")
packed_fluent_message = create_packed_fluent_message(tag, data)
connect unless connected?
@socket.reserve_write(packed_fluent_message)
logger.trace("reserve_send: done")
end

def resume
connect
@socket.resume
Expand Down Expand Up @@ -113,6 +116,11 @@ def shutdown_socket
@socket.close unless @socket.closed?
end

def create_packed_fluent_message(tag, data)
fluent_message = [tag, Time.now.to_i, data]
MessagePackPacker.pack(fluent_message)
end

def log_tag
"[#{Process.ppid}][#{Process.pid}] fluent-message-sender"
end
Expand Down
11 changes: 8 additions & 3 deletions lib/droonga/forwarder.rb
Expand Up @@ -47,7 +47,8 @@ def forward(message, destination)
command = destination["type"]
receiver = destination["to"]
arguments = destination["arguments"]
output(receiver, message, command, arguments)
reserve = destination["reserve"]
output(receiver, message, command, arguments, :reserve => reserve)
logger.trace("forward: done")
end

Expand All @@ -72,7 +73,7 @@ def resume
end

private
def output(receiver, message, command, arguments)
def output(receiver, message, command, arguments, options={})
logger.trace("output: start")
if not receiver.is_a?(String) or not command.is_a?(String))
logger.trace("output: abort: invalid argument",
Expand Down Expand Up @@ -103,7 +104,11 @@ def output(receiver, message, command, arguments)
output_tag = "#{tag}.message"
log_info = "<#{receiver}>:<#{output_tag}>"
logger.trace("output: post: start: #{log_info}")
sender.send(output_tag, message)
if options[:reserve]
sender.reserve_send(output_tag, message)
else
sender.send(output_tag, message)
end
logger.trace("output: post: done: #{log_info}")
logger.trace("output: done")
end
Expand Down

0 comments on commit 052fb3e

Please sign in to comment.