Class: Mimi::Messaging::Adapters::Memory

Inherits:
Base
  • Object
show all
Defined in:
lib/mimi/messaging/adapters/memory.rb

Overview

A Memory is an in-memory implementation of a messaging adapter.

All message dispatching happens within a single thread, the same as the caller’s, so all ivocations are synchronous.

The Memory purpose is only to use in tests and for the higher abstractions development.

Instance Attribute Summary

Attributes inherited from Base

#serializer

Instance Method Summary collapse

Methods inherited from Base

#initialize, register_adapter_name, #register_message_serializer

Constructor Details

This class inherits a constructor from Mimi::Messaging::Adapters::Base

Instance Method Details

#command(target, message, opts = {}) ⇒ Object

Sends COMMAND to target

Parameters:

Raises:

  • (ArgumentError)


32
33
34
35
36
# File 'lib/mimi/messaging/adapters/memory.rb', line 32

def command(target, message, opts = {})
  raise ArgumentError, "Message is expected" unless message.is_a?(Mimi::Messaging::Message)
  dispatch_command(target, message, opts)
  nil
end

#event(target, message, opts = {}) ⇒ Object

Sends EVENT to target

Parameters:

Raises:

  • (ArgumentError)


56
57
58
59
# File 'lib/mimi/messaging/adapters/memory.rb', line 56

def event(target, message, opts = {})
  raise ArgumentError, "Message is expected" unless message.is_a?(Mimi::Messaging::Message)
  dispatch_event(target, message, opts)
end

#query(target, message, opts = {}) ⇒ Object

Sends QUERY to target

Parameters:

Raises:

  • (ArgumentError)


44
45
46
47
48
# File 'lib/mimi/messaging/adapters/memory.rb', line 44

def query(target, message, opts = {})
  raise ArgumentError, "Message is expected" unless message.is_a?(Mimi::Messaging::Message)
  response_serialized = dispatch_query(target, message, opts)
  deserialize(response_serialized)
end

#startObject



20
21
# File 'lib/mimi/messaging/adapters/memory.rb', line 20

def start
end

#start_event_processor(topic_name, processor, _opts = {}) ⇒ Object



67
68
69
70
71
# File 'lib/mimi/messaging/adapters/memory.rb', line 67

def start_event_processor(topic_name, processor, _opts = {})
  super
  event_processors[topic_name] ||= []
  event_processors[topic_name] << processor
end

#start_event_processor_with_queue(topic_name, queue_name, processor, opts = {}) ⇒ Object



73
74
75
76
77
78
# File 'lib/mimi/messaging/adapters/memory.rb', line 73

def start_event_processor_with_queue(topic_name, queue_name, processor, opts = {})
  super
  event_processors_with_queue[topic_name] ||= {}
  event_processors_with_queue[topic_name][queue_name] ||= []
  event_processors_with_queue[topic_name][queue_name] << processor
end

#start_request_processor(queue_name, processor, _opts = {}) ⇒ Object



61
62
63
64
65
# File 'lib/mimi/messaging/adapters/memory.rb', line 61

def start_request_processor(queue_name, processor, _opts = {})
  super
  request_processors[queue_name] ||= []
  request_processors[queue_name] << processor
end

#stopObject



23
24
# File 'lib/mimi/messaging/adapters/memory.rb', line 23

def stop
end

#stop_all_processorsObject



80
81
82
83
84
# File 'lib/mimi/messaging/adapters/memory.rb', line 80

def stop_all_processors
  @request_processors = {}
  @event_processors = {}
  @event_processors_with_queue = {}
end