private TerminalSessionFactory loadTerminalSessionFactory(Configurations conf) {
    String backend = conf.get(AmoroManagementConf.TERMINAL_BACKEND);
    if (backend == null) {
      throw new IllegalArgumentException("lack terminal implement config.");
    }
    String backendImplement;
    switch (backend.toLowerCase()) {
      case "local":
        backendImplement = LocalSessionFactory.class.getName();
        break;
      case "kyuubi":
        backendImplement = KyuubiTerminalSessionFactory.class.getName();
        break;
      case "custom":
        Optional<String> customFactoryClz =
            conf.getOptional(AmoroManagementConf.TERMINAL_SESSION_FACTORY);
        if (!customFactoryClz.isPresent()) {
          throw new IllegalArgumentException(
              "terminal backend type is custom, but terminal session factory is not "
                  + "configured");
        }
        backendImplement = customFactoryClz.get();
        break;
      default:
        throw new IllegalArgumentException(
            "illegal terminal implement: " + backend + ", local, kyuubi, " + "custom is available");
    }
    TerminalSessionFactory factory;
    try {
      factory = (TerminalSessionFactory) Class.forName(backendImplement).newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
      throw new RuntimeException("failed to init session factory", e);
    }

    String factoryPropertiesPrefix = AmoroManagementConf.TERMINAL_PREFIX + backend + ".";
    Configurations configuration = new Configurations();

    for (String key : conf.keySet()) {
      if (!key.startsWith(AmoroManagementConf.TERMINAL_PREFIX)) {
        continue;
      }
      String value = conf.getValue(ConfigOptions.key(key).stringType().noDefaultValue());
      key = key.substring(factoryPropertiesPrefix.length());
      configuration.setString(key, value);
    }
    configuration.set(
        AmoroManagementConf.TERMINAL_SENSITIVE_CONF_KEYS,
        serviceConfig.get(AmoroManagementConf.TERMINAL_SENSITIVE_CONF_KEYS));
    configuration.set(TerminalSessionFactory.FETCH_SIZE, this.resultLimits);
    factory.initialize(configuration);
    return factory;
  }
Get last execution info

@param terminalId - id of terminal window
@return last session info
amoro-ams/src/main/java/org/apache/amoro/server/terminal/TerminalManager.java