Sha256: 478e593d62f28f7b549bdd86f9bc7bdf19a0b48bf532e73af535d33188bf8930

Contents?: true

Size: 850 Bytes

Versions: 12

Compression:

Stored size: 850 Bytes

Contents

module GELF
  module Transport
    class UDP
      attr_accessor :addresses

      def initialize(addresses)
        @addresses = addresses
      end

      def send_datagrams(datagrams)
        socket = get_socket
        idx = get_address_index

        host, port = @addresses[idx]
        set_address_index((idx + 1) % @addresses.length)
        datagrams.each do |datagram|
          socket.send(datagram, 0, host, port)
        end
      end

      def close
        socket = get_socket
        socket.close if socket
      end

      private

      def get_socket
        Thread.current[:gelf_udp_socket] ||= UDPSocket.open
      end

      def get_address_index
        Thread.current[:gelf_udp_address_idx] ||= 0
      end

      def set_address_index(value)
        Thread.current[:gelf_udp_address_idx] = value
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
gelf_redux-4.1.0 lib/gelf/transport/udp.rb
gelf_redux-4.0.1 lib/gelf/transport/udp.rb
gelf_redux-4.0.0 lib/gelf/transport/udp.rb
gelf_redux-3.2.2 lib/gelf/transport/udp.rb
gelf_redux-3.1.2 lib/gelf/transport/udp.rb
gelf_redux-3.2.1 lib/gelf/transport/udp.rb
gelf_redux-3.1.1 lib/gelf/transport/udp.rb
gelf.fitterpen-3.1.1 lib/gelf/transport/udp.rb
gelf.fitterpen-3.1.0 lib/gelf/transport/udp.rb
gelf-3.1.0 lib/gelf/transport/udp.rb
gelf-3.1.0.pre.rc.1 lib/gelf/transport/udp.rb
gelf-3.0.0 lib/gelf/transport/udp.rb