Class: Mutalisk::Connection
- Inherits:
-
Object
- Object
- Mutalisk::Connection
- Defined in:
- lib/mutalisk/connection.rb
Constant Summary collapse
- READ_MAXLEN =
100_000
Instance Attribute Summary collapse
-
#bytes_read ⇒ Object
readonly
stats.
-
#connect_errors ⇒ Object
readonly
Returns the value of attribute connect_errors.
-
#connection_id ⇒ Object
readonly
Returns the value of attribute connection_id.
-
#read_errors ⇒ Object
readonly
Returns the value of attribute read_errors.
-
#requests_sent ⇒ Object
readonly
Returns the value of attribute requests_sent.
-
#responses_received ⇒ Object
readonly
Returns the value of attribute responses_received.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#write_errors ⇒ Object
readonly
Returns the value of attribute write_errors.
Instance Method Summary collapse
- #idle? ⇒ Boolean
-
#initialize(thread, uri, cid) ⇒ Connection
constructor
A new instance of Connection.
- #receive ⇒ Object
- #send_request(headers = nil) ⇒ Object
Constructor Details
#initialize(thread, uri, cid) ⇒ Connection
Returns a new instance of Connection.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mutalisk/connection.rb', line 20 def initialize(thread, uri, cid) @thread = thread @uri = uri @connection_id = cid # stats @bytes_read = 0 @requests_sent = 0 @responses_received = 0 @read_errors = 0 @write_errors = 0 @connect_errors = 0 connect end |
Instance Attribute Details
#bytes_read ⇒ Object (readonly)
stats
11 12 13 |
# File 'lib/mutalisk/connection.rb', line 11 def bytes_read @bytes_read end |
#connect_errors ⇒ Object (readonly)
Returns the value of attribute connect_errors.
16 17 18 |
# File 'lib/mutalisk/connection.rb', line 16 def connect_errors @connect_errors end |
#connection_id ⇒ Object (readonly)
Returns the value of attribute connection_id.
7 8 9 |
# File 'lib/mutalisk/connection.rb', line 7 def connection_id @connection_id end |
#read_errors ⇒ Object (readonly)
Returns the value of attribute read_errors.
14 15 16 |
# File 'lib/mutalisk/connection.rb', line 14 def read_errors @read_errors end |
#requests_sent ⇒ Object (readonly)
Returns the value of attribute requests_sent.
12 13 14 |
# File 'lib/mutalisk/connection.rb', line 12 def requests_sent @requests_sent end |
#responses_received ⇒ Object (readonly)
Returns the value of attribute responses_received.
13 14 15 |
# File 'lib/mutalisk/connection.rb', line 13 def responses_received @responses_received end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
5 6 7 |
# File 'lib/mutalisk/connection.rb', line 5 def socket @socket end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
8 9 10 |
# File 'lib/mutalisk/connection.rb', line 8 def thread @thread end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/mutalisk/connection.rb', line 6 def uri @uri end |
#write_errors ⇒ Object (readonly)
Returns the value of attribute write_errors.
15 16 17 |
# File 'lib/mutalisk/connection.rb', line 15 def write_errors @write_errors end |
Instance Method Details
#idle? ⇒ Boolean
36 37 38 |
# File 'lib/mutalisk/connection.rb', line 36 def idle? !!@idle end |
#receive ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mutalisk/connection.rb', line 57 def receive @response ||= Response.new(@request) resp = @socket.readpartial(READ_MAXLEN) @bytes_read += resp.bytesize @response << resp if @response.complete? @idle = true @responses_received += 1 end @response rescue EOFError @idle = true @response rescue Errno::ECONNRESET => e @read_errors += 1 @idle = true reconnect @response end |
#send_request(headers = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mutalisk/connection.rb', line 40 def send_request(headers=nil) raise ConnectionBusyError unless idle? reset_response @request = spawn_request(headers) @request.start @idle = false @requests_sent += 1 @request rescue Errno::EPIPE @write_errors += 1 reconnect end |