/**
   * Tries to check if the Network Server is up and running by calling ping If successful, then it
   * returns else tries for 50 seconds before giving up and throwing an exception.
   *
   * @throws Exception when there is a problem with testing if the Network Server is up and running
   */
  private static void waitForStart() throws Exception {

    // Server instance for testing connection
    org.apache.derby.drda.NetworkServerControl server = null;

    // Use NetworkServerControl.ping() to wait for
    // NetworkServer to come up.  We could have used
    // NetworkServerControl to start the server but the property is
    // easier.
    server = new NetworkServerControl();

    System.out.println("Testing if Network Server is up and running!");
    for (int i = 0; i < 10; i++) {
      try {

        Thread.currentThread().sleep(5000);
        server.ping();
      } catch (Exception e) {
        System.out.println("Try #" + i + " " + e.toString());
        if (i == 9) {
          System.out.println("Giving up trying to connect to Network Server!");
          throw e;
        }
      }
    }
    System.out.println("Derby Network Server now running");
  }
Example #2
0
  private static void waitForStart(String portString, int timeToWait) throws Exception {
    int waitTime = 0;
    int port = Integer.parseInt(portString);

    NetworkServerControl derbyServer =
        new NetworkServerControl(InetAddress.getByName("localhost"), port);

    while (waitTime < timeToWait) {
      try {
        derbyServer.ping();
        return;
      } catch (Exception e) {
        Thread currentThread = Thread.currentThread();
        synchronized (currentThread) {
          try {
            currentThread.wait(1000);
            waitTime += 1000;
            if (waitTime >= timeToWait) {
              System.out.println("Giving up on wait, waited: " + waitTime);
              throw e;
            }
          } catch (InterruptedException ie) {
          }
        }
      }
    }
  }
 public boolean isStarted() {
   try {
     networkServerControl.ping();
     return true;
   } catch (Exception e) {
     return false;
   }
 }