Print Email Download Reference This Send to Kindle Reddit This
submit to reddit

Lottery Program Java

Aim:-To prepare a lottery program in java by using RMI mechanism and report that describe REMOTE METHOD INVOCATION (RMI).3

Abstract:-

This report implements a distributed application using java RMI. The main purpose of this report is just to investigate and study of remote method invocation and their structure. Where In the RMI program that is well known middle wear frame work I used in two files one belongs to the server and another belongs to client .where server does not know any thing abut the client and client keep some little information about the server. Also message interface is providing the interface services between server and class in this report I am describing the RMI structure functionality and reliability and using protocol to make them RMI communication possible.

Aim:-To prepare a lottery program in java by using RMI mechanism and report that describe REMOTE METHOD INVOCATION (RMI).

Objective:-

The objectives of the report are to attain:

Introduction:-

there are thousand of different processor connected with each other .where object invocation allow to java virtual machine to locate and run another java virtual machine located any where else .this extremely important technology makes possible to distribute the load across other distribute machine that can be one. In short java RMI is a remote procedure call.

RMI application are divided into two parts .server, client. That gives you very easy solution.

This report explores the brief discussion about the java RMI and how the lotto programmes has been define in order to use RMI technology. Where three entities are involved in running program that java RMI use.

Back ground:-

Distributed need a computation process in different address space in order to make communication in different host? Java language in one of the best plate form to communicate communication mechanism that support RMI and RPC and socket programming. Java remote method provides integrated and reliable communication via remote method calls.

In RMI back ground process and entities participate in three different orders to translate RMI set up

(1)Client (2) server (3) object registry

1) Client: this is the program that has been written to access remote method.

2) Server:-at the server side this program is to write an object method client put their request for this remote object to the server to be executed.

3) Object registry: - object registry classify object is registered and it will run on known port (by default) client must contact to make their access successful to remote object before invoking the remote method.

How RMI Works:-

Remote method invocation is a mechanism for communication that's basically run between two machines that is basically running on java virtual machine.

For example:

There are two machines that are running on java. when java code on machine A need method then B translate it self as an java object method .the whole back end communication process between machine A and B is done by remote method invocation in this example the behind running procedure client and server make connection through special classes stub and skeleton .stub run on client side and skeleton run on server side.

These two program act as a middle ware.

Middle ware:-

Middle ware act like a glue or connectivity soft ware between two applications generally is it soft ware that does not have a user interface and that gives multiple process interact and exchange of data between systems.

Stub and skeleton programming in java:-

Stub and skeleton is a frame work and standard communication system that will not have to deal with network and socket programming .RMI stub and skeleton provides import interface and skeleton in RMI programming where client application program invoke the server side component and skeleton act as an interface means performing the job of marshalling and un marshalling

THE STUB AND SKELETON PRESENTATION

RMI

Skeleton Server

RMI Client stub

CALL

RETURN

Marshalling represent data or object into byte stream and de marshalling represent conversion of byte stream into data and object.

RMI layered architecture:-

RMI (remote method architecture) is based on three layered architecture every layer has got their own functionality and independency. None of the layered effect on each other in order to enhancement even you are making a UDP connection as well.

Very first layered that belong to the stub and skeleton layer thus layer act like an interface reference variable and redirect the remote call toward the remote services.

The 2nd layered in RMI translate their job to intercept and manage references made from client side.

And the third layered in RMI system that makes complete RMI system is TCP/IP that provide a basic connectivity and fire wall prevention strategies even in the face of networking obstacles.

RMI PROTOCOL:

Java RMI at least three level of protocol. On the top TCP/IP protocol RMI uses JRMP (java remote method protocol) protocol .this wire level stream base protocol consist of two different level one of them is JDK 1.1 first version that basically require skeleton classes and the 2nd version protocol is 2SDK that does not require skeleton classes.

New released version is RMI-IIOP that is using object management (OMG) instead of JRMP in order to communicate server and client.

Explanation for lottery program:-

Lottery program in java by using RMI in client server mechanism that perform the operation each time when client run program and give any number to generate the 6 random number set of lottery number then server program generates n sets of lottery number.

The lottery number consists of following files.

1) MESSAGE RECEIVE INTERFACE

2) RMI SERVER

3) RMI CLIENT

MESSAGE RECEIVES INTERFACE.JAVA:-

This part represent the remote method invocation .where the method receive message belongs to server class implements this interface known as remote client .this lottery program where remote client program type server class is the interface.

RMI SERVER.JAVA:-

In the 2nd part of this lottery program the RMI server program having a class where we defined the method is remote client. This RMI server class is the implementation of the RMI interface.

RMI CLIENT.JAVA:-

This class belongs to client program class. Where class translating their job to call REMOTE METHOD.

Execution out line for the lottery program:-

Execution of the lottery program are given below

Compile source code.

