async def run(self): with logger.ExceptionCatcher('ReceiveMessage'): spade_msg = await self.receive(self.agent.TIME_QUANT) if not spade_msg: return msg = deserialize_message(spade_msg) logger.logger.log(logger.EVENT_MESSAGE_RECEIVED, sender=msg.agent, receiver=self.agent.jid, content=msg.body) if msg.receiver_session is not None and msg.receiver_session in self.agent.sessions: self.agent.sessions[msg.receiver_session].add_in_message( msg) elif msg.receiver_session is not None: logger.logger.log( logger.EVENT_EXCEPTION, where=f'Agent {self.agent.id} ReceiveMessage', type='Invalid session', exception=f'{msg.receiver_session}') else: self.agent.received_msg_without_session(msg)
async def run(self): await asyncio.sleep(self.agent.LOGIC_TIME_QUANT) with logger.ExceptionCatcher('GenerateIncome'): current_time = datetime.datetime.now() dt = datetime.timedelta(seconds=self.agent.LOGIC_TIME_QUANT) self.agent.income(current_time, dt)
async def run(self): await asyncio.sleep(self.agent.LOGIC_TIME_QUANT) with logger.ExceptionCatcher('GenerateProduct'): current_time = datetime.datetime.now() dt = current_time - self.last_generate_time self.agent.produce(current_time, dt) self.last_generate_time = current_time
async def run(self): await asyncio.sleep(self.agent.LOGIC_TIME_QUANT) with logger.ExceptionCatcher('ManageNeeds'): current_time = datetime.datetime.now() to_satisfy = datetime.timedelta( seconds=self.agent.config.needs_satisfaction_timeout) self.time_to_satisfy = current_time + to_satisfy self.agent.create_needs(current_time, to_satisfy) if self.agent.current_needs == 0: return await asyncio.sleep(to_satisfy.total_seconds()) self.agent.check_satisfaction()
async def run(self): await asyncio.sleep(self.agent.TIME_QUANT) with logger.ExceptionCatcher('SendMessages'): sessions = self.agent.get_sessions() for sess in sessions: messages = list(sess.take_all_out_messages()) for msg in messages: try: await self.send(msg.serialize()) logger.logger.log(logger.EVENT_MESSAGE_SENT, sender=self.agent.jid, receiver=msg.agent, content=msg.body) except Exception as e: logger.logger.log( logger.EVENT_EXCEPTION, where=f'Agent {self.agent.id} SendMessages', type=str(type(e)), exception=str(e)) if sess.ended: self.agent.remove_session(sess.session_id)
def run_real_time_plot(): with logger.ExceptionCatcher('Visualisation'): return vis_updater()
async def run(self): await asyncio.sleep(self.agent.LOGIC_TIME_QUANT) with logger.ExceptionCatcher('DropProduct'): self.agent.drop()
async def run(self): await asyncio.sleep(self.agent.TIME_QUANT) with logger.ExceptionCatcher('CreateOffers'): self.agent.run_transaction_in_server_mode(selling=False) self.agent.run_transaction_in_server_mode(selling=True)