lib/pione/agent/tuple-space-client.rb in pione-0.2.2 vs lib/pione/agent/tuple-space-client.rb in pione-0.3.0

- old
+ new

@@ -9,44 +9,30 @@ end end # Send a hello message to the tuple space server. def hello - write(to_agent_tuple) + write(TupleSpace::AgentTuple.new(agent_type: agent_type, uuid: uuid)) end # Send a bye message to the tuple space server. def bye Util.ignore_exception do - write(to_bye_tuple) + take!(TupleSpace::AgentTuple.new(agent_type: agent_type, uuid: uuid)) end end - # Makes the agent tuple. - # @return [Tuple::Agent] - # the agent tuple - def to_agent_tuple - Tuple[:agent].new(agent_type: agent_type, uuid: uuid) - end - - # Makes the bye tuple. - # @return [Tuple::Bye] - # the bye tuple - def to_bye_tuple - Tuple[:bye].new(agent_type: agent_type, uuid: uuid) - end - # Notify the agent happened a exception. def notify_exception(e) # ignore exception because the exception caused tuple server is down... Util.ignore_exception do - write(Tuple[:exception].new(uuid, agent_type, e)) + write(TupleSpace::ExceptionTuple.new(uuid, agent_type, e)) end end def base_location - read(Tuple[:base_location].any).location + read(TupleSpace::BaseLocationTuple.any).location end # Protected take. def take(*args) tuple = super(*args, &method(:set_current_tuple_entry)) @@ -79,44 +65,35 @@ current_tuple_entry.cancel if current_tuple_entry end end class TupleSpaceClient < BasicAgent - include TupleSpaceServerInterface + include TupleSpace::TupleSpaceInterface include TupleSpaceClientOperation # Initialize agent's state. - def initialize(tuple_space_server) + def initialize(tuple_space) super() - set_tuple_space_server(tuple_space_server) + set_tuple_space(tuple_space) end - def start - super() - return self - end + # + # transitions + # - # State initialized. - def transit_to_initialized + def transit_to_init hello end - # State terminated - def transit_to_terminated + def transit_to_terminate Util.ignore_exception { bye } cancel_current_tuple_entry end - # State error - def transit_to_error(e) - if e - $stderr.puts e - $stderr.puts e.backtrace - end - notify_exception(e) - terminate - end + # + # helper methods + # # Redefine hello method with logging. def hello record = Log::AgentConnectionProcessRecord.new.tap do |record| record.agent_type = agent_type @@ -136,10 +113,10 @@ with_process_log(record) {super} end # Override call transition method with logging. def call_transition_method(*args) - unless [:logger, :command_listener, :messenger].include?(agent_type) + unless [:logger, :job_terminator, :messenger].include?(agent_type) record = Log::AgentActivityProcessRecord.new.tap do |rec| rec.agent_type = agent_type rec.agent_uuid = uuid rec.state = args.first end