javac LotteryServer.java

javac MessageInterface.java

javac LotteryClient.java

2) rmic LotteryServer

EXECUTION: _

1) Run,

Java LotteryServer

2) On different command prompt

Java Lottery Client 5 (Note: here 5 could be any amount you want to play).

Difference between RPC and RMI:-

Distributing computing is playing vital and lead role in the electronics communication from last couple of year. Where main frame, dumb terminal and finally intelligent client and worked station led the revolution concept in network technology and distributed system. Here I am talking about the RPC and RMI. in both technology the common word is “REMOTE”. Where RPC is the predecessor of RMI same like oracle 7 is predecessor of oracle 8.or we can that RMI is totally based on previous technology RPC That

Developed in 980.

RPC (remote procedural call):-

REMOTE PROCEDURAL CALL (RPC is a power full technique) that allows a procedural programming for constructing the distributed client server based program RPC allow a procedural program language to call a function .calling argument is being passed from the remote procedure and the caller wait the feed back response from the remote procedure .

RPC translate their job in order to marshalling and networking of data.

For example: - packaging of function specification and enhancing the argument and return all these values over the network.

RMI (remote method invocation):-

RMI remote method invocation) is the predecessor, simplest and direct model of distributed communication and RPC .once a object is register that belong to the method of java being remotely accessed that client start to look up the server side to use the service after receiving the interface reference. In RMI marshalling of data is controlled by RMI .where system of method call is identical in order to call a object method in same program. Like a RPC in RMI the program need to be concerned with the transmission of data across the network. RMI does not keep the requirement for any developer to learn interface definition language (IDC). Because RMI is just supporting to one language. RMI is just giving the facility of truly and solid object oriented distributing computing. RMI is expandable plate form that provides all benefits transfer of object of complex data type. Low maintenance cost and secure environment.

ADVANTAGES AND DIS ADVANTAGES: _

RMI keep preference over RPC. At very initial and basic level RMI is belong to RPC.

RPC system is does support to procedural language system and essentially least common denominator system. So it cannot provide the functionality that is not available all possible target plate form.

RMI that using the native system focused on purely java that has fully approach to provide distributed communication technology java RMI keep across plate form portable feature where RPC require a lot more over head then RMI.

Algorithm fro server:-

Algorithm for Client:-

FLOW DIAGRAM FOR LOTERY PROGRAM:-

Start

Flow Diagram for the Server

int thisPort;

String thisAddress

Registry registry;

public Vector sentreceiveMessage(int x)

System.out.println("Received request to play for £"+x);

System.out.println("Processing...");System.out.println("Processing...");

Vector mainVec=new Vector()

for(int m=0;m<x;m++)

Vector vArr=generateNos(5); mainVec.add(vArr);

System.out.println("Process Finished!")

return mainVec

END

GENERATES number

Vector vNo=new Vector()

List<Integer> numbers = new ArrayList<Integer>()

for (int i = 0; i <= 49; i++)

