def Start(db, port=0, is_master=False, server_cls=ThreadedHTTPServer,
          reqhandler_cls=DataServerHandler):
  """Start the data server."""
  # This is the service that will handle requests to the data store.

  if reqhandler_cls.MASTER or reqhandler_cls.DATA_SERVER:
    logging.fatal("Attempt to start server with duplicate request handler.")

  if not reqhandler_cls.SERVICE:
    reqhandler_cls.SERVICE = store.DataStoreService(db)

  # Create the command table for faster execution of remote calls.
  # Along with a method, each command has the required permissions.
  cmd = rdf_data_server.DataStoreCommand.Command
  reqhandler_cls.CMDTABLE = {
      cmd.DELETE_ATTRIBUTES: (reqhandler_cls.SERVICE.DeleteAttributes, "w"),
      cmd.DELETE_SUBJECT: (reqhandler_cls.SERVICE.DeleteSubject, "w"),
      cmd.MULTI_SET: (reqhandler_cls.SERVICE.MultiSet, "w"),
      cmd.MULTI_RESOLVE_PREFIX: (reqhandler_cls.SERVICE.MultiResolvePrefix,
                                 "r"),
      cmd.RESOLVE_MULTI: (reqhandler_cls.SERVICE.ResolveMulti, "r"),
      cmd.LOCK_SUBJECT: (reqhandler_cls.SERVICE.LockSubject, "w"),
      cmd.EXTEND_SUBJECT: (reqhandler_cls.SERVICE.ExtendSubject, "w"),
      cmd.UNLOCK_SUBJECT: (reqhandler_cls.SERVICE.UnlockSubject, "w"),
      cmd.SCAN_ATTRIBUTES: (reqhandler_cls.SERVICE.ScanAttributes, "r")
  }

  # Initialize nonce store for authentication.
  if not reqhandler_cls.NONCE_STORE:
    reqhandler_cls.NONCE_STORE = auth.NonceStore()

  if port == 0 or port is None:
    logging.debug("No port was specified as a parameter. Expecting to find "
                  "port in configuration file.")
  else:
    logging.debug("Port specified was '%i'. Ignoring configuration directive "
                  "Dataserver.port.", port)

  server_port = port or config_lib.CONFIG["Dataserver.port"]

  if is_master:
    logging.debug("Master server running on port '%i'", server_port)
    reqhandler_cls.InitMasterServer(server_port)
  else:
    logging.debug("Non-master data server running on port '%i'", server_port)
    reqhandler_cls.InitDataServer(server_port)

  reqhandler_cls.InitHandlerTables()

  logging.info("Starting! master: " + str(is_master) + " with handler " +
               reqhandler_cls.__name__)

  try:
    server = server_cls(("", server_port), reqhandler_cls)
    server.serve_forever()
  except __HOLE__:
    print ("Caught keyboard interrupt, stopping server at port %s" %
           server_port)
  except socket.error:
    print "Service already running at port %s" % server_port
  finally:
    if reqhandler_cls.MASTER:
      reqhandler_cls.MASTER.Stop()
    else:
      reqhandler_cls.DATA_SERVER.Stop()
dataset/ETHPy150Open google/grr/grr/server/data_server/data_server.py/Start