Netscape Internet Service Broker for Java: Programmer's Guide, Version 1.0

[Contents] [Previous] [Next]

Chapter 4
Object and Implementation Activation

This chapter discusses how services are implemented and made available to clients. It includes the following major sections:

Object Implementation

An object implementation provides the state and processing activities for an ORB object. An ORB object is created when its implementation class is instantiated in Java by an implementation process or service. An object implementation uses the Basic Object Adaptor (BOA) to activate its ORB objects for use by clients. ISB for Java supports both persistent and transient object references.

Persistent Object References

You create a persistent object reference when you instantiate an object and specify an object name. Persistent object references remain valid beyond the lifetime of the processes that create them. These object references have a global scope; they are registered with the naming service and used by client applications. Persistent object references are registered when the boa.obj_is_ready method is invoked.

You can use persistent object references to implement long-running services that provide long-term tasks. Light-weight and domain-specific, transient object references take a relatively short amount of time to instantiate. Persistent object references take longer to instantiate. Consequently, the ideal mix is to have some persistent object references and many more transient object references used by your application. The following code example creates and registers a persistent object reference using the name ISB_Bank.

Creating a persistent object.

// Using Enterprise Server's ORB
public class Server {
  public static void main(String[] args) {
    try {
      // Initialize the ORB.
      org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
      // Initialize the BOA.
      org.omg.CORBA.BOA boa = orb.BOA_init();
      // Create the account manager object.
      AccountManager manager = new AccountManager("ISB_Bank");
      // Export the newly created object.
      boa.obj_is_ready(manager);
      String host = java.netInetAddress.getLocalHost().getHostName();
      netscape.WAI.Naming.register
         ("http://" + host + "/ISB_Bank", manager);

      // Or, if using Communicator's ORB, the call would be:
      // netscape.WAI.Naming.register
      //    ("http://" + host + "/NameService/ISB_Bank", manager);

      // Wait for incoming requests
      boa.impl_is_ready();
    } catch(org.omg.CORBA.SystemException se) {
        System.err.println(se);
    }
      catch(java.net.UnknownHostException u) {
        System.err.println(u);
    }
  }
}

Checking for Persistent Object References

The Object._is_persistent method allows your client application to determine whether an object reference is persistent or transient. It is important to know whether a reference is persistent because some methods for manipulating object references will fail if the reference is transient. The _is_persistent method returns true if the reference is persistent and false if it is transient. For information about all of the available methods, see the Netscape Internet Service Broker for Java Reference Guide.

Transient Object References

Object references that are only available during the lifetime of the process that created them are called transient object references. Only those entities that possess an explicit object reference to a transient object reference can invoke its methods. To create a transient object reference, instantiate an object without specifying an object name, as shown below.

Creating a transient object.

// Using Enterprise Server's ORB
public class Server {
  public static void main(String[] args) {
    try {
      // Initialize the ORB.
      org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
      // Initialize the BOA.
      org.omg.CORBA.BOA boa = orb.BOA_init();
      // Create the account manager object.
      AccountManager manager = new AccountManager(); 
      // Export the newly created object.
      boa.obj_is_ready(manager);
      String host = java.netInetAddress.getLocalHost().getHostName();
      netscape.WAI.Naming.register
         ("http://" + host + "/ISB_Bank", manager);

      // Or, if using Communicator's ORB, the call would be:
      // netscape.WAI.Naming.register
      //    ("http://" + host + "/NameService/ISB_Bank", manager);

      // Wait for incoming requests
      boa.impl_is_ready();
    } catch(org.omg.CORBA.SystemException se) {
        System.err.println(se);
    }
      catch(java.net.UnknownHostException u) {
        System.err.println(u);
    }
  }
}

Object Registration

Once a server has instantiated the ORB objects that it offers, the BOA must be notified when the objects have been initialized. Lastly, the BOA is notified when the server is ready to receive requests from client applications.

The obj_is_ready method notifies the BOA that a particular ORB object is ready to receive requests from client applications. If your server offers more than one ORB object, it must invoke obj_is_ready for each object, passing the object reference as an argument.

If a persistent object reference is passed to obj_is_ready, the BOA will register the object with the naming service. If the reference is transient, no such registration will occur. If obj_is_ready has not been invoked for an object by its server and a client attempts to bind to the object, the exception NO_IMPLEMENT is raised.

Once all of the objects have been instantiated and all the invocations of obj_is_ready have been made, the server must invoke the impl_is_ready method to enter an event loop and await client requests. Servers that are activated through a GUI (graphical user interface) or are activated by other means do not need to use impl_is_ready.

Activating Objects Directly

Direct activation of an object involves an object server instantiating all the Java implementation classes, invoking the BOA.obj_is_ready method for each object, and then invoking BOA.impl_is_ready to begin receiving requests. The following code example shows how this processing would occur for a server offering two AccountManager objects; one with the object name of Chicago and the other named Dallas. Once the objects have been instantiated and activated, the server invokes BOA.impl_is_ready to begin receiving client requests.

NOTE: The method BOA.obj_is_ready must be called for each object offered by the implementation.
Server activating two objects and the implementation.

// Using Enterprise Server's ORB
public class Server {
  public static void main(String[] args) {
    try {
      // Initialize the ORB.
      org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
      // Initialize the BOA.
      org.omg.CORBA.BOA boa = orb.BOA_init();
      // Create the account manager object for Chicago.
      AccountManager chicago = new AccountManager("Chicago");
      // Create the account manager object for Dallas.
      AccountManager dallas = new AccountManager("Dallas");
      // Export the newly created objects.
      boa.obj_is_ready(chicago);
      boa.obj_is_ready(dallas);
      System.out.println(chicago + " is ready.");
      System.out.println(dallas + " is ready.");
      String host = java.netInetAddress.getLocalHost().getHostName();

      // Or, if using Communicator's ORB, the call would be:
      // netscape.WAI.Naming.register
      //    ("http://" + host + "/NameService/bank", chicago);

      netscape.WAI.Naming.register("http://" + host + "/bank", chicago);
      netscape.WAI.Naming.register("http://" + host + "/bank", dallas);

      // Wait for incoming requests
      boa.impl_is_ready();
    } catch(org.omg.CORBA.SystemException se) {
        System.err.println(se);
    }
      catch(java.net.UnknownHostException u) {
        System.err.println(u);
    }
  }
}

The Basic Object Adaptor

A service implementation uses the Basic Object Adaptor (BOA) to activate its ORB objects so they can be used by client applets and applications. ISB for Java's BOA provides several important functions to clients and the service implementations they use.

A service can reside in the same process as its client or it can reside in a separate process called a server. Servers can contain and offer one or more services. Furthermore, they can be activated by the BOA on demand or they can be started by some entity external to the BOA.

Object and Implementation Deactivation

An object implementation that was started manually is deactivated when the server that implements the object exits. At that time, ISB for Java automatically unregisters the services within that implementation.

Service implementations that called obj_is_ready can be deactivated explicitly by calling deactivate_obj. Then, the implementation will not be available to service client requests. The service can only be re-activated if it is restarted or if it again calls obj_is_ready.


[Contents] [Previous] [Next]

Last Updated: 02/04/98 13:46:53


Copyright © 1997 Netscape Communications Corporation

Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use