Class: Plog::Client
- Inherits:
-
Object
- Object
- Plog::Client
- Defined in:
- lib/plog/client.rb
Constant Summary collapse
- PROTOCOL_VERSION =
The protocol version spoken by this client.
Packets::PROTOCOL_VERSION
- RECV_SIZE =
65_536- DEFAULT_OPTIONS =
{ :host => '127.0.0.1', :port => 23456, # Use the socket's default value unless this option is specified. :send_buffer_size => nil, :chunk_size => 64000, :large_message_threshold => nil, :on_large_message => nil, :logger => Logger.new(nil) }
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
readonly
Returns the value of attribute chunk_size.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#large_message_threshold ⇒ Object
readonly
Returns the value of attribute large_message_threshold.
-
#last_message_id ⇒ Object
readonly
Returns the value of attribute last_message_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#on_large_message ⇒ Object
readonly
Returns the value of attribute on_large_message.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#send_buffer_size ⇒ Object
readonly
Returns the value of attribute send_buffer_size.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #reset ⇒ Object
- #send(message, options = {}) ⇒ Object
- #socket ⇒ Object
- #stats(timeout = 3.0) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/plog/client.rb', line 38 def initialize(={}) = DEFAULT_OPTIONS.merge() @host = [:host] @port = [:port] @send_buffer_size = [:send_buffer_size] @chunk_size = [:chunk_size] = [:large_message_threshold] = [:on_large_message] @logger = [:logger] = Mutex.new end |
Instance Attribute Details
#chunk_size ⇒ Object (readonly)
Returns the value of attribute chunk_size.
30 31 32 |
# File 'lib/plog/client.rb', line 30 def chunk_size @chunk_size end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
27 28 29 |
# File 'lib/plog/client.rb', line 27 def host @host end |
#large_message_threshold ⇒ Object (readonly)
Returns the value of attribute large_message_threshold.
32 33 34 |
# File 'lib/plog/client.rb', line 32 def end |
#last_message_id ⇒ Object (readonly)
Returns the value of attribute last_message_id.
36 37 38 |
# File 'lib/plog/client.rb', line 36 def end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
34 35 36 |
# File 'lib/plog/client.rb', line 34 def logger @logger end |
#on_large_message ⇒ Object (readonly)
Returns the value of attribute on_large_message.
33 34 35 |
# File 'lib/plog/client.rb', line 33 def end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
28 29 30 |
# File 'lib/plog/client.rb', line 28 def port @port end |
#send_buffer_size ⇒ Object (readonly)
Returns the value of attribute send_buffer_size.
29 30 31 |
# File 'lib/plog/client.rb', line 29 def send_buffer_size @send_buffer_size end |
Instance Method Details
#reset ⇒ Object
89 90 91 92 |
# File 'lib/plog/client.rb', line 89 def reset close_socket end |
#send(message, options = {}) ⇒ 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 82 83 84 85 86 87 |
# File 'lib/plog/client.rb', line 57 def send(, = {}) # Interpret the encoding of the string as binary so that chunking occurs # at the byte-level and not at the character-level. = .dup.force_encoding('BINARY') () if () = = .length = Checksum.compute() chunks = chunk_string(, chunk_size) logger.debug { "Plog: sending (#{message_id}; #{chunks.length} chunk(s))" } chunks.each_with_index do |data, index| send_to_socket( Packets::MultipartMessage.encode( , , , chunk_size, chunks.count, index, data, )) end rescue => e logger.error { "Plog: error sending message: #{e}" } raise e end |
#socket ⇒ Object
94 95 96 |
# File 'lib/plog/client.rb', line 94 def socket @socket ||= open_socket end |
#stats(timeout = 3.0) ⇒ Object
52 53 54 55 |
# File 'lib/plog/client.rb', line 52 def stats(timeout = 3.0) send_to_socket("\0\0stats") JSON.parse receive_packet_from_socket(timeout) end |