Class: Bones::RPC::Synchronous::Connection::Writer
- Inherits:
-
Object
- Object
- Bones::RPC::Synchronous::Connection::Writer
- Defined in:
- lib/bones/rpc/synchronous/connection/writer.rb
Overview
Defined Under Namespace
Classes: NodeProxy
Instance Attribute Summary collapse
- #reader ⇒ Object readonly
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #async ⇒ Object
-
#initialize(connection, socket, adapter) ⇒ Writer
constructor
A new instance of Writer.
- #terminate ⇒ Object
- #write(operations) ⇒ Object
Constructor Details
#initialize(connection, socket, adapter) ⇒ Writer
Returns a new instance of Writer.
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
#reader ⇒ Object (readonly)
7 8 9 |
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 7 def reader @reader end |
Instance Method Details
#alive? ⇒ Boolean
19 20 21 |
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 19 def alive? !!@alive end |
#async ⇒ Object
23 24 25 |
# File 'lib/bones/rpc/synchronous/connection/writer.rb', line 23 def async self end |
#terminate ⇒ Object
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
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 |, future| .serialize(@buffer, @adapter) .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.}", "n/a") terminate raise e end |