Sha256: 8b7bca3ffe8204aa74be4180e66ce4bc94f25c49bc5f47676f55ba3bcfbb08df

Contents?: true

Size: 897 Bytes

Versions: 16

Compression:

Stored size: 897 Bytes

Contents

module Appsignal
  class Pipe
    attr_reader :reader, :writer, :listener

    def initialize
      Appsignal.logger.debug "Initializing pipe in #{$$}"
      @reader, @writer = IO.pipe
      @listener = Thread.new do
        loop do
          Appsignal.agent.enqueue(Marshal::load(@reader))
        end
      end
      @listening = true
    end

    def write(transaction)
      Marshal::dump(transaction, @writer)
    rescue IOError
      Appsignal.logger.debug "Broken pipe in #{$$}"
      Appsignal.agent.shutdown
    end

    def stop_listening!
      Thread.kill(@listener)
      @reader.close unless @reader.closed?
      @listening = false
    end

    def listening?
      !! @listening
    end

    class << self
      def init
        Thread.current[:appsignal_pipe] = Appsignal::Pipe.new
      end

      def current
        Thread.current[:appsignal_pipe]
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
appsignal-0.9.1 lib/appsignal/pipe.rb
appsignal-0.9.0 lib/appsignal/pipe.rb
appsignal-0.8.15 lib/appsignal/pipe.rb
appsignal-0.9.0.beta.1 lib/appsignal/pipe.rb
appsignal-0.9.0.alpha.1 lib/appsignal/pipe.rb
appsignal-0.8.14 lib/appsignal/pipe.rb
appsignal-0.8.13 lib/appsignal/pipe.rb
appsignal-0.8.12 lib/appsignal/pipe.rb
appsignal-0.8.11 lib/appsignal/pipe.rb
appsignal-0.8.10 lib/appsignal/pipe.rb
appsignal-0.8.8 lib/appsignal/pipe.rb
appsignal-0.8.7 lib/appsignal/pipe.rb
appsignal-0.8.7.alpha.1 lib/appsignal/pipe.rb
appsignal-0.8.6 lib/appsignal/pipe.rb
appsignal-0.8.6.beta.1 lib/appsignal/pipe.rb
appsignal-0.8.6.beta.0 lib/appsignal/pipe.rb