1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/drb/extservm.rb
nobu 5aad820604 * io.c (pipe_open): erred program name should be reported by
exceptions, instead of the first argument.

* process.c (rb_spawn): ditto.

* process.c (proc_spawn_v): use first argument as program name.

* win32/win32.c (rb_w32_aspawn): ditto.

* win32/win32.c (CreateChild): search executable file if no program
  name given.

* lib/drb/extservm.rb (invoke_service_command): use Process.spawn.
  [ruby-dev:23103]

* lib/rdoc/ri/ri_display.rb (setup_pager): use IO.popen.
  [ruby-dev:23086], [ruby-dev:23103]

* lib/rdoc/diagram.rb (convert_to_png): ditto.

* lib/rdoc/generators/chm_generator.rb (compile_project): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-03-02 07:30:35 +00:00

90 lines
1.5 KiB
Ruby

=begin
external service manager
Copyright (c) 2000 Masatoshi SEKI
=end
require 'drb/drb'
require 'thread'
module DRb
class ExtServManager
include DRbUndumped
@@command = {}
def self.command
@@command
end
def self.command=(cmd)
@@command = cmd
end
def initialize
@servers = {}
@waiting = []
@queue = Queue.new
@thread = invoke_thread
end
attr_reader :server
def service(name)
while true
server = nil
Thread.exclusive do
server = @servers[name] if @servers[name]
end
return server if server && server.alive?
invoke_service(name)
end
end
def regist(name, ro)
ary = nil
Thread.exclusive do
@servers[name] = ro
ary = @waiting
@waiting = []
end
ary.each do |th|
begin
th.run
rescue ThreadError
end
end
self
end
def unregist(name)
Thread.exclusive do
@servers.delete(name)
end
end
private
def invoke_thread
Thread.new do
while true
name = @queue.pop
invoke_service_command(name, @@command[name])
end
end
end
def invoke_service(name)
Thread.critical = true
@waiting.push Thread.current
@queue.push name
Thread.stop
end
def invoke_service_command(name, command)
raise "invalid command. name: #{name}" unless command
Thread.exclusive do
return if @servers.include?(name)
@servers[name] = false
end
Process.spawn("#{command} #{DRb.uri} #{name}")
end
end
end