class RubyProxy::DRbClient

Get DRbClient

Attributes

ip[RW]
port[RW]

Public Class Methods

add_load_path(path) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 238
def add_load_path(path)
    #path = File.expand_path(path)
    client.add_load_path(path)
end
alive?() click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 217
def alive?
    @client.respond_to?("any_thing")
    true
rescue DRb::DRbConnError
    false
end
client() click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 206
def client
    begin
        stop_service if @client.nil? and Config.autostart
        start_service if @client.nil? and Config.autostart
        connect_addr = "druby://#{Config.ip}:#{Config.port}"
        @client ||= DRbObject.new(nil, connect_addr)
    rescue DRb::DRbConnError
        raise RubyProxy::NotConnError, "can connect to druby server: #{connect_addr}"
    end
end
do_at_exit() click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 290
def do_at_exit
    at_exit do
        info 'try to stop service'
        stop_service
    end
end
proxy_global_get(arg) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 230
def proxy_global_get(arg)
    client.proxy_global_get(arg)
end
proxy_global_set(arg, var) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 234
def proxy_global_set(arg, var)
    client.proxy_global_set(arg, var)
end
proxy_load(file) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 226
def proxy_load(file)
    client.proxy_load(file)
end
start_command() click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 258
def start_command
    #raise RubyProxy::CommandNotFoundError, "ruby command can not be found: #{Config.command}" unless File.file?(Config.command)
    server_file = File.expand_path File.join(File.dirname(__FILE__), 'server.rb')
    Config.command + " " + server_file
end
start_service(t=10) click to toggle source

not use it later

# File lib/woolen_common/ruby_proxy/client.rb, line 244
def start_service(t=10)
    message = nil
    @service_log = nil
    info 'start ruby proxy server...'
    info start_command
    #~ @server_thread =  Thread.new do |t|
    #~ t.abort_on_exception = true
    @service_log = IO.popen(start_command)
    #~ end
    #~ @server_thread.abort_on_exception = true
    wait_until_server_start_time(t)
    do_at_exit if Config.autostart
end
stop_service(t=5) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 264
def stop_service(t=5)
    #TCPSocket.new(Config.ip,Config.port)
    @client ||= DRbObject.new(nil, "druby://#{Config.ip}:#{Config.port}")
    @client.stop_proxy
    sleep 1
rescue
    debug "service not start,stop fail!"
    debug "#{$!}"
ensure
    @client = nil
end
wait_until_server_start_time(t) click to toggle source
# File lib/woolen_common/ruby_proxy/client.rb, line 276
def wait_until_server_start_time(t)
    t.times do |tt|
        begin
            #~ raise CannotStartServer, "" unless @server_thread.alive?
            TCPSocket.new(Config.ip, Config.port)
            info 'server is starting'
            return true
        rescue Exception
            sleep 1
        end
    end
    raise RuntimeError, 'start drbserver fail'
end