/** Main program to start a VM for an activation group. */
 public static void main(String args[]) {
   try {
     if (System.getSecurityManager() == null) {
       System.setSecurityManager(new SecurityManager());
     }
     MarshalInputStream in =
         new MarshalInputStream(
             System.in,
             ActivationGroupInit.class.getClassLoader(),
             false,
             null,
             Collections.EMPTY_LIST);
     in.useCodebaseAnnotations();
     ActivationGroupID id = (ActivationGroupID) in.readObject();
     ActivationGroupDesc desc = (ActivationGroupDesc) in.readObject();
     long incarnation = in.readLong();
     Class cl = RMIClassLoader.loadClass(desc.getLocation(), desc.getClassName());
     try {
       Method create =
           cl.getMethod(
               "createGroup",
               new Class[] {ActivationGroupID.class, ActivationGroupDesc.class, long.class});
       create.invoke(null, new Object[] {id, desc, new Long(incarnation)});
     } catch (NoSuchMethodException e) {
       ActivationGroup.createGroup(id, desc, incarnation);
     }
   } catch (Exception e) {
     System.err.println("Exception in starting ActivationGroupInit:");
     e.printStackTrace();
   } finally {
     try {
       System.in.close();
       // note: system out/err shouldn't be closed
       // since the parent may want to read them.
     } catch (Exception ex) {
       // ignore exceptions
     }
   }
 }
  public static void main(String args[]) {
    /*
     * The following line is required with the JDK 1.2 VM so that the
     * VM can exit gracefully when this test completes.  Otherwise, the
     * conservative garbage collector will find a handle to the server
     * object on the native stack and not clear the weak reference to
     * it in the RMI runtime's object table.
     */
    Object dummy1 = new Object();
    RMID rmid = null;

    System.err.println("\nRegression test for bug/rfe 4109103\n");

    try {

      // Set security manager according to the
      // testlibrary.
      TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);

      // start an rmid.
      RMID.removeLog();
      rmid = RMID.createRMID(rmidOut, rmidErr, false);
      rmid.start();

      /* Cause activation groups to have a security policy that will
       * allow security managers to be downloaded and installed
       */
      Properties p = new Properties();
      // this test must always set policies/managers in its
      // activation groups
      p.put("java.security.policy", TestParams.defaultGroupPolicy);
      p.put("java.security.manager", TestParams.defaultSecurityManager);

      /* new desc - we will reuse in order to get multiple vms.*/
      System.err.println("Create activation group in this VM");
      ActivationGroupDesc groupDesc = new ActivationGroupDesc(p, null);
      ActivationSystem system = ActivationGroup.getSystem();
      ActivationGroupID groupID = system.registerGroup(groupDesc);
      ActivationGroup.createGroup(groupID, groupDesc, 0);

      ActivationDesc desc = new ActivationDesc("CheckAnnotations", null, null);
      myRMI = (MyRMI) Activatable.register(desc);

      /* The test-
       * Loop a bunch of times to force activator to
       * spawn VMs (groups)
       */
      for (int i = 0; i < 3; i++) {

        // object activated in annotation check via method call
        if (!checkAnnotations(i - 1)) {
          TestLibrary.bomb("Test failed: output improperly annotated.");
        }

        /*
         * Clean up object too.
         */
        System.err.println("Deactivate object via method call");
        myRMI.shutdown();
      }
      System.err.println("\nsuccess: CheckAnnotations test passed ");

    } catch (Exception e) {
      TestLibrary.bomb("\nfailure: unexpected exception ", e);
    } finally {
      try {
        Thread.sleep(4000);
      } catch (InterruptedException e) {
      }

      myRMI = null;
      System.err.println("rmid shut down");
      ActivationLibrary.rmidCleanup(rmid);
    }
  }