FileDocCategorySizeDatePackage
AppServer.javaAPI DocExample3474Sun Mar 02 21:32:20 GMT 1997bank.server

AppServer

public class AppServer extends UnicastRemoteObject implements RemoteAppServer
The application server for the banking application. This makes itself available to clients which can use it to get references to client objects.

Fields Summary
Constructors Summary
public AppServer(String u, Properties props)
Constructs a new AppServer object. There should be only one per application server process.

param
u the data store URL
param
props the properties containing the user ID and password
exception
java.rmi.RemoteException thrown if the object cannot be exported

        super();
        Transaction.url = u;
        Transaction.properties = props;
    
Methods Summary
public RemoteCustomergetCustomer(imaginary.persist.RemoteLockHolder h, int id)
Allows a remote client to get a reference to a customer object located on the application server.

param
h the lock holder on the client
param
id the customer ID for the desired customer object
exception
imaginary.persist.PersistenceException an error occurred restopring the desired customer
exception
java.rmi.RemoteException an error occurred exporting the customer

        Transaction t = Transaction.getTransaction();
        RemoteCustomer c;
            
        try {
            c = (RemoteCustomer)Persistent.getPersistent(t, id,
                                                      "bank.server.Customer");
        }
        catch( Exception e ) {
            e.printStackTrace();
            return null;
        }
        return c;
    
public static voidmain(java.lang.String[] args)
The entry point to the application server. It takes three arguments:
  1. The data store URL
  2. The user ID used to connect to the data store
  3. The password used to connect to the data store
It then makes an instance of the AppServer class available to all connecting clients via the RMI URL:
rmi://host/AppServer

param
args the args to the AppServer process

        if( args.length != 3 ) {
            System.out.println("Syntax: [java AppServer URL UID PASSWORD]");
            return;
        }
        System.out.println("Installing the security manager...");
        System.setSecurityManager(new RMISecurityManager());
        try {
            AppServer server;
            Properties props = new Properties();
            String url = args[0];

            props.put("user", args[1]);
            props.put("password", args[2]);
            System.out.println("Starting the application server...");
            Naming.rebind("AppServer", new AppServer(url, props));
            System.out.println("AppServer bound with url: " + url + "...");
        }
        catch( Exception e ) {
            e.printStackTrace();
        }