Exemplo n.º 1
0
class Supervisor(Actor):
    def __init__(self, name, workers):
        Actor.__init__(self, name)
        self.workers = workers
        self.supervisor_strategy = RoundRobinIndexer(len(workers))
        self.state = ActorStates.Idle

    def start(self):
        Actor.start(self)

        for w in self.workers:
            w.start()

    def receive(self, message):
        if -1 == len(self.workers) - 1:
            raise Exception("Supervisor received work but no workers to give it to!")

        index = self.supervisor_strategy.next()
        print("Sending work to worker %s [%d]" % (self.workers[index].name, self.inbox.qsize()))

        self.workers[index].inbox.put(message)
Exemplo n.º 2
0
class Supervisor(Actor):
    def __init__(self, name, workers):
        Actor.__init__(self, name)
        self.workers = workers
        self.supervisor_strategy = RoundRobinIndexer(len(workers))
        self.state = ActorStates.Idle

    def start(self):
        Actor.start(self)

        for w in self.workers:
            w.start()

    def receive(self, message):
        if -1 == len(self.workers) - 1:
            raise Exception(
                "Supervisor received work but no workers to give it to!")

        index = self.supervisor_strategy.next()
        print("Sending work to worker %s [%d]" %
              (self.workers[index].name, self.inbox.qsize()))

        self.workers[index].inbox.put(message)
Exemplo n.º 3
0
 def __init__(self, name, workers):
     Actor.__init__(self, name)
     self.workers = workers
     self.supervisor_strategy = RoundRobinIndexer(len(workers))
     self.state = ActorStates.Idle
Exemplo n.º 4
0
 def __init__(self, name, workers):
     Actor.__init__(self, name)
     self.workers = workers
     self.supervisor_strategy = RoundRobinIndexer(len(workers))
     self.state = ActorStates.Idle