lib/instrumental/agent.rb in instrumental_agent-0.9.0 vs lib/instrumental/agent.rb in instrumental_agent-0.9.1
- old
+ new
@@ -1,14 +1,31 @@
require 'instrumental/rack/middleware'
require 'instrumental/version'
require 'logger'
require 'thread'
require 'socket'
-if RUBY_VERSION < "1.9"
- require 'system_timer'
+if RUBY_VERSION < "1.9" && RUBY_PLATFORM != "java"
+ begin
+ gem 'system_timer'
+ require 'system_timer'
+ InstrumentalTimeout = SystemTimer
+ rescue Exception => e
+ puts <<-EOMSG
+WARNING:: You do not currently have system_timer installed.
+It is strongly advised that you install this gem when using
+instrumental_agent with Ruby 1.8.x. You can install it in
+your Gemfile via:
+gem 'system_timer'
+or manually via:
+gem install system_timer
+ EOMSG
+ require 'timeout'
+ InstrumentalTimeout = Timeout
+ end
else
require 'timeout'
+ InstrumentalTimeout = Timeout
end
# Sets up a connection to the collector.
#
@@ -188,11 +205,10 @@
end
private
def with_timeout(time, &block)
- tmr_klass = RUBY_VERSION < "1.9" ? SystemTimer : Timeout
- tmr_klass.timeout(time) { yield }
+ InstrumentalTimeout.timeout(time) { yield }
end
def valid_note?(note)
note !~ /[\n\r]/
end