The Artima Developer Community
Sponsored Link

Java Answers Forum
Java RMI help needed please

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
romeo

Posts: 1
Nickname: romeo
Registered: Nov, 2002

Java RMI help needed please Posted: Nov 12, 2002 3:34 AM
Reply to this message Reply
Advertisement
I need some help on an assignment on Java RMI (remote method invocation). I have been asked to generate a client, server, interface code for a matrix calculator,
<p>
The remote matrix computation engine should be able to do the following calculations: matrix multiplication, sum of two matrices, and the product of a scalar number and a matrix
<p>
HINTS: Details about matrix calculation rules can be found in the following websites:
<p>
http://hilbert.dartmouth.edu/~m8s00/handouts/matrices3/node2.html
http://hilbert.dartmouth.edu/~m8s00/handouts/matrices3/node3.html
<p>
After much difficulty i managed to successfully generate working code for a standard calculator that subtracts, divides, adds and multiplies two integars,Can someone please help me from here, How can i modify this code so that it fits the role of a matrix computation engine. I have included the code below, Thanks in advance.
<p>


<java>
//Interface: Calculator.java

public interface Calculator
extends java.rmi.Remote {
public long add(long a, long b)
throws java.rmi.RemoteException;

public long sub(long a, long b)
throws java.rmi.RemoteException;

public long mul(long a, long b)
throws java.rmi.RemoteException;

public long div(long a, long b)
throws java.rmi.RemoteException;
}



//The implementation of interface Calculator: CalculatorImpl.java

public class CalculatorImpl
extends
java.rmi.server.UnicastRemoteObject
implements Calculator {

public CalculatorImpl()
throws java.rmi.RemoteException {
super();
}

public long add(long a, long b)
throws java.rmi.RemoteException {
return a + b;
}

public long sub(long a, long b)
throws java.rmi.RemoteException {
return a - b;
}

public long mul(long a, long b)
throws java.rmi.RemoteException {
return a * b;
}

public long div(long a, long b)
throws java.rmi.RemoteException {
return a / b;
}
}



//The Calculator server program: CalculatorServer.java
import java.rmi.Naming;

public class CalculatorServer {

public CalculatorServer() {
try {
Calculator c = new CalculatorImpl();
Naming.rebind("rmi://localhost:1099/CalculatorService", c);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}

public static void main(String args[]) {
new CalculatorServer();
}
}




//The Calculator client program: CalculatorClient.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;

public class CalculatorClient {

public static void main(String[] args) {
try {
Calculator c = (Calculator)
Naming.lookup(
"rmi://localhost/CalculatorService");
System.out.println( c.sub(4, 3) );
System.out.println( c.add(4, 5) );
System.out.println( c.mul(3, 6) );
System.out.println( c.div(9, 3) );
}
catch (MalformedURLException murle) {
System.out.println();
System.out.println(
"MalformedURLException");
System.out.println(murle);
}
catch (RemoteException re) {
System.out.println();
System.out.println(
"RemoteException");
System.out.println(re);
}
catch (NotBoundException nbe) {
System.out.println();
System.out.println(
"NotBoundException");
System.out.println(nbe);
}
catch (
java.lang.ArithmeticException
ae) {
System.out.println();
System.out.println(
"java.lang.ArithmeticException");
System.out.println(ae);
}
}
}
</java>

Topic: help with creating a new fixed length file Previous Topic   Next Topic Topic: Recursive method using StringReverse

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use