import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class SellerRegistration{ //Client
/**
* Method main
*
*
* @param args
*
*/
public static void main(
String[] args) {
try{
if(System.getSecurityManager() == null){
System.setSecurityManager(new RMISecurityManager());
}
RemoteInterface sellerInterface = (RemoteInterface)Naming.lookup("Seller");
//Creation of SellerObject from user input(1.Name, 2.Email, 3.TelephoneNumber)
SellerObject sellerObj = new SellerObject();
System.out.println(" Please enter the inputs 1)Name 2)Email 3)Telephone Number in this given order");
//Validate the user input
if(args.length == 3){
sellerObj.setName(args[0]);
sellerObj.setEmail(args[1]);
sellerObj.setTelephoneNumber(Integer.parseInt(args[2]));
}
else{
System.out.println("Invalid Number of user Input");
}
String sellerId = sellerInterface.sellerRegistration(sellerObj);
System.out.println("before writing to Seller Log file");
//Enter the success message for the Registration in Seller's Log File
String filePath= "C:\\j2sdk1.4.2_12\\bin\\DistributedSystems\\SellerLogfile.txt";
String action = "Register";
//Check whether the sellerId is valid to know the correct status
String status = "";
if(sellerId != null && !sellerId.equals("")){
status = "Success";
}else{
status = "Fail";
}
String[] contents = new String[3];
contents[0] = args[0];
contents[1] = args[1];
contents[2] = args[2];
new Service().writeToLog(filePath, action, status, contents);
System.out.println("after writing to Seller Log file");
}catch(Exception e){
System.out.println(e);
}
}
}
=================================
import java.rmi.*;
public class Broker { //Server
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
System.setSecurityManager(new RMISecurityManager());
System.out.println("Main OK");
try{
RemoteInterface sellerInterface = new RemoteServant();
System.out.println("After creating Servant");
Naming.rebind("Seller", sellerInterface);
System.out.println("Broker Ready");
}catch(Exception e){
System.out.println("Broker server main");
}
}
}