Module: Aggro

Defined in:
lib/aggro.rb,
lib/aggro.rb,
lib/aggro/node.rb,
lib/aggro/saga.rb,
lib/aggro/query.rb,
lib/aggro/client.rb,
lib/aggro/server.rb,
lib/aggro/channel.rb,
lib/aggro/command.rb,
lib/aggro/locator.rb,
lib/aggro/logging.rb,
lib/aggro/version.rb,
lib/aggro/aggregate.rb,
lib/aggro/event_bus.rb,
lib/aggro/event_dsl.rb,
lib/aggro/node_list.rb,
lib/aggro/file_store.rb,
lib/aggro/local_node.rb,
lib/aggro/message/ok.rb,
lib/aggro/projection.rb,
lib/aggro/subscriber.rb,
lib/aggro/binding_dsl.rb,
lib/aggro/event_proxy.rb,
lib/aggro/message/ask.rb,
lib/aggro/saga_runner.rb,
lib/aggro/saga_status.rb,
lib/aggro/block_helper.rb,
lib/aggro/subscription.rb,
lib/aggro/transform/id.rb,
lib/aggro/aggregate_ref.rb,
lib/aggro/attribute_dsl.rb,
lib/aggro/handler/query.rb,
lib/aggro/message/query.rb,
lib/aggro/cluster_config.rb,
lib/aggro/message/events.rb,
lib/aggro/message/result.rb,
lib/aggro/message_parser.rb,
lib/aggro/message_router.rb,
lib/aggro/transform/date.rb,
lib/aggro/transform/noop.rb,
lib/aggro/transform/time.rb,
lib/aggro/handler/command.rb,
lib/aggro/message/command.rb,
lib/aggro/transform/email.rb,
lib/aggro/transform/money.rb,
lib/aggro/concurrent_actor.rb,
lib/aggro/event_serializer.rb,
lib/aggro/message/endpoint.rb,
lib/aggro/transform/string.rb,
lib/aggro/zeromq_transport.rb,
lib/aggro/file_store/reader.rb,
lib/aggro/file_store/writer.rb,
lib/aggro/message/heartbeat.rb,
lib/aggro/nanomsg_transport.rb,
lib/aggro/transform/boolean.rb,
lib/aggro/transform/integer.rb,
lib/aggro/handler/get_events.rb,
lib/aggro/handler/start_saga.rb,
lib/aggro/message/get_events.rb,
lib/aggro/message/start_saga.rb,
lib/aggro/message/server_error.rb,
lib/aggro/message/invalid_target.rb,
lib/aggro/saga_runner/start_saga.rb,
lib/aggro/transform/time_interval.rb,
lib/aggro/zeromq_transport/client.rb,
lib/aggro/zeromq_transport/server.rb,
lib/aggro/handler/create_aggregate.rb,
lib/aggro/message/create_aggregate.rb,
lib/aggro/message/unknown_operation.rb,
lib/aggro/zeromq_transport/publisher.rb,
lib/aggro/message/unhandled_operation.rb,
lib/aggro/zeromq_transport/subscriber.rb,
lib/aggro/message/publisher_endpoint_inquiry.rb

Overview

Public: Module for namespacing and configuration methods.

Defined Under Namespace

Modules: Aggregate, AttributeDSL, BindingDSL, BlockHelper, Command, EventDSL, EventSerializer, Handler, Logging, Message, MessageParser, NanomsgTransport, Projection, Query, Saga, Transform, ZeroMQTransport Classes: AggregateRef, Channel, Client, ClientNode, ClusterConfig, ConcurrentActor, Event, EventArgument, EventBus, EventProxy, EventStream, FileStore, LocalNode, Locator, MessageRouter, Node, NodeList, QueryError, SagaRunner, SagaStatus, Server, Subscriber, Subscription

Constant Summary collapse

MESSAGE_TYPES =
Message
.constants
.map { |sym| Message.const_get sym }
.select { |m| m.const_defined? 'TYPE_CODE' }
.each_with_object({}) { |m, h| h.merge! m::TYPE_CODE => m }
.freeze
VERSION =
'0.0.4'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.data_dirObject



