class SourceGroup

This class is the container for the objects that will receive common method calls

It also manages the concurrency model to be used when performing the method calls

Constants

IterativeBlock

Built-in concurrency models for delegating methods

execute forwarding in an iterative fashion
ThreadedBlock

If we like speed (with a dash of danger) we can thread the requests rather than iterate

ThreadedFirstResponseBlock

More speed (with more danger) we can use the first valid response (note the change in t.join) How to react to the first response, maybe fibers?

Attributes

concurrency_model[RW]

Public Class Methods

new(sources, concurrency_model = :iterative) click to toggle source
# File lib/group_delegator/source_group.rb, line 114
def initialize(sources, concurrency_model = :iterative)
  @sources = sources
  @concurrency_model = concurrency_model
end

Public Instance Methods

forward(m, *args, &block) click to toggle source
# File lib/group_delegator/source_group.rb, line 119
def forward(m, *args, &block)
  forward_custom(@concurrency_model, m, *args, &block)
end
forward_custom(forward_method, m, *args, &block) click to toggle source
# File lib/group_delegator/source_group.rb, line 123
def forward_custom(forward_method, m, *args, &block)
  forward_block = case forward_method
    when :iterative
      IterativeBlock
    when :threaded
      ThreadedBlock
    when :first_response
      ThreadedFirstResponseBlock
    when Proc
      forward_method
    else
      raise "Invalid parameter: #{forward_method.inspect}"
    end
    
  @valid_response_trace = {}
  @invalid_response_list = []
  sources = @sources
  if sources.size > 0
    resp = forward_block.call(sources, m, *args, &block)
    @valid_response_trace = resp[:valid]
  else
    raise "No sources assigned"
  end
  @valid_response_trace
end
forward_first_resp(m, *args, &block) click to toggle source
# File lib/group_delegator/source_group.rb, line 158
def forward_first_resp(m, *args, &block)
  forward_custom(:first_response, m, *args, &block)
end
forward_iterative(m, *args, &block) click to toggle source

just some sugar

# File lib/group_delegator/source_group.rb, line 150
def forward_iterative(m, *args, &block)
  forward_custom(:iterative, m, *args, & block)
end
forward_threaded(m, *args, &block) click to toggle source
# File lib/group_delegator/source_group.rb, line 154
def forward_threaded(m, *args, &block)
  forward_custom(:threaded, m, *args, & block)
end