Class: Proxi::ConsoleReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/proxi/reporting.rb

Overview

This is a very basic console reporter to see what's happening

Subscribe to connection events, and you will see output that looks like this

1. +++
1. < 91
2. +++
3. +++
2. < 91
3. < 91
1. > 4096
1. > 3422
1. ---

Each connection gets a unique incremental number assigned, followed by:

  • '+++' new connection

  • '—' connection closed

  • '< 1234' number of bytes proxied to the remote

  • '> 1234' number of bytes proxied back from the remote

Instance Method Summary collapse

Constructor Details

#initializeConsoleReporter

Returns a new instance of ConsoleReporter.


28
29
30
31
32
# File 'lib/proxi/reporting.rb', line 28

def initialize
  @count = 0
  @mutex = Mutex.new
  @connections = {}
end

Instance Method Details

#data_in(conn, data) ⇒ Object


44
45
46
# File 'lib/proxi/reporting.rb', line 44

def data_in(conn, data)
  puts "#{@connections[conn]}. < #{data.size}"
end

#data_out(conn, data) ⇒ Object


48
49
50
# File 'lib/proxi/reporting.rb', line 48

def data_out(conn, data)
  puts "#{@connections[conn]}. > #{data.size}"
end

#end_connection(conn) ⇒ Object


39
40
41
42
# File 'lib/proxi/reporting.rb', line 39

def end_connection(conn)
  puts "#{@connections[conn]}. ---"
  @connections.delete(conn)
end

#main_loop_error(conn, exc) ⇒ Object


52
53
54
55
# File 'lib/proxi/reporting.rb', line 52

def main_loop_error(conn, exc)
  STDERR.puts "#{@connections[conn]}. #{exc.class} #{exc.message}"
  STDERR.puts exc.backtrace
end

#start_connection(conn) ⇒ Object


34
35
36
37
# File 'lib/proxi/reporting.rb', line 34

def start_connection(conn)
  @mutex.synchronize { @connections[conn] = (@count += 1) }
  puts "#{@connections[conn]}. +++"
end