Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: RMI Java project

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry RMI Java project

    I have no idea how to do this...any help or snippets of code to get me on the right track would be most appreciated!
    Last class before graduation...I am not a programmer and have the up most respect for everyone in this field....

    For Step 2 of the RMI project you need to implement a non-distributed version of the application utilizing 2 components: Input/Output (IO) module and Process Coordinator (PC). The former is responsible for all I/O operations and the latter is to provide a service of remote matrix multiplication.

    I/O Module:
    1.Create a class, containing main() method which accepts command-line arguments. Name the class IO to honor function of the module.
    2.Read an integer to be used as length of all 3 square matrices as a command-line argument. For example running java IO.IO 15 needs to be interpreted as passing N=15 where all matrices are assumed to be of dimension 15x15. It is assumed here that class IO is placed into a package named IO, that's why you run java IO.IO ... and not just java IO ... In case you don't want to deal with packages --- it is completely up to you, no points will be deducted.
    3.Fill in 2 matrices A and B randomly generated integers in the range from -100 to +100. In case when matrices dimensions are appropriate (small enough) -- print both matrices. In any case, save both matrices into a text file while separating entries of the same row by a space or a tab and separating rows by a new line character, i.e. \n. Save each matrix in a separate file (we will use these files later on Step 3 to evaluate correctness of the result).
    4.Locate a registry, running on the PC side (IP address or hostname can be passed as the 4th command-line argument or to be hardcoded). In case that the registry cannot be located, the I/O program must be exited with error message.
    5.Lookup for a particular name (to be specified on the PC site) in the located registry and obtain a reference to the remote object registered on PC.
    6.Invoke remote method mult() which takes 2 matrices (objects of class Matrix which you need to develop or simply 2-dimensional arrays of integers, i.e. int[][]) and returns their product, i.e. another matrix of whichever type you used to specify method's params.
    7.Resulting matrix C, returned by the remote method needs to be displayed (in case it fits the screen) and saved into a text file, using the same format as for matrices A and B.


    PC module:
    1.Create a class, containing implementation of the remote method mult() to be used by I/O. This method needs to be able to multiply two matrices and return the resulting one. The class needs to be declared as extends UnicastRemoteObject implements <name of the interface>, where <name of the interface> is suggested to reflect the fact that a service is provided by PC to IO, for example PC2IO is a good candidate to name such an interface. Following the logic of naming the interface, the logic implementing class can be named to honor the fact that it contains implementation of the remote method, i.e. PC2IO_Impl. Have in mind that method mult() must be declared as throwing RemoteException, otherwise you will not be able to remotely invoke this method by means of RMI.
    2.Create another class, call it PC (for instance). This class will have main() method. Within main() method:
    1.Create object of class PC2IO_Impl
    Note: Have in mind that such an object must be declared as of type PC2IO (interface) but needs to be created by calling constructor of class PC2IO_Impl.
    2.Create new or obtain a reference to already existing Registry.
    Note: At first you need to make an attempt to create a Registry. This operation may fail for many reasons, for example, when Registry does already exist. In case of failure, an exception will be thrown, so you need to catch and handle it. In the attempt to handle such thrown exception you need to try to re-use existing Registry. In case of success just use the obtained reference to the existing Registry, otherwise, in case of failure, you need to inform the user that PC cannot start (it is useless without available Registry).
    3.Bind the newly created PC2IO_Impl object with some particular name (see above, in the description of the IO module) in the Registry.
    Note: Following the introduced naming convention, a good name would be "PC2IO".


    Overview of the operations:

    Having all classes (PC, IO, PC2IO_Impl) and shared interface (PC2IO) created, you will need to run PC first. The next step is to run IO so it will generate random matrices A and B, will contact PC, will invoke remote method mult(), and finally will optionally print and save result of matrix multiplication. Both programs can be run either on the same or different computers. In former later case, IP address of the PC needs to be known on the IO side (hardcoded or passed as a command line argument). Also, in case of having both programs running on different computers, the existence of PC2IO interface on both sides must be enforced.


  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: RMI Java project

    what have done so far?

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RMI Java project

    Hello!

    Thanks for taking a look!

    Step1

    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import java.rmi.Naming;
    import java.io.PrintStream;
    import java.io.File;
    import java.io.FileNotFoundException;


    class IO {
    public static void main(String args[]) {
    if(args.length < 1) {
    System.err.println("Need at least one integer parameter to denote matrix size");
    System.exit(1);
    }
    int N = 0;
    try {
    N = Integer.parseInt(args[0]);
    }
    catch (Exception e) {
    System.err.println("Command-line parameter must be of type integer to represent size of the matrix");
    System.exit(2);
    }

    int [] A = new int[15];
    int [] B = new int[15];

    java.util.Random rn = new java.util.Random();
    for (int i=0; i < A.length; i++) A[i] = rn.nextInt(20) + 1;
    for (int i=0; i < A.length; i++) System.out.print( A[i] + " " );
    for (int i=0; i < B.length; i++) B[i] = rn.nextInt(20) + 1;
    for (int i=0; i < B.length; i++) System.out.print( B[i] + " " );

    try (
    PrintStream output = new PrintStream(new File("output.txt"));
    ){

    for(int i =0;i<A.length;i++){
    String sc ="";
    for (int i=0;i<A[i].length;i++){
    sc+=A[i][i]+" ";
    }
    output.println("random numbers matrix A " + A[i] + " random numbers matrix B " + sc + B[i]);
    }
    output.close();

    } catch (FileNotFoundException e) {

    e.printStackTrace();
    }


    }
    }

    Step 2


    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.rmi.RMISecurityManager;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.*;

    public class PC extends UnicastRemoteObject implements PC2IO{
    int i,j,k;
    int c[][]=new int[2][2];


    public void mult(int a[][],int b[][]) throws RemoteException
    {
    System.out.println("Matrix Multiplication:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    c[i][j]=a[i][j]*b[i][j];
    System.out.print(c[i][j]+" ");
    }
    System.out.println();
    }
    }
    public static void main(String args[]) {
    try { //special exception handler for registry creation
    LocateRegistry.createRegistry(1099);
    System.out.println("java RMI registry created.");
    } catch (RemoteException e) {
    //do nothing, error means registry already exists
    System.out.println("java RMI registry already exists.");

    }

    }
    }

    Step 3



    import java.rmi.Remote;
    import java.rmi.RemoteException;

    public interface PC2IO() extends Remote {
    public String getMult() throws RemoteException;

    }

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: RMI Java project

    i dont have a clue on this topic but im sure someone will be able to help you, i only asked cus that would have been the reply you got from anyone who would help you.
    good luck

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RMI Java project

    you are right....thanks!

Similar Threads

  1. Java RMI eclipse BANK, help!
    By klskl in forum Object Oriented Programming
    Replies: 2
    Last Post: November 23rd, 2013, 01:54 PM
  2. java rmi and socket programming
    By sumit kumar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 21st, 2013, 12:28 AM
  3. Java Socket and RMI programming help
    By Yogesh4591 in forum Java Networking
    Replies: 0
    Last Post: November 17th, 2012, 10:57 PM
  4. JAVA RMI question
    By rlk in forum Java Networking
    Replies: 6
    Last Post: March 21st, 2012, 02:22 PM
  5. How can I get Remote Address from Object? (Java RMI)
    By sahin in forum Java Networking
    Replies: 1
    Last Post: February 4th, 2012, 10:02 PM

Tags for this Thread