class Aggro::Server

Public: Binds a transport endpoint and handles incoming messages.

Constants

HANDLERS
RAW_HANDLER

Public Class Methods

new(endpoint, publisher_endpoint) click to toggle source
# File lib/aggro/server.rb, line 16
def initialize(endpoint, publisher_endpoint)
  @endpoint = endpoint
  @publisher_endpoint = publisher_endpoint

  @transport_server = Aggro.transport.server endpoint, method(RAW_HANDLER)
  @transport_publisher = Aggro.transport.publisher publisher_endpoint
end

Public Instance Methods

bind() click to toggle source
# File lib/aggro/server.rb, line 24
def bind
  @transport_server.start
  @transport_publisher.open_socket
end
handle_message(message) click to toggle source
# File lib/aggro/server.rb, line 29
def handle_message(message)
  message_router.route message
end
publish(message) click to toggle source
# File lib/aggro/server.rb, line 33
def publish(message)
  @transport_publisher.publish message
end
stop() click to toggle source
# File lib/aggro/server.rb, line 37
def stop
  @transport_publisher.close_socket
  @transport_server.stop
end

Private Instance Methods

handle_command(message) click to toggle source
# File lib/aggro/server.rb, line 44
def handle_command(message)
  Handler::Command.new(message, self).call
end
handle_create(message) click to toggle source
# File lib/aggro/server.rb, line 48
def handle_create(message)
  Handler::CreateAggregate.new(message, self).call
end
handle_get_events(message) click to toggle source
# File lib/aggro/server.rb, line 52
def handle_get_events(message)
  Handler::GetEvents.new(message, self).call
end
handle_heartbeat(_message) click to toggle source
# File lib/aggro/server.rb, line 56
def handle_heartbeat(_message)
  Message::OK.new
end
handle_publisher_endpoint_inquiry(_message) click to toggle source
# File lib/aggro/server.rb, line 60
def handle_publisher_endpoint_inquiry(_message)
  Message::Endpoint.new @publisher_endpoint
end
handle_query(message) click to toggle source
# File lib/aggro/server.rb, line 64
def handle_query(message)
  Handler::Query.new(message, self).call
end
handle_raw(raw) click to toggle source
# File lib/aggro/server.rb, line 68
def handle_raw(raw)
  handle_message MessageParser.parse raw
end
handle_start_saga(message) click to toggle source
# File lib/aggro/server.rb, line 72
def handle_start_saga(message)
  Handler::StartSaga.new(message, self).call
end
message_router() click to toggle source
# File lib/aggro/server.rb, line 76
def message_router
  @message_router ||= begin
    MessageRouter.new.tap do |router|
      HANDLERS.each { |type, sym| router.attach_handler type, method(sym) }
    end
  end
end