class Bones::RPC::Synchronous::Connection::Writer

Attributes

reader[R]

Public Class Methods

new(connection, socket, adapter) click to toggle source
# File lib/bones/rpc/synchronous/connection/writer.rb, line 9
def initialize(connection, socket, adapter)
  @connection = connection
  @socket = socket
  @adapter = adapter
  @resolved = @connection.node.address.resolved
  @alive = true
  @buffer = ""
  @reader = Reader.new(@connection, @socket, @adapter, self)
end

Public Instance Methods

alive?() click to toggle source
# File lib/bones/rpc/synchronous/connection/writer.rb, line 19
def alive?
  !!@alive
end
async() click to toggle source
# File lib/bones/rpc/synchronous/connection/writer.rb, line 23
def async
  self
end
terminate() click to toggle source
# File lib/bones/rpc/synchronous/connection/writer.rb, line 42
def terminate
  return if not alive?
  @alive = false
  @reader.terminate
  @connection.cleanup_socket(@socket)
end
write(operations) click to toggle source
# File lib/bones/rpc/synchronous/connection/writer.rb, line 27
def write(operations)
  proxy = NodeProxy.new(@connection.node)
  operations.each do |message, future|
    message.serialize(@buffer, @adapter)
    message.attach(proxy, future) if future
  end
  @socket.write(@buffer)
  @buffer = ""
  return proxy
rescue EOFError, Errors::ConnectionFailure => e
  Loggable.warn("  BONES-RPC:", "#{@resolved} Writer terminating: #{e.message}", "n/a")
  terminate
  raise e
end