lib/aggro.rb in aggro-0.0.3 vs lib/aggro.rb in aggro-0.0.4

- old
+ new

@@ -4,13 +4,13 @@ require 'active_support/core_ext/hash/keys' require 'concurrent' require 'consistent_hashing' require 'invokr' require 'fileutils' -require 'msgpack' -require 'object-stream' +require 'uri' require 'yaml' +require 'zero_mq' # Private: Define methods to protect handlers from code reloading. module Aggro module_function @@ -29,13 +29,13 @@ def step_handlers @step_handlers ||= Hash.new { |hash, key| hash[key] = {} } end end -require 'aggro/abstract_store' require 'aggro/attribute_dsl' require 'aggro/event_dsl' +require 'aggro/logging' require 'aggro/message/ask' require 'aggro/message/command' require 'aggro/message/create_aggregate' require 'aggro/message/endpoint' @@ -45,10 +45,11 @@ require 'aggro/message/invalid_target' require 'aggro/message/ok' require 'aggro/message/publisher_endpoint_inquiry' require 'aggro/message/query' require 'aggro/message/result' +require 'aggro/message/server_error' require 'aggro/message/start_saga' require 'aggro/message/unhandled_operation' require 'aggro/message/unknown_operation' require 'aggro/handler/command' @@ -56,16 +57,18 @@ require 'aggro/handler/get_events' require 'aggro/handler/query' require 'aggro/handler/start_saga' require 'aggro/transform/boolean' +require 'aggro/transform/date' require 'aggro/transform/email' require 'aggro/transform/id' require 'aggro/transform/integer' require 'aggro/transform/money' require 'aggro/transform/noop' require 'aggro/transform/string' +require 'aggro/transform/time' require 'aggro/transform/time_interval' require 'aggro/aggregate' require 'aggro/aggregate_ref' require 'aggro/binding_dsl' @@ -79,23 +82,24 @@ require 'aggro/event_proxy' require 'aggro/event_serializer' require 'aggro/file_store' require 'aggro/local_node' require 'aggro/locator' +require 'aggro/marshal_stream' require 'aggro/message_parser' require 'aggro/message_router' -require 'aggro/nanomsg_transport' require 'aggro/node' require 'aggro/node_list' require 'aggro/projection' require 'aggro/query' require 'aggro/saga' require 'aggro/saga_runner' require 'aggro/saga_status' require 'aggro/server' require 'aggro/subscriber' require 'aggro/subscription' +require 'aggro/zeromq_transport' # Public: Module for namespacing and configuration methods. module Aggro ClientNode = Struct.new(:id) Event = Struct.new(:name, :occured_at, :details) @@ -110,10 +114,11 @@ .each_with_object({}) { |m, h| h.merge! m::TYPE_CODE => m } .freeze class << self attr_writer :data_dir + attr_writer :logger attr_writer :port attr_writer :publisher_port attr_writer :transport end @@ -157,10 +162,14 @@ else @local_node ||= ClientNode.new(SecureRandom.uuid) end end + def logger + @logger ||= -> (_level, _progname, _message = nil, &_block) {} + end + 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) } @@ -180,18 +189,27 @@ def reset @cluster_config = nil @event_bus.shutdown if @event_bus @event_bus = nil @local_node = nil - @node_list = nil + reset_clients && @node_list = nil @port = nil - @publisher = nil @publisher_port = nil + @server.stop if @server @server = nil @store = nil end + def reset_clients + return unless @node_list + + @node_list.nodes + .select { |node| node.is_a? Node } + .map(&:client) + .each(&:disconnect!) + end + def server return unless cluster_config.server_node? @server ||= Server.new(local_node.endpoint, local_node.publisher_endpoint) end @@ -199,8 +217,8 @@ def store @store ||= FileStore.new(data_dir) end def transport - @transport ||= NanomsgTransport + @transport ||= ZeroMQTransport end end