Ejemplo n.º 1
0
  public MedSavantServerEngine(
      String databaseHost, int databasePort, String rootUserName, String password)
      throws RemoteException, SQLException, SessionExpiredException {

    try {
      // get the address of this host.
      thisAddress = (InetAddress.getLocalHost()).toString();
    } catch (Exception e) {
      throw new RemoteException("Can't get inet address.");
    }

    listenOnPort = MedSavantServerUnicastRemoteObject.getListenPort();

    if (!performPreemptiveSystemCheck()) {
      System.out.println("System check FAILED, see errors above");
      System.exit(1);
    }

    System.out.println("Server Information:");
    System.out.println(
        "  SERVER VERSION: "
            + VersionSettings.getVersionString()
            + "\n"
            + "  SERVER ADDRESS: "
            + thisAddress
            + "\n"
            + "  LISTENING ON PORT: "
            + listenOnPort
            + "\n");
    // + "  EXPORTING ON PORT: " + MedSavantServerUnicastRemoteObject.getExportPort());
    try {
      // create the registry and bind the name and object.
      registry = LocateRegistry.createRegistry(listenOnPort);

      // TODO: get these from the user

      ConnectionController.setHost(databaseHost);
      ConnectionController.setPort(databasePort);

      System.out.println();
      System.out.println("Database Information:");

      System.out.println(
          "  DATABASE ADDRESS: " + databaseHost + "\n" + "  DATABASE PORT: " + databasePort);

      System.out.println("  DATABASE USER: "******"  PASSWORD FOR " + rootUserName + ": ");
        System.out.flush();
        char[] pass = System.console().readPassword();
        password = new String(pass);
      } else {
        System.out.print("  PASSWORD: "******"Connecting to database ... ");
      try {
        ConnectionController.connectOnce(databaseHost, databasePort, "", rootUserName, password);
      } catch (SQLException ex) {
        System.out.println("FAILED");
        throw ex;
      }
      System.out.println("OK");

      bindAdapters(registry);

      System.out.println("\nServer initialized, waiting for incoming connections...");

      EmailLogger.logByEmail("Server booted", "The MedSavant Server Engine successfully booted.");
    } catch (RemoteException e) {
      throw e;
    } catch (SessionExpiredException e) {
      throw e;
    }
  }