Class: RubyProxy::DRbClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_proxy/client.rb

Overview

Get DRbClient

Constant Summary collapse

@@logger =
Logger.new(STDOUT)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ipObject

Returns the value of attribute ip.



180
181
182
# File 'lib/ruby_proxy/client.rb', line 180

def ip
  @ip
end

.portObject

Returns the value of attribute port.



180
181
182
# File 'lib/ruby_proxy/client.rb', line 180

def port
  @port
end

Class Method Details

.add_load_path(path) ⇒ Object



194
195
196
197
# File 'lib/ruby_proxy/client.rb', line 194

def add_load_path(path)
  #path = File.expand_path(path)
  client.add_load_path(path)
end

.alive?Boolean

Returns:

  • (Boolean)


173
174
175
176
177
178
# File 'lib/ruby_proxy/client.rb', line 173

def alive?
  @client.respond_to?("any_thing")
  true
rescue DRb::DRbConnError
  false
end

.clientObject



162
163
164
165
166
167
168
169
170
171
# File 'lib/ruby_proxy/client.rb', line 162

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_exitObject



246
247
248
249
250
251
# File 'lib/ruby_proxy/client.rb', line 246

def do_at_exit
  at_exit do
    @@logger.info "try to stop service"
    stop_service
  end
end

.proxy_global_get(arg) ⇒ Object



186
187
188
# File 'lib/ruby_proxy/client.rb', line 186

def proxy_global_get(arg)
	client.proxy_global_get(arg)
end

.proxy_global_set(arg, var) ⇒ Object



190
191
192
# File 'lib/ruby_proxy/client.rb', line 190

def proxy_global_set(arg,var)
	client.proxy_global_set(arg,var)
end

.proxy_load(file) ⇒ Object



182
183
184
# File 'lib/ruby_proxy/client.rb', line 182

def proxy_load(file)
  client.proxy_load(file)
end

.start_commandObject



214
215
216
217
218
# File 'lib/ruby_proxy/client.rb', line 214

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) ⇒ Object

not use it later



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/ruby_proxy/client.rb', line 200

def start_service(t=10)
  message = nil
  @service_log = nil
  @@logger.info "start ruby proxy server..."
  @@logger.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) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/ruby_proxy/client.rb', line 220

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
  @@logger.debug "service not start,stop fail!"
  @@logger.debug "#{$!}"
ensure
  @client = nil
end

.wait_until_server_start_time(t) ⇒ Object

Raises:

  • (RuntimeError)


232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/ruby_proxy/client.rb', line 232

def wait_until_server_start_time(t)
  t.times do |tt|
    begin
      #~ raise CannotStartServer, "" unless @server_thread.alive?
      TCPSocket.new(Config.ip,Config.port)
      @@logger.info "server is starting"
      return true
    rescue Exception
      sleep 1
    end
  end
  raise RuntimeError,"start drbserver fail"
end