Class: WsdlMapper::Runtime::AsyncHttpBackend

Inherits:
BackendBase
  • Object
show all
Includes:
Middlewares
Defined in:
lib/wsdl_mapper/runtime/async_http_backend.rb

Overview

Middleware Stack

Default Configuration

The default stack is composed of the following middlewares: Diagram

  1. message.factory: Middlewares::AsyncMessageFactory
  2. request.factory: Middlewares::AsyncRequestFactory
  3. dispatcher: Middlewares::AsyncDispatcher
  4. response.factory: Middlewares::AsyncResponseFactory

Instance Attribute Summary

Attributes inherited from BackendBase

#stack

Instance Method Summary (collapse)

Constructor Details

- (AsyncHttpBackend) initialize(connection: Faraday.new, executor: nil)

Returns a new instance of AsyncHttpBackend



25
26
27
28
29
30
31
32
33
# File 'lib/wsdl_mapper/runtime/async_http_backend.rb', line 25

def initialize(connection: Faraday.new, executor: nil)
  super()
  @executor = executor

  stack.add 'message.factory', AsyncMessageFactory.new
  stack.add 'request.factory', AsyncRequestFactory.new
  stack.add 'dispatcher', AsyncDispatcher.new(connection)
  stack.add 'response.factory', AsyncResponseFactory.new
end

Instance Method Details

- (AsyncHttpBackend) disable_logging

Disables logging by removing the logging middlewares from the stack. Returns self.

Returns:



47
48
49
50
51
# File 'lib/wsdl_mapper/runtime/async_http_backend.rb', line 47

def disable_logging
  stack.remove 'request.logger'
  stack.remove 'response.logger'
  self
end

- (Concurrent::Promise) dispatch(operation, *args)

Takes an operation and arguments, wraps them in a new Concurrent::Promise, passes them to the BackendBase#stack and returns the response promise.

Parameters:

Returns:

  • (Concurrent::Promise)

    The unscheduled response promise.



58
59
60
61
# File 'lib/wsdl_mapper/runtime/async_http_backend.rb', line 58

def dispatch(operation, *args)
  promise = Concurrent::Promise.new(executor: @executor) { args }
  dispatch_async operation, promise
end

- (Concurrent::Promise) dispatch_async(operation, promise)

Passes a promise to the stack and returns the response promise.

Parameters:

Returns:

  • (Concurrent::Promise)

    The unscheduled response promise.



67
68
69
# File 'lib/wsdl_mapper/runtime/async_http_backend.rb', line 67

def dispatch_async(operation, promise)
  stack.execute([operation, promise]).last
end

- (AsyncHttpBackend) enable_logging(logger = Logger.new(STDOUT), log_level: Logger::DEBUG)

Enables request and response logging. Returns self.

Parameters:

  • logger (Logger) (defaults to: Logger.new(STDOUT))

    Logger instance to use.

  • log_level (Logger::DEBUG, Logger::INFO, Logger::FATAL, Logger::ERROR, Logger::WARN)

Returns:



39
40
41
42
43
# File 'lib/wsdl_mapper/runtime/async_http_backend.rb', line 39

def enable_logging(logger = Logger.new(STDOUT), log_level: Logger::DEBUG)
  stack.after 'request.factory', 'request.logger', AsyncRequestLogger.new(logger, log_level: log_level)
  stack.before 'response.factory', 'response.logger', AsyncResponseLogger.new(logger, log_level: log_level)
  self
end