module LogjamAgent::Util
Constants
- BIG_ENDIAN
copied from amqp protocol gem (slightly modified)
- FIXNUM_MAX
we assume we're running on MRI ruby
- META_INFO_DEVICE_NUMBER
- META_INFO_TAG
- META_INFO_VERSION
- UINT64
Public Instance Methods
augment_connection_spec(spec, default_port)
click to toggle source
# File lib/logjam_agent/util.rb, line 61 def augment_connection_spec(spec, default_port) protocol, host, port = %r{\A(?:([^:]+)://)?([^:]+)(?::(\d+))?\z}.match(spec).captures protocol ||= "tcp" port ||= default_port if protocol == "inproc" # should only be used for integration tests "#{protocol}://#{host}" else "#{protocol}://#{host}:#{port}" end end
next_fixnum(i)
click to toggle source
# File lib/logjam_agent/util.rb, line 41 def next_fixnum(i) (i+=1) > FIXNUM_MAX ? 1 : i end
pack_info(n, compression_method = LogjamAgent.compression_method)
click to toggle source
# File lib/logjam_agent/util.rb, line 45 def pack_info(n, compression_method = LogjamAgent.compression_method) info = [META_INFO_TAG, compression_method, META_INFO_VERSION, META_INFO_DEVICE_NUMBER].pack("nCCN") info << pack_uint64_big_endian(zclock_time) info << pack_uint64_big_endian(n) end
pack_uint64_big_endian(uint64)
click to toggle source
# File lib/logjam_agent/util.rb, line 17 def pack_uint64_big_endian(uint64) [uint64].pack(UINT64) end
unpack_info(info)
click to toggle source
# File lib/logjam_agent/util.rb, line 51 def unpack_info(info) tag, compression_method, version, device = info[0..7].unpack("nCCN") zclock = unpack_uint64_big_endian(info[8..15]) secs = zclock / 1000 msecs = zclock % 1000 sent = Time.at(secs) + 1000.0/msecs sequence = unpack_uint64_big_endian(info[16..23]) [tag, compression_method, version, device, sent, sequence] end
unpack_uint64_big_endian(string)
click to toggle source
# File lib/logjam_agent/util.rb, line 21 def unpack_uint64_big_endian(string) string.unpack(UINT64) end
zclock_time(t = Time.now)
click to toggle source
# File lib/logjam_agent/util.rb, line 37 def zclock_time(t = Time.now) t.tv_sec*1000 + t.tv_usec/1000 end