class TingYun::Support::Serialize::JsonMarshaller

Marshal collector protocol with JSON when available

Constants

OK_YAJL_VERSION

Public Class Methods

human_readable?() click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 67
def self.human_readable?
  true # for some definitions of 'human'
end
is_supported?() click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 63
def self.is_supported?
  JSONWrapper.usable_for_collector_serialization?
end
new() click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 14
def initialize
  TingYun::Agent.logger.debug "Using JSON marshaller (#{JSONWrapper.backend_name})"
  unless self.class.is_supported?
    TingYun::Agent.logger.warn "The JSON marshaller in use (#{JSONWrapper.backend_name}) is not recommended. Ensure the 'json' gem is available in your application for better performance."
  end
  warn_for_yajl
end

Public Instance Methods

dump(ruby, opts={}) click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 35
def dump(ruby, opts={})
  prepared = prepare(ruby, opts)

  if opts[:skip_normalization]
    normalize_encodings = false
  else
    normalize_encodings = TingYun::Agent.config[:normalize_json_string_encodings]
  end

  JSONWrapper.dump(prepared, :normalize => normalize_encodings)
end
format() click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 59
def format
  'json'
end
load(data) click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 47
def load(data)
  if data.nil? || data.empty?
    ::TingYun::Agent.logger.error "Empty JSON response from collector: '#{data.inspect}'"
    return nil
  end

  return_value(JSONWrapper.load(data))
rescue => e
  ::TingYun::Agent.logger.debug "#{e.class.name} : #{e.message} encountered loading collector response: #{data}"
  raise
end
warn_for_yajl() click to toggle source
# File lib/ting_yun/support/serialize/json_marshaller.rb, line 24
def warn_for_yajl
  if defined?(::Yajl)
    require 'yajl/version'
    if VersionNumber.new(::Yajl::VERSION) < OK_YAJL_VERSION
      ::TingYun::Agent.logger.warn "Detected yajl-ruby version #{::Yajl::VERSION} which can cause segfaults with TingYun_rpm's thread profiling features. We strongly recommend you upgrade to the latest yajl-ruby version available."
    end
  end
rescue => err
  ::TingYun::Agent.logger.warn "Failed trying to watch for problematic yajl-ruby version.", err
end