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

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

Overview

Since:

  • 0.0.1

Defined Under Namespace

Classes: NodeProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, socket, adapter) ⇒ Writer

Returns a new instance of Writer.

Since:

  • 0.0.1



9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#readerObject (readonly)

Since:

  • 0.0.1



7
8
9
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 7

def reader
  @reader
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

Since:

  • 0.0.1



19
20
21
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 19

def alive?
  !!@alive
end

#asyncObject

Since:

  • 0.0.1



23
24
25
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 23

def async
  self
end

#terminateObject

Since:

  • 0.0.1



42
43
44
45
46
47
# 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) ⇒ Object

Since:

  • 0.0.1



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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