title: How to call different remote objects on same interface method and maintain their own data? java RMI
body: <p>I have server class which implements common interface between client and server. I have multiple remote objects bonded to different rim registry(diff ports and rim_id). Client will lookup the registry based on clientID for e.g. IF clientID is EXE1111 then it should connects to EXE server remote object. I want each server object to have its own hashtable to store data given by client. Here is server code::</p>
  
  <pre><code>enter code here
  public class StationServers extends UnicastRemoteObject implements StationService{
      private static final long serialVersionUID = 8119533223378875144L;
      private String criminalRecordID="CR";
      private String missingRecordID="MR";
      private int count=11111;
  
      protected StationServers() throws RemoteException {
          super();
      }
  
      public static void main(String args[]){ 
              try {
                  bindSPVMServer(new StationServers());
                  bindSPLServer(new StationServers());
                  bindSPBServer(new StationServers());
  
                  System.out.print("Servers are up and running on ");
                  System.out.println(InetAddress.getLocalHost().getHostName());
              } catch (Exception e) {
                  System.err.println("Server start up error: "+e.getMessage());
                  e.printStackTrace();
              }
      }
  
      private static void bindSPVMServer(StationServers spvmObject) {
          try {
              Registry reg = LocateRegistry.createRegistry(Constants.SPVM_RMI_PORT);
              reg.bind(Constants.SPVM_RMI_ID, spvmObject);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      private static void bindSPLServer(StationServers splObject) {
          try {
              Registry reg = LocateRegistry.createRegistry(Constants.SPL_RMI_PORT);
              reg.bind(Constants.SPL_RMI_ID, splObject);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      private static void bindSPBServer(StationServers spbObject) {
          try {
              Registry reg = LocateRegistry.createRegistry(Constants.SPB_RMI_PORT);
              reg.bind(Constants.SPB_RMI_ID, spbObject);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public void createCRecord(String firstName, String lastName,
              String description, RecordStatus status) throws RemoteException {
      }
  
      @Override
      public void createMRecord(String firstName, String lastName,
              String address, String lastDate, String lastLocation,
              RecordStatus status) throws RemoteException {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public String getRecordCounts() throws RemoteException {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void editCRecord(String lastName, String recordID,
              RecordStatus newStatus) throws RemoteException {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>
  
  <p>Client Code::</p>
  
  <pre><code>enter code here
  public class OfficerClients implements Runnable{
      public static void showMenu() {
          System.out.println("\n****Welcome to DPIS****\n");
          System.out.println("Please select an option (1-5)");
          System.out.println("1. Create Criminal Record");
          System.out.println("2. Create Missing Record");
          System.out.println("3. Get Records Count");
          System.out.println("4. Edit Record");
          System.out.println("5. Exit");
      }
  
      public static void main(String[] args) {
          try {
  
              if (System.getSecurityManager() == null) 
                  System.setSecurityManager(new RMISecurityManager());
  
              new Thread(new OfficerClients()).start();
  
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
      private static RecordStatus getRecordStatus(String status, int userChoice) {
          if (userChoice == 1) {
              if (RecordStatus.CAPTURED.name().equals(status))
                  return RecordStatus.CAPTURED;
              else if (RecordStatus.ONTHERUN.name().equals(status))
                  return RecordStatus.ONTHERUN;
              else
                  throw new IllegalArgumentException("Invalid status for Criminal Record");
          } else if (userChoice == 2) {
              if (RecordStatus.FOUND.name().equals(status))
                  return RecordStatus.FOUND;
              else if (RecordStatus.MISSING.name().equals(status))
                  return RecordStatus.MISSING;
              else
                  throw new IllegalArgumentException("Invalid status for Missing Record");
          } else if (userChoice == 3) {
              if (RecordStatus.CAPTURED.name().equals(status))
                  return RecordStatus.CAPTURED;
              else if (RecordStatus.ONTHERUN.name().equals(status))
                  return RecordStatus.ONTHERUN;
              else if (RecordStatus.FOUND.name().equals(status))
                  return RecordStatus.FOUND;
              else if (RecordStatus.MISSING.name().equals(status))
                  return RecordStatus.MISSING;
          }
          throw new IllegalArgumentException("No Enum specified for this string");
      }
  
      private static StationService getRemoteObjectStub(String stationName) {
          String url = "rmi://localhost:";
          Remote lookup = null;
          try {
              if ("SPVM".equals(stationName))
                  url += Constants.SPVM_RMI_PORT;
              else if ("SPL".equals(stationName))
                  url += Constants.SPL_RMI_PORT;
              else if ("SPB".equals(stationName))
                  url += Constants.SPB_RMI_PORT;
  
              url += "/" + stationName;
  
              System.out.println("URL==" + url);
  
              if (url != null &amp;&amp; !url.isEmpty())
                  lookup = Naming.lookup(url);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return (StationService) lookup;
      }
  
      @Override
      public void run() {
          int userChoice = 0;
          String firstName = "", lastName = "", description = "", address = "", lastDate = "", lastLocation = "", badgeID = "", recStatus = "", recordID = "";
          RecordStatus status;
          String requestBadgeID = "Please enter your unique BadgeID: ";
          String requestRecordID = "Please enter RecordID: ";
          String requestFName = "First Name: ";
          String requestLName = "Last Name: ";
          String requestDesc = "Description of Crime: ";
          String requestAddress = "Last Known Address: ";
          String requestDate = "Date last seen: ";
          String requestPlace = "Place last seen: ";
          String requestStatus = "Status: ";
          String requestNewStatus = "New Status: ";
  
          showMenu();
  
          BufferedReader br = new BufferedReader(new InputStreamReader(
                  System.in));
          try{
  
          while (true) {
              Boolean valid = false;
  
              System.out.print(requestBadgeID);
              badgeID = br.readLine().toUpperCase();
              System.out.println(badgeID);
  
              String stationName = badgeID.replaceAll("[0-9]", "").trim();
              System.out.println(stationName);
              StationService server = getRemoteObjectStub(stationName);
  
              while (!valid) {
                  try {
                      System.out.print("Enter your choice: ");
                      userChoice = Integer.parseInt(br.readLine());
                      valid = true;
                  } catch (Exception e) {
                      System.out
                              .println("Invalid Input, please enter an integer: ");
                      valid = false;
                  }
              }
  
              switch (userChoice) {
              case 1:
                  System.out.print(requestFName);
                  firstName = br.readLine().trim().toUpperCase();
                  System.out.print(requestLName);
                  lastName = br.readLine().trim().toUpperCase();
                  System.out.print(requestDesc);
                  description = br.readLine().trim().toUpperCase();
                  System.out.print(requestStatus);
                  recStatus = br.readLine().trim().toUpperCase()
                          .replaceAll("\\s+", "");
                  status = getRecordStatus(recStatus, userChoice);
                  server.createCRecord(firstName, lastName, description,
                          status);
                  showMenu();
                  break;
              case 2:
                  System.out.print(requestFName);
                  firstName = br.readLine().trim().toUpperCase();
                  System.out.print(requestLName);
                  lastName = br.readLine().trim().toUpperCase();
                  System.out.print(requestAddress);
                  address = br.readLine().trim().toUpperCase();
                  System.out.print(requestDate);
                  lastDate = br.readLine().trim().toUpperCase();
                  System.out.print(requestPlace);
                  lastLocation = br.readLine().trim().toUpperCase();
                  System.out.print(requestStatus);
                  recStatus = br.readLine().trim().toUpperCase()
                          .replaceAll("\\s+", "");
                  status = getRecordStatus(recStatus, userChoice);
                  server.createMRecord(firstName, lastName, requestAddress,
                          lastDate, lastLocation, status);
                  showMenu();
                  break;
              case 3:
                  String recordCounts = server.getRecordCounts();
                  System.out.println(recordCounts);
                  showMenu();
                  break;
              case 4:
                  System.out.print(requestLName);
                  lastName = br.readLine().trim().toUpperCase();
                  System.out.print(requestRecordID);
                  recordID = br.readLine().trim().toUpperCase();
                  System.out.print(requestNewStatus);
                  recStatus = br.readLine().trim().toUpperCase()
                          .replaceAll("\\s+", "");
                  status = getRecordStatus(recStatus, userChoice);
                  server.editCRecord(lastName, recordID, status);
                  showMenu();
                  break;
              case 5:
                  System.out.println("Have a nice day!");
                  br.close();
                  System.exit(0);
              default:
                  System.out.println("Invalid Input, please try again.");
              }
          }
          }catch(Exception e){
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>I am new to RMI so I don't have any idea how to maintain each remote object and invoke based on client request and store records in hash table (per remote object).</p>
  
  <p>please help...</p>