示例#1
0
 def create(self, w):
     debug('create ActorsManager')
     actor = w.actors_manager = self.instantiate(self.ActorsManager(w), 
                                                 app = w.app)
     actor.app = w.app
     w.on_consumer_ready_callbacks.append(actor.on_consumer_ready)
     return actor
示例#2
0
 def on_start(self, connection):
     self.connection = connection
     actor_consumer = self.Consumer(self.connection.channel())
     debug('ActorsManager start consuming blabla')
     self.actor_consumer = actor_consumer
     self.actor_consumer.consume()
     self.contribute_to_state(self.state)
示例#3
0
 def reset(self):
     debug('Resetting active actors')
     print self.actor_registry.items()
     for id, (actor, consumer) in self.actor_registry.items():
         self.maybe_conn_error(consumer.cancel)
         # TODO:setting the connection here seems wrong ?
         actor.connection = self.connection
         self._start_actor_consumer(actor)
示例#4
0
 def add_actor(self, name, id = None):
     """Add actor to the actor registry and start the actor's main method"""
     try:
         actor = instantiate(name, connection = self.connection, 
                             id = id)
         self._start_actor_consumer(actor)
         if actor.id in self.actor_registry:
             warn('Actor with the same id already exists')
         debug('Register actor in the actor registry: %s' % name)
         return actor.id
     except Exception as exc:
         error('Start actor error: %r', exc, exc_info=True)
示例#5
0
 def on_consumer_ready(self, consumer):
     debug('ActorsManager in On consumer ready')
     if consumer.connection: 
         raise Exception('Consumer is ready.')
     consumer.on_reset_connection.append(self.on_start)
     consumer.on_close_connection.append(self.stop)
示例#6
0
 def start(self):
     debug('Starting ActorsManager')