예제 #1
0
    def run(self):
        print("Entrou no coordenador ", self.topic)
        cont = Cons(".\python.config")
        cont.subscribe([self.topic])
        bodies = []
        while True:
            try:
                data, err = self.timeout(cont, 15)
                print(f'Recebi data: {data}')
                if data == None:
                    continue
                elif err != None:
                    continue
                else:
                    bodies.append(data)
            except TypeError:
                # caso dê exesão, conferir se tem uam unica palavra a ser somada
                print("timeout")
                for topic in self.coordinatorsTopic:
                    print(f'publicando em coordenador')
                    for body in bodies:
                        prod = Prod("./python.config", topic)
                        prod.publish("data", body)
                        print(f'Publicando em {topic} - {str(body)}')
                        try:
                            prod.flush()
                        except:
                            pass
                if bodies == []:
                    continue
                self.run2(cont, bodies.copy())
                bodies = []

        cont.close()
예제 #2
0
    def run(self):
        print("Entrou no run")
        cont = Cons(".\python.config")
        cont.subscribe([self.topic])
        while True:
            reicivedBodies = []
            for body in self.bodies:
                prod = Prod("./python.config", self.coordenationTopic)
                prod.publish("data", body.__dict__)
                print(
                    f'Publicando em {self.coordenationTopic} - {body.__dict__}'
                )
                try:
                    prod.flush()
                except:
                    pass
            while True:
                try:
                    data, err = self.timeout(cont, 50)
                    print(f'Recebi data: {data}')
                    if data == None:
                        continue
                    elif err != None:
                        continue
                    else:
                        reicivedBodies.append(
                            Body(int(data['x']), int(data['y']),
                                 int(data['size']), int(data['xDisplacement']),
                                 int(data['yDisplacement'])))
                        print("Received bodies: ")
                except TypeError:
                    print("Entrou no exception")
                    if reicivedBodies == []:
                        print("reicivedBodies == []")
                        continue
                    with concurrent.futures.ThreadPoolExecutor(4) as executor:
                        # dividir para as threads
                        results = executor.map(self.changeAll,
                                               [(i, reicivedBodies.copy())
                                                for i in self.bodies])
                        resultados = []
                        print("Trabalhando sobre: ", reicivedBodies)
                        print("Resultados")
                        for result in results:
                            resultados.append(result)
                            print("  ->", result.__dict__)
                        print("Atulização")
                        for i, result in enumerate(resultados):
                            self.bodies[i] = result
                    break
            # break

        cont.close()
예제 #3
0
 def run(self):
     worker = Cons(".\python.config")
     worker.subscribe([self.topic])
     while True:
         # receber dados
         data, err = worker.run()
         print("Recebi: ", data)
         if data == None:
             continue
         elif err != None:
             continue
         else:
             nMachine = data['machine']
             word = data['word']
             data = data['data']
             with concurrent.futures.ThreadPoolExecutor() as executor:
                 executor.submit(self.work, data, nMachine, word)
     worker.close()
예제 #4
0
 def run(self):
     reduce = Cons(".\python.config")
     reduce.subscribe(["reduce"])
     while True:
         # receber dados
         data, err = reduce.run()
         print(data)
         if data == None:
             continue
         elif err != None:
             continue
         else:
             file = data['file']
             word = data['word']
             data = data['data']
             with concurrent.futures.ThreadPoolExecutor() as executor:
                 executor.submit(self.reduce, data, file, word)
     reduce.close()
예제 #5
0
 def run(self):
     termClean = Cons(".\python.config")
     termClean.subscribe(["termclean"])
     while True:
         # receber dados
         data, err = termClean.run()
         print(data)
         if data == None:
             continue
         elif err != None:
             continue
         else:
             file = data['file']
             word = data['word']
             data = data['data']
             with concurrent.futures.ThreadPoolExecutor() as executor:
                 executor.submit(self.publishToReduce, data, file, word)
     termClean.close()
예제 #6
0
import classProducer as producer
from classConsumer import Cons

prod = producer.Prod(".\python.config", "teste")

for n in range(10):
    print('piblising', "hello", {'count': n})
    prod.publish("hello", {'count': n})
    try:
        prod.flush()
    except:
        pass

cons = Cons(".\python.config")

cons.subscribe(["decode"])

cons.run()
예제 #7
0
    def run(self):
        cont = Cons(".\python.config")
        cont.subscribe(["cont"])
        dataFinal = {}
        while True:
            try:
                data, err = timeout(cont)
                print(f'Recebi data: {data}')
                if data == None:
                    continue
                elif err != None:
                    continue
                else:
                    word = data['word']
                    data = data['data']

                    if dataFinal.get(word) is None:
                        dataFinal[word] = data + ' '
                    else:
                        dataFinal[word] += data + ' '

                    if self.dictWord.get(word) is None:
                        self.dictWord[word] = 0

                    print(f'Datafinal: {dataFinal}')
                    print(f'Contagem atual: {self.dictWord}')
            except Exception:
                # caso dê exesão, conferir se tem uam unica palavra a ser somada
                print("timeout")
                for key, value in dataFinal.items():
                    splitado = [
                        int(num) for num in dataFinal[key].split(' ')
                        if num != ''
                    ]
                    if 0 < len(splitado) < 3:
                        print(f'tamanho < 3, valor atul: {self.dictWord[key]}')
                        print(f'Valor a somar: {sum(splitado)}')
                        self.dictWord[key] += sum(splitado)
                        dataFinal[key] = ''
                        prod = Prod("./python.config", key)
                        prod.publish("data", {
                            'data': str(self.dictWord[key]),
                            'word': word
                        })
                        print(
                            f'Publicando em {key} - {str(self.dictWord[key])}')
                        try:
                            prod.flush()
                        except:
                            pass
                    elif len(splitado) > 2:
                        for topic in self.topics:
                            prod = Prod("./python.config", topic)
                            prod.publish(
                                "data", {
                                    'data': value,
                                    'word': word,
                                    'machine': self.nMachines
                                })
                            print(f'Publicando em machines - {value}')
                            try:
                                prod.flush()
                            except:
                                pass
                        dataFinal[key] = ''

        cont.close()