public void init()

in src/main/java/org/apache/openejb/cts/deploy/StandardDeployment14.java [92:191]


  public void init(PrintWriter writer) {

    this.log = writer;
    TestUtil.logHarness("StandardDeployment14.init()");

    iPortingSet = TSDeployment.iPortingSet;
    TestUtil
        .logHarness("StandardDeployment14:  Using porting set #" + iPortingSet);

    try {
      propMgr = DeliverableFactory.getDeliverableInstance()
          .getPropertyManager();

      try {
        String portingString = String.valueOf(iPortingSet);
        initDeployTestUtils(portingString);
        deployStateFile = TEMP_DIR + File.separator + DEPLOYED_MODULES_FILE
            + "_" + portingString + ".ser";
      } catch (TSDeploymentException e) {
        TestUtil.logHarness("Unable to initialize the deployment utilities.");
      }
      htDeployedModules = getDeployedModules();
      dumpDeployedMods(htDeployedModules);

      TestUtil.logHarnessDebug("Adding shutdown hook for state serialization");

      // Handle shutdown gracefully.
      Runtime.getRuntime().addShutdownHook(new Thread() {

        // When the VM shuts down this method is invoked to undeploy
        // all currently deployed applications. Note, this method is
        // invoked when a user issues a ctrl-c or the VM shuts down
        // normally. No matter which way the VM shuts down, this
        // method will honor the harness execute mode specified by
        // the user in the ts.jte file (harness.executeMode property).
        public void run() {

          int harnessExecMode = ExecutionMode.getExecutionMode(propMgr);

          // immediately return if we are running in a mode
          // where undeploy is not required.
          if (harnessExecMode == ExecutionMode.DEPLOY
              || harnessExecMode == ExecutionMode.DEPLOY_RUN) {
            try {
              TestUtil.logHarness("IN SHUTDOWN HOOK BEFORE WRITE");
              dumpDeployedMods(htDeployedModules);
              writeMap(htDeployedModules);
            } catch (IOException ioe) {
              ioe.printStackTrace();
            }
            return;
          } else if (harnessExecMode == ExecutionMode.RUN) {
            return;
          }
          TestUtil.logHarness(
              "IN SHUTDOWNHOOK state file is : \"" + deployStateFile + "\"");
          dumpDeployedMods(htDeployedModules);
          Map deployedModules = (Map) htDeployedModules.clone();
          if (deployedModules.size() != 0) {
            TestUtil.logHarness("Shutdown requested during test run."
                + "  Undeploying previously deployed applications...");

            try {
              initDeployTestUtils(sDepNumber);
            } catch (TSDeploymentException e) {
              TestUtil.logHarness("Unable to initialize the deployment"
                  + " utilities.  Applications will not be undeployed.");
            }

            for (Iterator i = deployedModules.keySet().iterator(); i
                .hasNext();) {

              try {
                undeploy((String) i.next());
              } catch (TSDeploymentException tde) {
                TestUtil.logHarness("Unexpected exception while"
                    + " undeploying application during shutdown. " + "Cause: "
                    + tde.getMessage());
              }

            }
            // Release deployment manager in case we get killed
            // We'll also do this with the deploy and undeploy methods
            // since this will only be called if a shutdown is received
            dtu.releaseDeploymentManager();
            deleteDeployedModulesState(); // remove deployed module state
          }
        }
      });
      String portClass = "porting.ts.deploy2.class." + iPortingSet;
      TestUtil.logHarness("Using " + portClass);
      dep2 = TSDeployment2.getDeploymentInstance(log, portClass);
    } catch (Exception e) {
      e.printStackTrace();
      TestUtil.logHarness(
          "Creation of TSDeployment2 implementation instance failed."
              + " Please check the values of 'porting.ts.deploy2.class.1' and"
              + " 'porting.ts.deploy2.class.2'");
    }
  }