Sha256: bdc710008be077d42a6556489dd41bf142e7e9580bf1e116cc42818d1084c3ea

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

module IRuby
  module SessionAdapter
    class CztopAdapter < BaseAdapter
      def self.load_requirements
        require 'cztop'
      end

      def send(sock, data)
        sock << data
      end

      def recv(sock)
        sock.receive
      end

      def heartbeat_loop(sock)
        loop do
          message = sock.receive
          sock << message
        end
      end

      private

      def socket_type_class(type_symbol)
        case type_symbol
        when :ROUTER, :PUB, :REP
          CZTop::Socket.const_get(type_symbol)
        else
          if CZTop::Socket.const_defined?(type_symbol)
            raise ArgumentError, "Unsupported ZMQ socket type: #{type_symbol}"
          else
            raise ArgumentError, "Invalid ZMQ socket type: #{type_symbol}"
          end
        end
      end

      def make_socket(type_symbol, protocol, host, port)
        uri = "#{protocol}://#{host}:#{port}"
        socket_class = socket_type_class(type_symbol)
        socket_class.new(uri)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iruby-0.8.0 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.7.4 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.7.3 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.7.2 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.7.1 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.7.0 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.6.1 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.6.0 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.5.0 lib/iruby/session_adapter/cztop_adapter.rb
iruby-0.4.0 lib/iruby/session_adapter/cztop_adapter.rb