FileDocCategorySizeDatePackage
ActivateTest.javaAPI DocExample1878Wed Apr 05 11:25:42 BST 2000None

ActivateTest.java

/*
 * This example is from the book "Java Enterprise in a Nutshell".
 * Copyright (c) 1999 by O'Reilly & Associates.  
 * You may distribute this source code for non-commercial purposes only.
 * You may study, modify, and use this example for any purpose, as long as
 * this notice is retained.  Note that this example is provided "as is",
 * WITHOUT WARRANTY of any kind either expressed or implied.
 */

import java.rmi.activation.*;
import java.rmi.registry.*;
import java.rmi.*;
import java.net.URL;
import java.net.MalformedURLException;

public class ActivateTest {
  public static void main(String argv[]) {
    String serverName = argv[0];
    String codebaseURL = argv[1];
    try {
      // Make group for activatable object
      ActivationGroupDesc gdesc = new ActivationGroupDesc(null, null);
      ActivationGroupID gid =
       ActivationGroup.getSystem().registerGroup(gdesc);
      ActivationGroup.createGroup(gid, gdesc, 0);

      MarshalledObject activationArg = new MarshalledObject(serverName);
      
      System.out.println("Making server...");
      ThisOrThatServer server;
      if (argv.length > 2 && argv[2].equals("pre")) {
	server =
	  new ActivatableThisOrThatServerImpl(serverName, codebaseURL, 0);
      }
      else {
	ActivationDesc desc =
	  new ActivationDesc(gid,
			     "ActivatableThisOrThatServerImpl",
			     codebaseURL, activationArg);
	System.out.println("Registering server with activation server...");
	server = (ThisOrThatServer)Activatable.register(desc);
      }
      System.out.println("Registering with naming server as " + serverName + "...");
      LocateRegistry.getRegistry().rebind(serverName, server);
      System.out.println("Server registered with naming and activation");
    }
    catch (Exception e) {
      e.printStackTrace();
      System.out.println("Failed to register server.");
    }
    return;
  }
}