Sha256: 8208d2b92b03514b6ef9d04d322073fd0a640a09488e1350d7dbed0bb6313829

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'protobuf'
require 'protobuf/logging'
require 'protobuf/rpc/rpc.pb'
require 'protobuf/rpc/buffer'
require 'protobuf/rpc/env'
require 'protobuf/rpc/error'
require 'protobuf/rpc/middleware'
require 'protobuf/rpc/service_dispatcher'

module Protobuf
  module Rpc
    module Server
      def gc_pause
        ::GC.disable if ::Protobuf.gc_pause_server_request?

        yield

        ::GC.enable if ::Protobuf.gc_pause_server_request?
      end

      # Invoke the service method dictated by the proto wrapper request object
      #
      def handle_request(request_data, parent_env = nil)
        # Create an env object that holds different parts of the environment and
        # is available to all of the middlewares
        env = Env.new('encoded_request' => request_data,
                      'log_signature' => log_signature,
                      'parent_env' => parent_env)

        # Invoke the middleware stack, the last of which is the service dispatcher
        env = Rpc.middleware.call(env)

        env.encoded_response
      end

      def log_signature
        @_log_signature ||= "[server-#{self.class.name}]"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
protobuffy-4.0.1 lib/protobuf/rpc/server.rb
protobuffy-4.0.0 lib/protobuf/rpc/server.rb