Class: WindUp::Router::FirstAvailable

Inherits:
Base
  • Object
show all
Defined in:
lib/wind_up/routers.rb

Overview

The strategy employed is similar to a ScatterGatherFirstCompleted router in Akka, but wrapping messages in the ForwardedCall structure so computation is only completed once.

Instance Method Summary collapse

Methods inherited from Base

#add_subscriber, #broadcast, #initialize, #remove_subscriber, #send_message, #subscribers

Constructor Details

This class inherits a constructor from WindUp::Router::Base

Instance Method Details

#<<(msg) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/wind_up/routers.rb', line 112

def <<(msg)
  @mutex.lock
  begin
    mailbox << msg
    send_message(subscribers, WindUp::ForwardedCall.new(mailbox))
  ensure
    @mutex.unlock rescue nil
  end
end

#mailboxObject



108
109
110
# File 'lib/wind_up/routers.rb', line 108

def mailbox
  @mailbox ||= Celluloid::Mailbox.new
end

#shutdownObject



122
123
124
# File 'lib/wind_up/routers.rb', line 122

def shutdown
  mailbox.shutdown
end