Class: Bones::RPC::Connection::Writer

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/bones/rpc/connection/writer.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(connection, socket, adapter) ⇒ Writer

Returns a new instance of Writer.

Since:

  • 2.0.0


12
13
14
15
16
17
18
19
# File 'lib/bones/rpc/connection/writer.rb', line 12

def initialize(connection, socket, adapter)
  @connection = connection
  @socket = socket
  @adapter = adapter
  @resolved = @connection.node.address.resolved
  @buffer = ""
  @reader = Reader.new_link(@connection, @socket, @adapter)
end

Instance Method Details

#reader_died(actor, reason) ⇒ Object

Since:

  • 2.0.0


42
43
44
45
46
# File 'lib/bones/rpc/connection/writer.rb', line 42

def reader_died(actor, reason)
  Loggable.warn("  BONES-RPC:", "#{@resolved} Writer terminating: #{reason}", "n/a")
  @reader = nil
  terminate
end

#shutdownObject

Since:

  • 2.0.0


34
35
36
37
38
39
40
# File 'lib/bones/rpc/connection/writer.rb', line 34

def shutdown
  if @reader && @reader.alive?
    @reader.unlink
    @reader.async.terminate
  end
  @connection.cleanup_socket(@socket)
end

#write(operations) ⇒ Object

Since:

  • 2.0.0


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bones/rpc/connection/writer.rb', line 21

def write(operations)
  operations.each do |message, future|
    message.serialize(@buffer, @adapter)
    message.attach(@connection.node, future) if future
  end
  @socket.write(@buffer)
  @buffer = ""
  return true
rescue EOFError, Errors::ConnectionFailure => e
  Loggable.warn("  BONES-RPC:", "#{@resolved} Writer terminating: #{e.message}", "n/a")
  terminate
end