The K Zone, Home

About Me

K View

Projects

Papers

Gallery

Email

 

 

 
 

Evaluation of RMI - Page 5

 

Back to Contents Page

 
 

 

3. Comparison of Client/Server Model Implementation

For this part of the report we will construct a series of client/server models. Each model will possess the same functionality but will use a different remote communications mechanism. The aim is to demonstrate the comparative implementation issues of RMI versus alternative mechanisms. Since RMI can only be used in the Java environment applications will be coded in Java.

3.1 Description of Application

The purpose of the application model is to test the primality of numbers. The application offers three services:

isPrime() - tests if an argument is prime by checking if it is less than 2, if it is greater than 2 but can be divided by 2 then it is not prime. Figure 4 illustrates the implementation of the isPrime() method.

public static boolean isPrime(long n){
if (n < 2 || n > 2 && n%2 == 0) return false;
long m = (long)Math.sqrt(n) + 1;
for (long i = 3; i <= m; i += 2)
if (n%i == 0) return false;
return true;
}

Figure 4. isPrime() method


gcd() - calculates the gcd of a pair of arguments using Euclid's algorithm. Figure 5 illustrates the implementation of the gdc() method.

public static long gcd(long u, long v){
for ( ; ; ) {
long r = u % v;
if (r == 0) return v;
u = v;
v = r;
}
}

Figure 5. gcd() method

lcm() - calculates the product of a pair of arguments divided by their gcd. Figure 6 illustrates the implementation of the lcm() method.

public static long lcm(long u, long v){
return u*v/gcd(u,v);
}

Figure 6. lcm() method

Each implementation of the application will accept three arguments at the client side. The first of these arguments will be applied to the isPrime() method while the latter two will be applied to the gcd() and lcm() methods.

 

Next Page

 

 

Home | About Me | K View | Projects | Papers | Gallery | Email