-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha2.py
58 lines (49 loc) · 2.08 KB
/
a2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import spade
import time
class Tempus(spade.Agent.Agent):
class ReceiveBehav(spade.Behaviour.Behaviour):
"""This behaviour will receive all kind of messages"""
contador = 0
receiver = spade.AID.aid(name="master@127.0.0.1", addresses=["xmpp://master@127.0.0.1"])
def _setup(self):
print "iniciando"
def _process(self):
self.msg = None
self.msg = self._receive()
if self.msg == None:
#print "no me llego nada"
self.contador = self.contador + 2
if self.contador == 30:
print "espera"
self.msg = spade.ACLMessage.ACLMessage() # Instantiate the message
self.msg.setPerformative("inform") # Set the "inform" FIPA performative
self.msg.setOntology("myOntology") # Set the ontology of the message content
self.msg.setLanguage("OWL-S") # Set the language of the message content
self.msg.addReceiver(self.receiver) # Add the message receiver
self.msg.setContent("espera") # Set the message content
# Third, send the message with the "send" method of the agent
self.myAgent.send(self.msg)
else:
if self.contador == 60:
print "standby"
self.msg = spade.ACLMessage.ACLMessage() # Instantiate the message
self.msg.setPerformative("inform") # Set the "inform" FIPA performative
self.msg.setOntology("myOntology") # Set the ontology of the message content
self.msg.setLanguage("OWL-S") # Set the language of the message content
self.msg.addReceiver(self.receiver) # Add the message receiver
self.msg.setContent("standby") # Set the message content
# Third, send the message with the "send" method of the agent
self.myAgent.send(self.msg)
else:
print self.contador
else:
print "si me llego algo: "+ self.msg.content
self.contador = 0
time.sleep(2)
def _setup(self):
# Add the "ReceiveBehav" as the default behaviour
rb = self.ReceiveBehav()
self.setDefaultBehaviour(rb)
if __name__ == "__main__":
a = Tempus("tempus@127.0.0.1", "secret")
a.start()