001package edu.pdx.cs410J.rmi;
002
003import java.io.PrintStream;
004import java.rmi.NotBoundException;
005import java.rmi.RemoteException;
006import java.rmi.registry.LocateRegistry;
007import java.util.Map;
008
009/**
010 * This program contacts the remote movie database and makes note of a
011 * character in a movie that is played by a given actor.  After the
012 * character is noted, the <code>Movie</code> is fetched from the
013 * database and is printed out.
014 */
015public class NoteCharacter {
016  private static PrintStream out = System.out;
017
018  public static void main(String[] args) {
019    String host = args[0];
020    int port = Integer.parseInt(args[1]);
021    long movieId = Long.parseLong(args[2]);
022    String character = args[3];
023    long actorId = Long.parseLong(args[4]);
024
025    try {
026      MovieDatabase db = (MovieDatabase) LocateRegistry.getRegistry(host, port).lookup(MovieDatabase.RMI_OBJECT_NAME);
027      db.noteCharacter(movieId, character, actorId);
028
029      Movie movie = db.getMovie(movieId);
030      out.println(movie.getTitle());
031      for (Map.Entry entry : movie.getCharacters().entrySet()) {
032        out.println("  " + entry.getKey() + "\t" + entry.getValue());
033      }
034      System.exit(0);
035
036    } catch (RemoteException | NotBoundException ex) {
037      ex.printStackTrace(System.err);
038      System.exit(1);
039    }
040
041  }
042
043}