{ numbers.add(i)

Collections.shuffle(numbers)

for(int=0;p<=5;p++)

vNo.add(numbers.get(p))

return vNo

thisAddress= "127.0.0.1"

System.out.println("Lottery Server running at address="+thisAddress+",port="+thisPort)

End

LotteryServer s=new LotteryServer()

Main

registry.rebind("rmiServer", this)

registry = LocateRegistry.createRegistry( thisPort )

Start

Flow Diagram for the Client

MessageInterface rmiServer

Registry registry

String serverAddress="127.0.0.1"

String serverPort= "3232"

int amount=Integer.parseInt(args[0])

println("sending request to "+serverAddress+":"+serverPort)

registry=LocateRegistry.getRegistry(

serverAddress,

(new Integer(serverPort)).intValue()

Rmi server=(messageinterface)(registery.look up(“rmiserver”)

Vector noArr= rmiServer.sentreceiveMessage(amount)

for(int x=0;x<noArr.size();x++)

END

NO

YES

System.out.println("Lottery Numbers: "+noArr.get(x))

Conclusion: -

As represented report shows when using RMI communication in between the lottery program is quit simple and far greater by using RMI technique.

In this program host computer is not doing any thing but client side is working. Also this whole report expressing itself about the RMI server client and architecture and using protocol that makes possible communication between server and client.

Assignment plan:-

To complete this assignment we have to follow below schedule:

Assignment Schedule

Tasks Description

Duration (Hours)

Understand key issues

Java RMI AND RPC

10

Understand System

Understand principle and existing system of lottery program

20

Literature Search

Investigate technology system, white paper, journal, article, interaction design criteria, understanding the main ethical behind this technology, and decide when and how they should be applied to maintain.

30

Examine & Testing of lottery program

10

Testing

Overview of all the assignment and changing's

20

Recommendations

Recommend future work on the lottery system and report and how it may be improved and

20

Final Project Submission Date: - 7 May 2008

Total 110 hours

The attached plan shows these activities and the hours allocated to them. The schedule provides for study, giving average of about 16 hours study per week. The work structure and Gantt chart detailing project plan is attached with this report.

Gantt chart

Tasks

1

2

3

4

5

6

Total Hours

Understand Key

10

Understand System

20

Literature Search

30

Examine & Testing all research

10

Testing

20

Recommendation

20

Total Hours 110To Complete Final Report

110

REFRENCES:-

(Note: All these references were accessed between 20th April, 2008 and 6th may , 2008)

[1] eent3.lsbu.ac.uk/staff/xiaop/DSI/lab/RMI_Tutorial%201.pdf

[2] www.cs.kent.edu/~farrell/grid06/ass/RMI.html

[3] www.engr.mun.ca/~baxter/Publications/Steps2RMI.pdf

[4] java.sun.com/j2se/1.3/docs/guide/rmi/spec/rmiTOC.html - Cached

[5] www.cs.rutgers.edu/~pxk/rutgers/notes/content/rb-rmi.pdf

[6] answers.yahoo.com/question/index?qid=1006020703932

[7] 42.fht-esslingen.de/~adrian/master/rmi.pdf -

[8] yama-linux.cc.kagoshima-u.ac.jp/~yamanoue/researches/java/rmi-ex2/ - 59k -

[9] java.ittoolbox.com/pub/HS021003A.pdf

APPENDIX:-

Lottery program for server

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;

import java.util.Random;

import java.util.*;

public class LotteryServer extends java.rmi.server.UnicastRemoteObject

implements MessageInterface

{

int thisPort;

String thisAddress;

Registry registry; // rmi registry for lookup the remote objects.

// This method is called from the remote client by the RMI.

// This is the implementation of the “MessageInterface”.

public Vector sentreceiveMessage(int x) throws RemoteException

{

System.out.println("Received request to play for £"+x);

System.out.println("Processing...");

Vector mainVec=new Vector();

for(int m=0;m<x;m++){

Vector vArr=generateNos(5);

mainVec.add(vArr);

}

System.out.println("Process Finished!");

return mainVec;

}

/* Generate and add numbers b/w 0-49 in vector */

private Vector generateNos(int no){

Vector vNo=new Vector();

List<Integer> numbers = new ArrayList<Integer>();

for (int i = 0; i <= 49; i++){ numbers.add(i);}

Collections.shuffle(numbers);

for(int p=0;p<=5;p++){

vNo.add(numbers.get(p));

}

return vNo;

}

public LotteryServer() throws RemoteException

{

try{

// get the address of this host.

// thisAddress= (InetAddress.getLocalHost()).toString();

thisAddress= "127.0.0.1"; // to run on localhost

}

catch(Exception e){

throw new RemoteException("can't get inet address.");

}

thisPort=3232; // this port(registry's port)

System.out.println("Lottery Server running at address="+thisAddress+",port="+thisPort);

try{

// create the registry and bind the name and object.

registry = LocateRegistry.createRegistry( thisPort );

registry.rebind("rmiServer", this);

}

catch(RemoteException e){

throw e;

}

}

static public void main(String args[])

{

try{

LotteryServer s=new LotteryServer();

}

catch (Exception e) {

e.printStackTrace();

System.exit(1);

}

}

}

Lottery program for client:-

import java.rmi.*;

import java.rmi.registry.*;

import java.net.*;

import java.util.Vector;

public class LotteryClient

{

static public void main(String args[])

{

MessageInterface rmiServer;

Registry registry;

String serverAddress="127.0.0.1";

String serverPort= "3232";

int amount=Integer.parseInt(args[0]);

System.out.println("sending request to "+serverAddress+":"+serverPort);

try{

// get the “registry”

registry=LocateRegistry.getRegistry(

serverAddress,

(new Integer(serverPort)).intValue()

);

// look up the remote object

rmiServer=

(MessageInterface)(registry.lookup("rmiServer"));

// call the remote method

Vector noArr= rmiServer.sentreceiveMessage(amount);

for(int x=0;x<noArr.size();x++){

System.out.println("Lottery Numbers: "+noArr.get(x));

}

}

catch(RemoteException e){

e.printStackTrace();

}

catch(NotBoundException e){

e.printStackTrace();

}

}

}

Message interface program:-

import java.rmi.*;

import java.util.Vector;

public interface MessageInterface extends Remote

{

Vector sentreceiveMessage(int x) throws RemoteException;

}

Print Email Download Reference This Send to Kindle Reddit This

Share This Essay

To share this essay on Reddit, Facebook, Twitter, or Google+ just click on the buttons below:

Request Removal

If you are the original writer of this essay and no longer wish to have the essay published on the UK Essays website then please click on the link below to request removal:

Request the removal of this essay.


More from UK Essays