Class: Pione::Agent::InputGenerator

Inherits:
TupleSpaceClient show all
Defined in:
lib/pione/agent/input-generator.rb

Constant Summary collapse

DOMAIN =
"root"

Constants included from Log::MessageLog

Log::MessageLog::MESSAGE_QUEUE

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from BasicAgent

#chain_threads

Instance Method Summary collapse

Methods inherited from TupleSpaceClient

#bye, #call_transition_method, #hello, #transit_to_terminate

Methods included from Log::MessageLog

#debug_message, #debug_message_begin, #debug_message_end, debug_mode, debug_mode=, debug_mode?, message, quiet_mode, quiet_mode=, quiet_mode?, #show, #user_message, #user_message_begin, #user_message_end

Methods included from TupleSpaceClientOperation

#base_location, #bye, #finalize, #hello, #notify_exception, #read, #take

Methods included from TupleSpace::TupleSpaceInterface

#process_log, #processing_error, #set_tuple_space, tuple_space_operation, #tuple_space_server, #with_process_log

Methods inherited from BasicAgent

agent_type, inherited, set_agent_type, #start, #start!, #states, #terminate, #terminated?, #transit, #wait_until, #wait_until_after, #wait_until_before, #wait_until_terminated

Methods included from StateTransitionSingletonMethod

#chain, #define_exception_handler, #define_transition, #exception_handler, #start, #transition_chain

Constructor Details

#initialize(tuple_space, generator_name, input_location, stream) ⇒ InputGenerator

Initialize the agent.



38
39
40
41
42
43
44
45
46
47
48
# 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

Class Attribute Details

.generator_methodObject (readonly)

Returns the value of attribute generator_method.



10
11
12
# File 'lib/pione/agent/input-generator.rb', line 10

def generator_method
  @generator_method
end

Instance Attribute Details

#generatorObject (readonly)

instance methods



34
35
36
# File 'lib/pione/agent/input-generator.rb', line 34

def generator
  @generator
end

Instance Method Details

#transit_to_generateObject

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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_initObject

transitions



54
55
56
57
# File 'lib/pione/agent/input-generator.rb', line 54

def transit_to_init
  @generator.init
  @inputs = []
end

#transit_to_sleepObject



97
98
99
# 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) ⇒ Object

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



91
92
93
94
95
# 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