module Spring::ApplicationImpl

Public Instance Methods

before_command() click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 65
def before_command
  # NOP
end
eager_preload() click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 15
def eager_preload
  with_pty { preload }
end
fork_child(client, streams, child_started) { || ... } click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 52
def fork_child(client, streams, child_started)
  pid = fork { yield }
  child_started[0] = true

  disconnect_database
  reset_streams

  log "forked #{pid}"
  manager.puts pid

  wait pid, streams, client
end
notify_manager_ready() click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 3
def notify_manager_ready
  manager.puts
end
receive_streams(client) click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 7
def receive_streams(client)
  3.times.map { IOWrapper.recv_io(client).to_io }
end
reopen_streams(streams) click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 11
def reopen_streams(streams)
  [STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
end
reset_streams() click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 28
def reset_streams
  [STDOUT, STDERR].each { |stream| stream.reopen(spring_env.log_file) }
  STDIN.reopen("/dev/null")
end
screen_attached?() click to toggle source
# File lib/spring-jruby/impl/pool/application.rb, line 19
def screen_attached?
  !system(%{screen -ls | grep "#{ENV['SPRING_SCREEN_NAME']}" | grep Detached > /dev/null})
end
screen_move_to_bottom() click to toggle source
# File lib/spring-jruby/impl/pool/application.rb, line 23
def screen_move_to_bottom
  puts "\033[22B"
end
wait(pid, streams, client) click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 33
def wait(pid, streams, client)
  @mutex.synchronize { @waiting << pid }

  # Wait in a separate thread so we can run multiple commands at once
  Thread.new {
    begin
      _, status = Process.wait2 pid
      log "#{pid} exited with #{status.exitstatus}"

      streams.each(&:close)
      client.puts(status.exitstatus)
      client.close
    ensure
      @mutex.synchronize { @waiting.delete pid }
      exit_if_finished
    end
  }
end
with_pty() { || ... } click to toggle source
# File lib/spring-jruby/impl/fork/application.rb, line 19
def with_pty
  PTY.open do |master, slave|
    [STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
    Thread.new { master.read }
    yield
    reset_streams
  end
end