Chapter 7  Performance

Creating Remote Interface

Listing 7.1 (TimecalInterface.java)

import java.rmi.*;

//remote interface
public interface TimecalInterface extends Remote {
	
  //remote method
   public String remoteCall(String text)
	throws RemoteException;
}

The remote interface declares a method that takes a string as its arguments and simply returns the same string.

 

Server Implementation

Listing 7.2 (TimacalServerImpl.java)

import java.rmi.*;
import java.rmi.server.*;
import java.net.MalformedURLException;


//server implementation
public class TimecalServerImpl extends UnicastRemoteObject 
	implements TimecalInterface{
		
   //constructor
   public TimecalServerImpl()
	throws RemoteException {
			
	System.out.println("Creating server Object");
   }
		
   //remote method
   public String remoteCall(String text)
	throws RemoteException {
			
	int i=0;
	for(i=0;i<100;i++)
  	    System.out.println(text +" "+i);
			
	return text;
   }
		
   //main method
   public static void main(String []helloWorld) {
	try {
	 TimecalServerImpl timeServer = new TimecalServerImpl();
	 Naming.rebind("Server",timeServer);
	 System.out.println("Server Ready");
	}catch(RemoteException ex) {
	   System.out.println("Error " +ex.getMessage());
	}
	catch(MalformedURLException ex) {
	   System.out.println("Error " +ex.getMessage());
	}
    } 
				
}


 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com