aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/testIvy.py
blob: bd2a7530711efeac6dc846820b7b25e9da3fcf9a (plain)
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
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
Petit programme de test de la classe Ivy.Ivy
"""

import logging 
livy = logging.getLogger('Ivy')
console = logging.StreamHandler()
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
livy.addHandler(console)
livy.setLevel(logging.DEBUG)
from ivy import Ivy, IvyApplicationAdapter, IvyMessageAdapter
class MyApplicationAdapter (IvyApplicationAdapter):
    def connect(self, ivyclient):
        print "Connexion de %s"%ivyclient.getName()
    def die(self, ivyclient, id):
        print "Demande de fin de l'agent recu"

class MyMessageAdapter(IvyMessageAdapter):
    def receive(self, client, *arg):
        print "Message --> %s"%arg[0]
        
appAdapter = MyApplicationAdapter()
#Il ne faut pas mettre d'espace dans le nom de l'application
#sinon die ne fonctionne pas !!
bus        = Ivy("tinytest","Hello World",appAdapter)
print "Bus %s"%bus
bus.start("")
bus()
msgAdapter = MyMessageAdapter()
id         = bus.bindMsg("([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)",msgAdapter)
bus.theThread.join(5)
id1        = bus.bindMsg("(.*)",msgAdapter)
bus.theThread.join(20)