Sha256: 3281991b1af1c2da6e723dfd00efbc64d7684f71db8e23aa2d33c6c7949e6902

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module EventMachine
  module ProxyServer
    class Backend < EventMachine::Connection
      attr_accessor :plexer, :data, :name, :debug

      def initialize(debug = false)
        @debug = debug
        @connected = EM::DefaultDeferrable.new
        @data = []
      end

      def connection_completed
        debug [@name, :conn_complete]
        @connected.succeed
      end

      def receive_data(data)
        debug [@name, data]
        @data.push data
        @plexer.relay_from_backend(@name, data)
      end

      # Buffer data until the connection to the backend server
      # is established and is ready for use
      def send(data)
        @connected.callback { send_data data }
      end

      # Notify upstream plexer that the backend server is done
      # processing the request
      def unbind
        debug [@name, :unbind]
        @plexer.unbind_backend(@name)
      end

      private

      def debug(*data)
        return unless @debug
        require 'pp'
        pp data
        puts
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
em-proxy-0.1.2 lib/em-proxy/backend.rb
em-proxy-0.1.1 lib/em-proxy/backend.rb