def main(): parser = argparse.ArgumentParser( description="Lots of Messages experiment") parser.add_argument( "-e", "--experiments", help="Number of experiments to run", default=20, type=int) parser.add_argument( "-s", "--steps", help="Number of steps each experiment should require", default=5000, type=int) parser.add_argument( "-w", "--workers", help="How many worker threads running in the hive", default=5, type=int) args = parser.parse_args() hive = Hive() department_chair = hive.create_actor( DepartmentChair) hive.send_message( to=department_chair, directive="oversee_experiments", body={ "num_experiments": args.experiments, "num_steps": args.steps}) hive.run()
def main(): parser = argparse.ArgumentParser( description="Potter Puppet Pals simulator") parser.add_argument( "-s", "--students", help="Number of students", default=5, type=int) parser.add_argument( "-w", "--workers", help="How many worker threads running in the hive", default=5, type=int) args = parser.parse_args() hive = Hive() snape = hive.create_actor( Professor, id="snape") for i in range(args.students): student = hive.create_actor( Student, id=gen_student_name()) hive.send_message( to=student, directive="bother_professor", body={ "target": snape}) hive.run()
def main(): parser = argparse.ArgumentParser( description="Potter Puppet Pals simulator") parser.add_argument("-s", "--students", help="Number of students", default=5, type=int) parser.add_argument("-w", "--workers", help="How many worker threads running in the hive", default=5, type=int) args = parser.parse_args() hive = Hive() snape = hive.create_actor(Professor, id="snape") for i in range(args.students): student = hive.create_actor(Student, id=gen_student_name()) hive.send_message(to=student, directive="bother_professor", body={"target": snape}) hive.run()
def main(num_experiments=DEFAULT_NUM_STEPS, num_steps=DEFAULT_NUM_STEPS, subprocesses=None, slacker_time=0): """ Returns True if the experiment was a success. """ success_tracker = SuccessTracker() hive = Hive() department_chair = hive.create_actor(DepartmentChair, num_worker_processes=subprocesses or 0) hive.send_message(to=department_chair, directive="oversee_experiments", body={ "num_experiments": num_experiments, "num_steps": num_steps, "success_tracker": success_tracker, "slacker_time": slacker_time }) hive.run() return success_tracker.success
def startingActors(use_task_generator=False, performanceTesting=False): central_hive = Hive(hive_id = settings.HIVE_ID ) request_handler = central_hive.create_actor(RequestHandler, id=settings.REQUEST_HANDLER) scheduler = central_hive.create_actor(Scheduler, id=settings.SCHEDULER) swarm_keeper = central_hive.create_actor(SwarmKeeper, id=settings.SWARM_KEEPER) if use_task_generator == True: task_generator = central_hive.create_actor(TaskGenerator, id='generator') central_hive.send_message(to=request_handler, directive="start") central_hive.send_message(to=scheduler, directive="start") central_hive.send_message(to=swarm_keeper, directive="start") if use_task_generator == True: central_hive.send_message(to=task_generator, directive="start") if performanceTesting == True: testingActor = central_hive.create_actor(TestsGenerator, id=settings.TESTS_GENERATOR) if settings.IMPLAN_ASSIGNMENT == True: testDescription = 'implanAssignment' elif settings.IMPLAN == True: testDescription = 'implan' else: testDescription = 'basePlan' testDescription = testDescription + settings.MULTI_PLANNER central_hive.send_message(to=testingActor, directive="start", body = {"world":settings.WORLD_FILE_NAME,\ "test_description":testDescription, "test_name":settings.TEST_NAME,\ "arena_name":settings.ARENA_NAME}) central_hive.run()
def main(): logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.INFO) logging.getLogger('xudd.hive').setLevel(logging.INFO) logging.getLogger('xudd.actor').setLevel(logging.INFO) hive = Hive() server_id = hive.create_actor(Server, id='server') #hive.create_actor(HTTPHandler, id='http') #hive.create_actor(WSGI, id='wsgi') hive.send_message(to=server_id, directive='listen') try: hive.run() finally: try: _log.info('Closing sockets') server = hive._actor_registry[server_id] server.socket.close() for key, val in server.requests.iteritems(): sock, bind = val sock.close() except Exception as e: print(e)
def main(): logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.INFO) logging.getLogger('xudd.hive').setLevel(logging.INFO) logging.getLogger('xudd.actor').setLevel(logging.INFO) hive = Hive() server_id = hive.create_actor(Server, id='server') hive.create_actor(HTTPHandler, id='http') hive.create_actor(WSGI, id='wsgi') hive.send_message(to=server_id, directive='listen') try: hive.run() finally: try: _log.info('Closing sockets') server = hive._actor_registry[server_id] server.socket.close() for key, val in server.requests.iteritems(): sock, bind = val sock.close() except Exception as e: print(e)
def main(): import sys url = sys.argv[1] hive = Hive() web_reader = hive.create_actor(WebReader) hive.send_message(to=web_reader, directive="read_webs", body={"url": url}) hive.run()
def main(): hive = Hive() listener = hive.create_actor(Listener, id="listener") echoer = hive.create_actor(Echoer, id="echoer") hive.send_message(to=listener, directive="listen_loop", body={"echoer": echoer}) hive.run()
def main(): logging.basicConfig(level=logging.DEBUG) hive = Hive() irc_bot = hive.create_actor(IrcBot) hive.send_message( to=irc_bot, directive="connect_and_run") hive.run()
def main(): logging.basicConfig(level=logging.DEBUG) hive = Hive() server = hive.create_actor(Server, id='server') wsgi = hive.create_actor(WSGI, id='wsgi') hive.send_message(to='server', directive='listen') hive.run()
def main(): # Create the hive hive = Hive() # Add overseer, who populates the world and runs the simulation overseer_id = hive.create_actor(Overseer, id="overseer") hive.send_message( to=overseer_id, directive="init_world") # Actually initialize the world hive.run()
def setCommunicationInfrastructure(self): central_hive = Hive(hive_id=settings.HIVE_ID) request_handler = central_hive.create_actor( RequestHandler, id=settings.REQUEST_HANDLER) scheduler = central_hive.create_actor(Scheduler, id=settings.SCHEDULER) swarm_keeper = central_hive.create_actor(SwarmKeeper, id=settings.SWARM_KEEPER) central_hive.send_message(to=request_handler, directive="start") central_hive.send_message(to=scheduler, directive="start") central_hive.send_message(to=swarm_keeper, directive="start") central_hive.run()
def main(): # Set up logging logging.basicConfig() logging.getLogger().setLevel(logging.WARNING) # Invoke the destruction deity hive = Hive() # Add overseer, who populates the world and reports things overseer_id = hive.create_actor(Overseer, id="overseer") hive.send_message(to=overseer_id, directive="init_world") hive.run()
def main(): import sys url = sys.argv[1] hive = Hive() web_reader = hive.create_actor(WebReader) hive.send_message( to=web_reader, directive="read_webs", body={"url": url}) hive.run()
def main(): hive = Hive() listener = hive.create_actor( Listener, id="listener") echoer = hive.create_actor( Echoer, id="echoer") hive.send_message( to=listener, directive="listen_loop", body={"echoer": echoer}) hive.run()
def serve(): logging.basicConfig(level=logging.DEBUG) logging.getLogger('xudd.hive').setLevel(logging.INFO) logging.getLogger('xudd.actor').setLevel(logging.INFO) hive = Hive() wsgi_id = hive.create_actor(WSGI, app=wsgi_app) http_id = hive.create_actor(HTTP, request_handler=wsgi_id) server_id = hive.create_actor(Server, request_handler=http_id) hive.send_message(to=server_id, directive='listen') hive.run()
def main(): # Set up logging logging.basicConfig() logging.getLogger().setLevel(logging.WARNING) # Invoke the destruction deity hive = Hive() # Add overseer, who populates the world and reports things hive.create_actor(Overseer, id="overseer") hive.send_message( to="overseer", directive="init_world") hive.run()
def main(): logging.basicConfig(level=logging.DEBUG) # Fails stupidly if no username given try: username = sys.argv[1] except IndexError: raise IndexError("You gotta provide a username as first arg, yo") hive = Hive() irc_bot = hive.create_actor(IrcBot, username) hive.send_message(to=irc_bot, directive="connect_and_run") hive.run()
def main(): logging.basicConfig(level=logging.DEBUG) # Fails stupidly if no username given try: username = sys.argv[1] except IndexError: raise IndexError("You gotta provide a username as first arg, yo") hive = Hive() irc_bot = hive.create_actor(IrcBot, username) hive.send_message( to=irc_bot, directive="connect_and_run") hive.run()
def connect(): logging.basicConfig(level=logging.DEBUG) hive = Hive() bot_id = hive.create_actor(IRCBot, id='bot') irc_id = hive.create_actor(IRCClient, id='irc', message_handler=bot_id) client_id = hive.create_actor(Client, id='tcp_client', chunk_handler=irc_id) hive.send_message( to=client_id, directive='connect', body={'host': 'irc.freenode.net', 'port': 6667}) hive.run()
def connect(): logging.basicConfig( level=logging.DEBUG, format='%(levelname)08s %(threadName)s %(name)s: %(message)s') admin_hosts = os.environ.get('PPNX_ADMIN_HOSTS') autojoin_channels = os.environ.get('PPNX_AUTO_CHANNELS') kw = { 'autoreload': bool(int(os.environ.get('PPNX_AUTORELOAD', 0))) } for name in ['nick', 'user', 'password', 'realname']: value = os.environ.get('PPNX_{0}'.format(name.upper())) if value is not None: kw.update({name: value}) hive = Hive() hive.create_actor( IRCBot, id='bot', module_directory=os.path.join( os.path.dirname(__file__), '..', 'modules'), administrator_hosts=admin_hosts, autojoin_channels=autojoin_channels, **kw ) irc_id = hive.create_actor(IRCClient, id='irc', message_handler='bot') client_id = hive.create_actor(Client, id='tcp_client', chunk_handler=irc_id) connect_args = { 'host': os.environ.get('PPNX_HOST', 'irc.freenode.net'), 'port': int(os.environ.get('PPNX_PORT', 6667)) } hive.send_message( to='tcp_client', directive='connect', body=connect_args) hive.run()
def serve(): logging.basicConfig(level=logging.DEBUG) logging.getLogger('xudd.hive').setLevel(logging.INFO) logging.getLogger('xudd.actor').setLevel(logging.INFO) hive = Hive() wsgi_id = hive.create_actor(WSGI, app=wsgi_app) http_id = hive.create_actor(HTTP, request_handler=wsgi_id) server_id = hive.create_actor(Server, request_handler=http_id) hive.send_message( to=server_id, directive='listen') hive.run()
def main(num_experiments=DEFAULT_NUM_STEPS, num_steps=DEFAULT_NUM_STEPS, subprocesses=None, slacker_time=0): """ Returns True if the experiment was a success. """ success_tracker = SuccessTracker() hive = Hive() department_chair = hive.create_actor( DepartmentChair, num_worker_processes=subprocesses or 0) hive.send_message( to=department_chair, directive="oversee_experiments", body={ "num_experiments": num_experiments, "num_steps": num_steps, "success_tracker": success_tracker, "slacker_time": slacker_time}) hive.run() return success_tracker.success
def __init__(self, hive, id): super(Overseer, self).__init__(hive, id) self.message_routing.update({"init_world": self.init_world}) def init_world(self, message): """ Initialize the world we're operating in for this demo. """ handler = hive.create_actor(WebSocketHandler, id="handler") client = hive.create_actor(Client, id="client", chunk_handler=handler) yield self.wait_on_message(to=client, directive="connect", body={ "host": '127.0.0.1', "port": 8000 }) for i in range(10): self.send_message(to=client, directive="send", body={"message": "Message number " + str(i)}) if __name__ == '__main__': # create basic Hive hive = Hive() overseer_id = hive.create_actor(Overseer) hive.send_message(to=overseer_id, directive="init_world") hive.run()