Sha256: bb35be9da12a136599774865d8fae64f6bc314f10d7353379f101f0dae6e9801

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

Contents

java_import org.zeromq.ZMsg

require 'zoomq/handler'

module ZooMQ
  class Server
    class RequestHandler < Handler
      def handle(zloop, poller, worker)
        @server = worker.server
        origin, msg = recv_msg(poller.socket)
        result = handle_msg(msg)
        result.wrap(origin)
        result.send(poller.socket)
        return 0
      end

      def recv_msg(socket)
        msg = ZMsg.recvMsg(socket)
        [msg.unwrap, msg]
      end

      def handle_msg(msg)
        cls = String.from_java_bytes(msg.pop.data).constantize
        request = cls.parse(String.from_java_bytes(msg.pop.data))
        handle_request(request)
      end

      def handle_request(request)
        result = request.handle(@server)
        ZMsg.new_string_msg(result.class.to_s, result.to_s)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zoomq-0.1.1 lib/zoomq/server/request_handler.rb
zoomq-0.1.0 lib/zoomq/server/request_handler.rb