Developing a Java/RMI Server using JRMP
Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................JDK 1.2 (Java 2) or higher

The Steps involved in developing and deploying a Java/RMI Server using JRMP (Java Remote Method Protocol) are

1. Develop your Remote Interface
2. Implement your Java/RMI Server
3. Implement an application that creates your server
4. Develop your policy file
5. Compile the files, generate stubs & skeletons, run the RMIRegistry and startup your server

1. Develop your Remote Interface

SimpleStocks\StockMarket.java
package SimpleStocks;
import java.util.*;
import java.rmi.*;

public interface StockMarket extends java.rmi.Remote {
  float get_price( String symbol ) throws RemoteException;
}

2. Implement your Java/RMI Server

SimpleStocks\StockMarketImpl.java
/**
 * StockMarket
 */

package SimpleStocks;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class StockMarketImpl
  extends UnicastRemoteObject implements StockMarket {

  public StockMarketImpl( String name ) throws RemoteException {
    try {
      Naming.rebind( name, this );
    }
    catch( Exception e ) {
      System.out.println( e );
    }
  }

  public float get_price( String symbol ) {
    float price = 0;
    for( int i = 0; i < symbol.length(); i++ ) {
      price += (int) symbol.charAt( i );
    }
    price /= 5;
    return price;
  }

}
 

3. Implement an Application that creates your Server

StockMarketServer.java
/**
 * Copyright:    Copyright (c) 1998
 * Author:       Gopalan Suresh Raj
 */

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

import SimpleStocks.*;

public class StockMarketServer {

  public static void main(String[] args) throws Exception {
    if(System.getSecurityManager() == null) {
      System.setSecurityManager( new RMISecurityManager() );
    }

    StockMarketImpl myObject = new StockMarketImpl( "NASDAQ" );
    System.out.println( "RMI StockMarketServer ready..." );
  }
}

4. Develop your security policy file

policy.all
grant {
 permission java.security.AllPermission "", "";
};

5. Compile the Files, generate the stubs & skeletons, startup the RMIRegistry and Run the Server


E:\MyProjects\StockRMI\SimpleStocks>
E:\MyProjects\StockRMI\SimpleStocks>javac *.java

E:\MyProjects\StockRMI\SimpleStocks>cd..

E:\MyProjects\StockRMI>rmic SimpleStocks.StockMarketImpl

E:\MyProjects\StockRMI>javac *.java

E:\MyProjects\StockRMI>start rmiregistry

E:\MyProjects\StockRMI>java -Djava.security.policy=policy.all StockMarketServer
RMI StockMarketServer ready...

 

Java/RMI
Java/RMI - Under The Hood
Developing a Java/RMI Server using JRMP
Developing a Java/RMI Client using JRMP
Developing a Java/RMI Server Component using IIOP
Developing a Java/RMI Client to our RMI/IIOP Server Component
Developing a CORBA Client to our RMI/IIOP Server Component

click here to go to
My Advanced Java/J2EE Tutorial Page...

 


Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since September 21,1998.

Last Updated : Dec 19, '98

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-99, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site,are trademarks of their respective owners.