Class: Hoss::Transport::Connection::ProxyPipe::Write Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/hoss/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/hoss/transport/connection/proxy_pipe.rb', line 43

def initialize(io, compress: true)
  @io = io
  @compress = compress
  @bytes_sent = Concurrent::AtomicFixnum.new(0)
  @config = Hoss.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/hoss/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/hoss/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.



82
83
84
# File 'lib/hoss/transport/connection/proxy_pipe.rb', line 82

def bytes_sent
  @bytes_sent.value
end

#close(reason = nil) ⇒ 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.



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

def close(reason = nil)
  debug("Closing writer with reason #{reason}")
  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)


70
71
72
# File 'lib/hoss/transport/connection/proxy_pipe.rb', line 70

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/hoss/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.



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

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