Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.21 KB | None | 0 0
  1. module EventMachine
  2.   module RequestRouter
  3.     module Backend
  4.       attr_accessor :plexer, :data, :name, :port, :host, :debug
  5.  
  6.       def initialize(options)
  7.         @debug = options[:debug] || false
  8.         @name = options[:name] || :unknown
  9.         debug [:initialize, @name]
  10.         @host = options[:host] || "localhost"
  11.         @port = options[:port] || 80
  12.         @plexer = options[:plexer] || nil
  13.         @data = []
  14.       end
  15.  
  16.       def connection_completed
  17.         debug [:backend_connection_completed, @name]
  18.       end
  19.  
  20.       def post_init
  21.         debug [:backend_post_init]
  22.       rescue
  23.         p $!
  24.         puts $!.backtrace.join("\n  ")
  25.         exit!
  26.       end
  27.  
  28.       def receive_data(data)
  29.         debug [:backend_receive_data, @name, data]
  30.  
  31.         unless @plexer.nil?
  32.           @plexer.relay_from_backend(data, @name)
  33.           self.close_connection_after_writing()
  34.         end
  35.       end
  36.  
  37.       def send(data)
  38.         debug [:send, @name]
  39.         self.send_data(data)
  40.       end
  41.  
  42.       def unbind
  43.         debug [:backend_unbind, @name]
  44.       end
  45.  
  46.       def debug(*data)
  47.         return unless @debug
  48.         require 'pp'
  49.         pp data
  50.         puts
  51.       end
  52.     end
  53.   end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement