Grid technology & security

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

1. Interfaces

The first step is to compile the Java code for the interface. The program initializes all of the remote characteristic offered by the service:

Notice this program extends Remote, and each routine declares that it may throw a Remote Exception object.

Compile the program with the Java compiler:

javac Calculator

2. Implementation

Next, you write the implementation for the remote service. This is the CalculatorImpl class:

The CalculatorImpl class uses UnicastRemoteObject to link into the Remote Method Innovation. In this program the implementation class directly extends UnicastRemote Object. A class that does not extend UnicastRemote Object may use its exportObject() method to be linked into Remote Method Innovative..

When a class extends UnicastRemoteObject, it must provide a constructor that declares that it may throw a RemoteException object. When this constructor calls super(), it activates code in UnicastRemoteObject that performs the RMI linking and remote object initialization.

3. Stubs and Skeletons

The rmic compiler creates stub and skeleton class files (JRMP protocol), and stub and attach class files (IIOP protocol) for remote objects. These classes are generated from the compiled Java programming language contains remote object implementations. A remote object is one that execute the java.rmi.Remote.

You next run the RMI compiler, rmic, to create the stub and skeleton files.

>rmic CalculatorImpl

Try this in your directory. After you run rmic you should find the file CalculatorStub and, if you are running the Java 2 SDK, CalculatorSkel.

4. Host Server

Remote method innovative services must be hosted in a server process. The Calculator class Server is a very straightforward server that offers the bare prerequisites for hosting.

5. Running the RMI System

Now run the program. You need to start 3 consoles,

  1. CalculatorServer
  2. CalculatorClient
  3. Remote Method Innovative Registry.

Start with the remote method innovative Registry. You must be in the path that contains the classes you have compiled.

Start rmiregistry

Registry will start running and you can move to the second console.

Start the calculator server containing the CalculatorService,

java CalculatorServer

Calculator Server will initiate, and execute the implementation into memory and wait for client request.

In the third console, start the calculator client program.

java CalculatorClient 2 + 3

Java CalculatorClient 4 - 2

Java CalculatorClient 4 / 2

Java CalculatorClient 4 x 2 OR >Java CalculatorClient 4 X 2

Java CalculatorClient 4 p 2 OR >Java CalculatorClient 4 P 2

You must take care of spaces between the arguments

>Java CalculatorClient(Space)(number1)(space)(operator)(space)(number2)

Calculator.Java

public interface Calculator

extends java.rmi.Remote

{

public double calculate(double a, String o, double b)

throws java.rmi.RemoteException;

public String showOperators()

throws java.rmi.RemoteException;

}

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();

}

}

CalculatorImpl.Java

import java.util.ArrayList;

public class CalculatorImpl

extends

java.rmi.server.UnicastRemoteObject

implements Calculator {

public static ArrayList list = new ArrayList();

public CalculatorImpl()

throws java.rmi.RemoteException {

super();

}

public double calculate(double a, String o, double b)

throws java.rmi.RemoteException {

if(o.equals("+")) {

list.add(o);

if(list.size() > 5)

list.remove(0);

return a + b;

} else if(o.equals("-") )

{

list.add(o);

if(list.size() > 5)

list.remove(0);

return a - b;

} else if(o.equals("x") || o.equals("X"))

{

list.add(o);

if(list.size() > 5)

list.remove(0);

return a * b;

} else if(o.equals("/"))

{

list.add(o);

if(list.size() > 5)

list.remove(0);

return a/b;

}else if(o.equals("p")|| o.equals("P"))

{

list.add(o);

if(list.size() > 5)

list.remove(0);

return Math.pow(a,b);

} else

return 0;

}

public String showOperators()

throws java.rmi.RemoteException

{

String s="";

for(int i=0; i<list.size(); i++)

{

s = s + ", " + list.get(i);

}

return s;

}

}

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");

double a = Double.parseDouble(args[0]);

double b = Double.parseDouble(args[2]);

String op = args[1];

System.out.println("your calculation is : " + c.calculate(a,op,b));

System.out.println("Operators Used: " + c.showOperators());

}

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);

}

}

}

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.