Parent

Included Modules

RText::Frontend::Connector

Public Class Methods

new(config, options={}) click to toggle source
# File lib/rtext/frontend/connector.rb, line 12
def initialize(config, options={})
  @config = config
  @logger = options[:logger]
  @state = :off
  @invocation_id = 1
  @invocations = {}
  @busy = false
  @busy_start_time = nil
  @connection_listener = options[:connect_callback]
  @outfile_provider = options[:outfile_provider]
  @keep_outfile = options[:keep_outfile]
  @connection_timeout = options[:connection_timeout] || 10
end

Public Instance Methods

execute_command(obj, options={}) click to toggle source
# File lib/rtext/frontend/connector.rb, line 26
def execute_command(obj, options={})
  timeout = options[:timeout] || 5
  @busy = false if @busy_start_time && (Time.now > @busy_start_time + timeout)
  if @busy
    do_work
    :backend_busy 
  elsif connected?
    obj["invocation_id"] = @invocation_id
    obj["type"] = "request"
    @socket.send(serialize_message(obj), 0)
    result = nil
    @busy = true
    @busy_start_time = Time.now
    if options[:response_callback]
      @invocations[@invocation_id] = lambda do |r|
        if r["type"] == "response" || r["type"] =~ /error$/
          @busy = false
        end
        options[:response_callback].call(r)
      end
      @invocation_id += 1
      do_work
      :request_pending 
    else
      @invocations[@invocation_id] = lambda do |r|
        if r["type"] == "response" || r["type"] =~ /error$/ 
          result = r
          @busy = false
        end
      end
      @invocation_id += 1
      while !result
        if Time.now > @busy_start_time + timeout
          result = :timeout
          @busy = false
        else
          sleep(0.1)
          do_work
        end
      end
      result
    end
  else
    connect unless connecting?
    do_work
    :connecting 
  end
end
resume() click to toggle source
# File lib/rtext/frontend/connector.rb, line 75
def resume
  do_work
end
stop() click to toggle source
# File lib/rtext/frontend/connector.rb, line 79
def stop
  while connecting?
    do_work
    sleep(0.1)
  end
  if connected?
    execute_command({"type" => "request", "command" => "stop"})
    while do_work 
      sleep(0.1)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.