Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4 from sishen/master.

Make ruby_bosh JRuby compatible. check for SystemTimer/Timeout
  • Loading branch information...
commit 2998e9ec2a8aec0f39a329cc507b0efc0eed5081 2 parents 211fe31 + f2655c6
@skyfallsin authored
Showing with 37 additions and 18 deletions.
  1. +36 −14 lib/ruby_bosh.rb
  2. +1 −4 ruby_bosh.gemspec
View
50 lib/ruby_bosh.rb
@@ -3,8 +3,6 @@
require 'rexml/document'
require 'base64'
require 'hpricot'
-require 'timeout'
-require 'system_timer'
class RubyBOSH
BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
@@ -133,25 +131,49 @@ def parse(_response)
_response
end
- def deliver(xml)
- SystemTimer.timeout(@timeout) do
- send(xml)
- recv(RestClient.post(@service_url, xml, @headers))
+ begin
+ require 'system_timer'
+ def deliver(xml)
+ SystemTimer.timeout(@timeout) do
+ send(xml)
+ recv(RestClient.post(@service_url, xml, @headers))
+ end
+ rescue ::Timeout::Error => e
+ raise RubyBOSH::Timeout, e.message
+ rescue Errno::ECONNREFUSED => e
+ raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
+ rescue Exception => e
+ raise RubyBOSH::Error, e.message
+ end
+ rescue LoadError
+ warn "WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang." unless RUBY_VERSION >= "1.9" || RUBY_PLATFORM =~ /java/
+
+ require "timeout"
+ def deliver(xml)
+ Timeout.timeout(@timeout) do
+ send(xml)
+ recv(RestClient.post(@service_url, xml, @headers))
+ end
+ rescue ::Timeout::Error => e
+ raise RubyBOSH::Timeout, e.message
+ rescue Errno::ECONNREFUSED => e
+ raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
+ rescue Exception => e
+ raise RubyBOSH::Error, e.message
end
- rescue ::Timeout::Error => e
- raise RubyBOSH::Timeout, e.message
- rescue Errno::ECONNREFUSED => e
- raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
- rescue Exception => e
- raise RubyBOSH::Error, e.message
end
def send(msg)
- puts("Ruby-BOSH - SEND\n#{msg}") if @@logging; msg
+ puts("Ruby-BOSH - SEND\n[#{now}]: #{msg}") if @@logging; msg
end
def recv(msg)
- puts("Ruby-BOSH - RECV\n#{msg}") if @logging; msg
+ puts("Ruby-BOSH - RECV\n[#{now}]: #{msg}") if @logging; msg
+ end
+
+ private
+ def now
+ Time.now.strftime("%a %b %d %H:%M:%S %Y")
end
end
View
5 ruby_bosh.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{ruby_bosh}
- s.version = "0.6.0"
+ s.version = "0.6.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Pradeep Elankumaran"]
@@ -45,18 +45,15 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<builder>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
- s.add_runtime_dependency(%q<SystemTimer>, [">= 0"])
else
s.add_dependency(%q<builder>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<hpricot>, [">= 0"])
- s.add_dependency(%q<SystemTimer>, [">= 0"])
end
else
s.add_dependency(%q<builder>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<hpricot>, [">= 0"])
- s.add_dependency(%q<SystemTimer>, [">= 0"])
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.