Class: Atatus::Transport::Connection::ProxyPipe::Write Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/atatus/transport/connection/proxy_pipe.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(io, compress: true) ⇒ Write

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Write.



43
44
45
46
47
48
49
50
51
52
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 43

def initialize(io, compress: true)
  @io = io
  @compress = compress
  @bytes_sent = Concurrent::AtomicFixnum.new(0)
  @config = Atatus.agent&.config # this is silly, fix Logging

  return unless compress
  enable_compression!
  ObjectSpace.define_finalizer(self, self.class.finalize(@io))
end

Instance Attribute Details

#ioObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 58

def io
  @io
end

Class Method Details

.finalize(io) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 54

def self.finalize(io)
  proc { io.close }
end

Instance Method Details

#bytes_sentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 81

def bytes_sent
  @bytes_sent.value
end

#closeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 65

def close
  io.close
end

#closed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


69
70
71
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 69

def closed?
  io.closed?
end

#enable_compression!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 60

def enable_compression!
  io.binmode
  @io = Zlib::GzipWriter.new(io)
end

#write(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
79
# File 'lib/atatus/transport/connection/proxy_pipe.rb', line 73

def write(str)
  io.puts(str).tap do
    @bytes_sent.update do |curr|
      @compress ? io.tell : curr + str.bytesize
    end
  end
end