class Pione::Agent::InputGenerator

Constants

DOMAIN

Attributes

generator_method[R]
generator[R]

instance methods

Public Class Methods

new(tuple_space, generator_name, input_location, stream) click to toggle source

Initialize the agent.

Calls superclass method
# File lib/pione/agent/input-generator.rb, line 38
def initialize(tuple_space, generator_name, input_location, stream)
  super(tuple_space)
  @base_location = base_location

  # generator method
  if generator_method = InputGenerator.generator_method[generator_name]
    @generator = generator_method.new(tuple_space, input_location, stream)
  else
    raise UnknownInputGeneratorMethod.new(generator_name)
  end
end

Public Instance Methods

transit_to_generate() click to toggle source

Generate a input data tuple and put it into tuple space.

# File lib/pione/agent/input-generator.rb, line 60
def transit_to_generate
  if input = @generator.generate
    # put into history
    @inputs << input

    # build original location
    orig_location = input.location

    # build input location
    input_location = @base_location + "input" + input.name

    # make process log record
    record = Log::PutDataProcessRecord.new.tap do |record|
      record.agent_type = agent_type
      record.agent_uuid = uuid
      record.location = input_location
      record.size = orig_location.size
    end

    # upload the file
    with_process_log(record) do
      orig_location.copy(input_location)
    end

    # put data tuple into tuple space
    write(input.set(location: input_location))
  end
end
transit_to_init() click to toggle source

transitions

# File lib/pione/agent/input-generator.rb, line 54
def transit_to_init
  @generator.init
  @inputs = []
end
transit_to_sleep() click to toggle source
# File lib/pione/agent/input-generator.rb, line 97
def transit_to_sleep
  sleep Global.input_generator_stream_check_timespan
end
transit_to_stop_iteration(e) click to toggle source

State stop_iteration. StopIteration exception is ignored because it means the input generation was completed.

# File lib/pione/agent/input-generator.rb, line 91
def transit_to_stop_iteration(e)
  if not(@inputs.empty?) or not(@generator.stream?)
    write(TupleSpace::CommandTuple.new("start-root-rule", nil))
  end
end