Class: Pione::Agent::ProcessManager

Inherits:
TupleSpaceClient show all
Includes:
Log::MessageLog
Defined in:
lib/pione/agent/process-manager.rb

Constant Summary

Constants included from Log::MessageLog

Log::MessageLog::MESSAGE_QUEUE

Instance Attribute Summary collapse

Attributes inherited from BasicAgent

#chain_threads

Instance Method Summary collapse

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 inherited from TupleSpaceClient

#bye, #call_transition_method, #hello, #transit_to_terminate

Methods included from TupleSpaceClientOperation

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

Methods included from TupleSpace::TupleSpaceInterface

#process_log, #processing_error, #read!, #set_tuple_space, #take!, #take_all!, tuple_space_operation, #tuple_space_server, #with_process_log

Methods inherited from BasicAgent

agent_type, inherited, set_agent_type, #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(space, env, package, param_set, stream) ⇒ ProcessManager

Returns a new instance of ProcessManager.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pione/agent/process-manager.rb', line 13

def initialize(space, env, package, param_set, stream)
  unless env.rule_get!(Lang::RuleExpr.new("Main"))
    raise JobError.new("Rule `Main` not found in the package.")
  end

  super(space)
  @space = space
  @env = env
  @package = package
  @param_set = param_set
  @stream = stream
  @package_id = @env.current_package_id
end

Instance Attribute Details

#packageObject (readonly)

instance method



11
12
13
# File 'lib/pione/agent/process-manager.rb', line 11

def package
  @package
end

Instance Method Details

#transit_to_initObject

transitions



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pione/agent/process-manager.rb', line 42

def transit_to_init
  # split parameter set as package toplvel's and main's
  toplevel_variable_names = @env.variable_table.select_names_by(@env, @env.current_package_id)
  toplevel_param_set = @param_set.filter(toplevel_variable_names)
  main_param_set = @param_set.delete_all(toplevel_variable_names)

  # merge the toplevel parameter set
  @env.merge_param_set(toplevel_param_set, force: true)

  # setup root rule
  root_definition = @env.make_root_rule(main_param_set)
  @rule_condition = root_definition.rule_condition_context.eval(@env)

  # share my environment
  write(TupleSpace::EnvTuple.new(@env.dumpable)) # need to be dumpable
end

#transit_to_runObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pione/agent/process-manager.rb', line 63

def transit_to_run
  finder = RuleEngine::DataFinder.new(@space, 'root')
  list = Enumerator.new(finder, :find, :input, @rule_condition.inputs, @env).to_a
  if list.empty?
    user_message "error: no inputs"
    terminate
  else
    # call root rule of the current package
    list.each do |env, inputs|
      package_id = @env.current_package_id
      handler = RuleEngine.make(@space, @env, package_id, "Root", inputs, Lang::ParameterSet.new, 'root', nil)
      handler.handle
    end
  end

  return
end

#transit_to_sleepObject



59
60
61
# File 'lib/pione/agent/process-manager.rb', line 59

def transit_to_sleep
  take(TupleSpace::CommandTuple.new("start-root-rule", nil))
end