Class: RubyProxy::DRbClient
- Inherits:
-
Object
- Object
- RubyProxy::DRbClient
- Defined in:
- lib/ruby_proxy/client.rb
Constant Summary collapse
- @@logger =
Logger.new(STDOUT)
Class Attribute Summary collapse
-
.ip ⇒ Object
Returns the value of attribute ip.
-
.port ⇒ Object
Returns the value of attribute port.
Class Method Summary collapse
- .alive? ⇒ Boolean
- .client ⇒ Object
- .proxy_load(dir_or_file) ⇒ Object
- .start_service(t = 5) ⇒ Object
- .stop_service(t = 5) ⇒ Object
- .wait_until_server_start_time(t) ⇒ Object
Class Attribute Details
.ip ⇒ Object
Returns the value of attribute ip.
162 163 164 |
# File 'lib/ruby_proxy/client.rb', line 162 def ip @ip end |
.port ⇒ Object
Returns the value of attribute port.
162 163 164 |
# File 'lib/ruby_proxy/client.rb', line 162 def port @port end |
Class Method Details
.alive? ⇒ Boolean
155 156 157 158 159 160 |
# File 'lib/ruby_proxy/client.rb', line 155 def alive? @client.respond_to?("any_thing") @client rescue DRb::DRbConnError raise end |
.client ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ruby_proxy/client.rb', line 142 def client begin stop_service if @client.nil? @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@port}") alive? @client rescue Exception start_service @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@port}") @client end end |
.proxy_load(dir_or_file) ⇒ Object
164 165 166 |
# File 'lib/ruby_proxy/client.rb', line 164 def proxy_load(dir_or_file) client.proxy_load(dir_or_file) end |
.start_service(t = 5) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ruby_proxy/client.rb', line 168 def start_service(t=5) = nil @start_service_log_path = File.join(File.dirname(__FILE__),'start_service.log') server_thread = Thread.new do @@logger.info "start jruby proxy server..." org_path = Dir.pwd Dir.chdir(File.join(File.dirname(__FILE__),'..')) do # we can start jruby proxy or ruby # just change here command temp = ENV["RUBYOPT"] ENV["RUBYOPT"] = "-rubygems" system("start /I /B jruby -J-Dfile.encoding=UTF-8 ruby_proxy/server.rb #{@ip} #{@port} \"#{org_path}\" ") #> #{@start_service_log_path} 2>&1") ENV["RUBYOPT"] = temp end end wait_until_server_start_time(t) end |
.stop_service(t = 5) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ruby_proxy/client.rb', line 187 def stop_service(t=5) TCPSocket.new(@ip,@port) @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@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
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ruby_proxy/client.rb', line 199 def wait_until_server_start_time(t) t.times do |tt| begin TCPSocket.new(@ip,@port) @@logger.info "server is starting" return true rescue Exception sleep 1 end end raise RuntimeError,"start drbserver fail, reason: #{File.read(@start_service_log_path) rescue nil}" end |