147
148
149
150
151
152
153
# File 'lib/aggro.rb', line 147

def data_dir
  @data_dir ||= begin
    ENV.fetch('AGGRO_DIR') { './tmp/aggro' }.tap do |dir|
      FileUtils.mkdir_p dir
    end
  end
end

.loggerObject



167
168
169
# File 'lib/aggro.rb', line 167

def logger
  @logger ||= -> (_level, _progname, _message = nil, &_block) {}
end

.portObject



181
182
183
# File 'lib/aggro.rb', line 181

def port
  @port ||= ENV.fetch('PORT') { 5000 }.to_i
end

.publisher_portObject



185
186
187
# File 'lib/aggro.rb', line 185

def publisher_port
  @publisher_port ||= ENV.fetch('PUBLISHER_PORT') { 6000 }.to_i
end

.transportObject



221
222
223
# File 'lib/aggro.rb', line 221

def transport
  @transport ||= ZeroMQTransport
end

Class Method Details

.channelsObject



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/aggro.rb', line 127

def channels
  if cluster_config.server_node?
    @channels ||= begin
      Aggro.store.registry.reduce({}) do |channels, (id, type)|
        channels.merge id => Channel.new(id, type)
      end
    end
  else
    @channels ||= {}
  end
end

.class_attributesObject



17
18
19
# File 'lib/aggro.rb', line 17

def class_attributes
  @class_attributes ||= Hash.new { |hash, key| hash[key] = {} }
end

.cluster_configObject



139
140
141
# File 'lib/aggro.rb', line 139

def cluster_config
  @cluster_config ||= ClusterConfig.new cluster_config_path
end

.cluster_config_pathObject



143
144
145
# File 'lib/aggro.rb', line 143

def cluster_config_path
  [data_dir, 'cluster.yml'].join('/')
end

.command_handlersObject



21
22
23
# File 'lib/aggro.rb', line 21

def command_handlers
  @command_handlers ||= Hash.new { |hash, key| hash[key] = {} }
end

.event_busObject



155
156
157
# File 'lib/aggro.rb', line 155

def event_bus
  @event_bus ||= EventBus.new
end

.local_nodeObject



159
160
161
162
163
164
165
# File 'lib/aggro.rb', line 159

def local_node
  if cluster_config.server_node?
    @local_node ||= LocalNode.new(cluster_config.node_name)
  else
    @local_node ||= ClientNode.new(SecureRandom.uuid)
  end
end

.node_listObject



171
172
173
174
175
176
177
178
179
# File 'lib/aggro.rb', line 171

def node_list
  @node_list ||= begin
    NodeList.new.tap do |node_list|
      nodes = cluster_config.nodes
      nodes.each { |name, server| node_list.add Node.new(name, server) }
      node_list.add local_node if cluster_config.server_node?
    end
  end
end

.query_handlersObject



25
26
27
# File 'lib/aggro.rb', line 25

def query_handlers
  @query_handlers ||= Hash.new { |hash, key| hash[key] = {} }
end

.resetObject



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/aggro.rb', line 189

def reset
  @cluster_config = nil
  @event_bus.shutdown if @event_bus
  @event_bus = nil
  @local_node = nil
  reset_clients && @node_list = nil
  @port = nil
  @publisher_port = nil
  @server.stop if @server
  @server = nil
  @store = nil
end

.reset_clientsObject



202
203
204
205
206
207
208
209
# File 'lib/aggro.rb', line 202

def reset_clients
  return unless @node_list

  @node_list.nodes
    .select { |node| node.is_a? Node }
    .map(&:client)
    .each(&:disconnect!)
end

.serverObject



211
212
213
214
215
# File 'lib/aggro.rb', line 211

def server
  return unless cluster_config.server_node?

  @server ||= Server.new(local_node.endpoint, local_node.publisher_endpoint)
end

.step_handlersObject



29
30
31
# File 'lib/aggro.rb', line 29

def step_handlers
  @step_handlers ||= Hash.new { |hash, key| hash[key] = {} }
end

.storeObject



217
218
219
# File 'lib/aggro.rb', line 217

def store
  @store ||= FileStore.new(data_dir)
end