Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

DISTRIBUTED SYSTEM-CCS21303

Distributed System – CCS21303/ TCS21503


ASSIGNMENT 3

Received Date :
Submission Date :
Weightage : 20 %
Semester : SEPT-2021

Instruction to students:
• This is GROUP assignment.
• Complete this cover sheet and attach it to your assignment (first page).

Student declaration:
I declare that:
• This assignment is my own work
• I understand what is meant by plagiarism
• My lecturer has the right to deduct my marks in the case of:
- Late submission
- Any plagiarism found in my assignment.
No. Name Student ID Report Presentation
1 KATHIKGESU JAYAMANI 012020020841
DISTRIBUTED SYSTEM-CCS21303

ASSIGNMENT 3
CHAPTER /TOPIC: DISTRIBUTED SYSTEM

INSTRUCTION:
1. Report MUST contain minimum pages of 5 and maximum of 10.
2. Each student is required to submit an individual written report that consists of
Content, Conclusion and References
3. Mode: Individual
4. Submission in the form of written report (Hard Copy)
5. Date of Submission: 15 November 2021

** If you have any difficulties in submitting the assignment according to the


date given, please come and discuss with me.

PROGRAM OUTCOME(S):
PO1 Apply computing principles and knowledge in major areas of computer
science. (Knowledge)
PO2 Analyse, design and implement appropriate solutions to meet specifications
using modern computing techniques and tools. (Practical skills)
PO3 Demonstrate familiarity with basic concepts, emerging technologies, and
contemporary issues relating to the societal impacts of computing. (Social
skills and responsibilities)
COURSE OUTCOME(S):
CO1: Design and construct reliable software involving cooperating process on both
uni-processor and multiprocessor system.
CO2: Analyze the problems involved in the design of distributed system.

ANSWER ALL QUESTIONS:


DISTRIBUTED SYSTEM-CCS21303

1. How does a server know that one of his remote objects provided by him is no
longer used by clients and can be collected? How does Java RMI handle this
problem and what alternatives are there?

First of all can put responsibilities for cleaning up objects either on the client or on the server
with or without protocol support. If you leave it to the client it can be risky, just as leaving it
to the server programmer. Hiding it in the protocol also provide the solution for this . By using
these type of similar kind of methodologies a server will be known that one of its private or
remote servers provided by him is no longer used by clients and can be easily collected with
more accuracy in detecting them as well.

Java Remote Method Invocation (RMI) allows you to write distributed objects using
Java.

For an Java RMI client to contact a remote Java RMI server, the client must first hold a
reference to the server. The Naming.lookup method call is the most common mechanism by
which clients initially obtain references to remote servers. Remote references may be obtained
by other means, for example: all remote method calls can return remote references. This is
what Naming.lookup does; it uses a well-known stub to make a remote method call to
the rmiregistry, which sends back the remote reference to the object requested by
the lookup method.Every remote reference contains a server hostname and port number that
allow clients to locate the VM that is serving a particular remote object. Once a Java RMI client
has a remote reference, the client will use the hostname and port provided in the reference to
open a socket connection to the remote server. Please note that with Java RMI the
terms client and server can refer to the same program. A Java program that acts as a Java RMI
server contains an exported remote object. A Java RMI client is a program that invokes one or
more methods on a remote object in another virtual machine. If a VM performs both of these
functions, it may be referred to as an RMI client and a Java RMI server.
DISTRIBUTED SYSTEM-CCS21303

2. What is the purpose of an Interface Definition Language? Why does CORBA


not just use the Java interface construct?

IDL represents Interface Definition Language. Its motivation is to characterize the capacities
of a dispersed assistance alongside a typical arrangement of information types for interfacing
with those appropriated administrations.
IDL meets various targets:
1. Language Independence
2. Disseminated administration detail
3. Meaning of complicated information types
4. Equipment Independence

CORBA is a detail that characterizes how conveyed articles can interoperate. Until the blast in
ubiquity of the World Wide Web, and specifically, the Java programming language, CORBA
was essentially a very good quality, circulated object arrangement fundamentally utilized by
C++ engineers.

3. Two remote objects are related and should be updated in one operation. What
kind of service do you need for this if you assume that both objects can be on
different systems and that multiple operations can happen concurrently?

CompletableFuture is an extension to Java’s Future API which was introduced in Java 5.


CompletableFuture is used for asynchronous programming in Java. Asynchronous
programming is a means of writing non-blocking code by running a task on a separate thread
than the main application thread and notifying the main thread about its progress, completion
or failure.

4. The Lookup operation performs a single-level lookup, returning the Unique


File Identifier (UFID) corresponding to a given simple name in a specified
directory. What is Network File System deviate from one-copy file update
semantics? Why should UFID be unique across all possible file systems?

Network File System provides deviation from one-copy file update semantics, as one-copy file
update semantics allows all the concurrent processes to view the content of the file if there is
only one copy of the file content in existence. Unique file identifier or UFID is unique across
all the possible file systems, as the file groups can be moved and previously distinct distributed
systems can be consolidated to develop one single system.
DISTRIBUTED SYSTEM-CCS21303

5. Write a simple java program to implement RMI.

import java.rmi.Remote;
public interface AddInterface extends Remote {
// Declaring the method prototype
public int add(int x, int y) throws RemoteException;
}
Subli.java
import java.rmi.Remote;
public interface SubInterface extends Remote {
// Declaring the method prototype
public int sub(int x, int y) throws RemoteException;
}
Mull.java
import java.rmi.Remote;
public interface MulInterface extends Remote {
// Declaring the method prototype
public int mul(int x, int y) throws RemoteException;
}
Divl.java
import java.rmi.Remote;
public interface DivInterface extends Remote {
// Declaring the method prototype
public int div(int x, int y) throws RemoteException;
}
Impl.java
import java.rmi.*;
import java.rmi.server.*;
public class Impl extends UnicastRemoteObject
implements AddInterface, SubInterface, MulInterface,
DivInterface {
// Default constructor to throw RemoteException
// from its parent constructor
public Impl() throws Exception { super(); }
// Implementation of the AddInterface,
// subInterface, MulInterface, and DivInterface
public int add(int x, int y) { return x + y; }
public int sub(int x, int y) { return x - y; }
public int mul(int x, int y) { return x * y; }
public int div(int x, int y) { return x / y; }
}
Server.java
import java.rmi.*;
import java.rmi.registry.*;
public class Server {
public static void main(String[] args) throws Exception
{
// Create an object of the interface
// implementation class
Impl obj = new Impl();
// Binds the remote object by the name ADD
DISTRIBUTED SYSTEM-CCS21303

Naming.rebind("ADD", obj);
System.out.println("Server Started");
}
}
Client.java
import java.rmi.*;
import java.util.*;
public class Client {
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner(System.in);
while (true) {
// User Menu
System.out.println(
"\n1.Addition\n2.Substraction\n3.multiplication\n4.division\n5.Exit");
System.out.println("Enter the option:");
int opt = sc.nextInt();
if (opt == 5) {
break;
}
System.out.println(
"Enter the the first number:");
int a = sc.nextInt();
System.out.println("Enter the second number:");
int b = sc.nextInt();
int n;
switch (opt) {
case 1:
// lookup method to find reference of remote
// object
AddInterface obj
= (AddInterface)Naming.lookup("ADD");
n = obj.add(a, b);
System.out.println("Addition= " + n);
break;
case 2:
SubInterface obj1
= (SubInterface)Naming.lookup("ADD");
n = obj1.sub(a, b);
System.out.println("Substaction= " + n);
break;
case 3:
MulInterface obj2
= (MulInterface)Naming.lookup("ADD");
n = obj2.mul(a, b);
System.out.println("Multiplication = " + n);
break;
case 4:
DivInterface obj3
= (DivInterface)Naming.lookup("ADD");
n = obj3.div(a, b);
DISTRIBUTED SYSTEM-CCS21303

System.out.println("Division = " + n);


break;
}
}
}
}
DISTRIBUTED SYSTEM-CCS21303

Lab 3 Answer

Rmi Interface

import java.rmi.*;

interface ReceiveMessageInterface extends Remote{


void receiveMessage(String x) throws RemoteException;
}

Rmi Client

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class RmiClient{


static public void main(String args[]){
ReceiveMessageInterface rmiServer;
Registry registry;
System.out.println("Assignment 3");
System.out.println("Name:Kathikgesu Jayamani ID:012020020841");
System.out.println("");
String serverAddress=("192.168.0.151");
String serverPort=("8080");
String text=("Hye There, Kathikgesu Here!");
System.out.println
("sending " + text + " to " +serverAddress + ":" + serverPort);
try{
registry=LocateRegistry.getRegistry
(serverAddress,(new Integer(serverPort)).intValue());
rmiServer=(ReceiveMessageInterface)(registry.lookup("rmiServer"));
// call the remote method
rmiServer.receiveMessage(text);
}
catch(RemoteException e){
e.printStackTrace();
}
catch(NotBoundException e){
System.err.println(e);
}
}}
DISTRIBUTED SYSTEM-CCS21303

RMI Server

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;

public class RmiServer extends


java.rmi.server.UnicastRemoteObject implements ReceiveMessageInterface{
String address;
Registry registry;

public void receiveMessage(String x) throws RemoteException{


System.out.println(x);
}

public RmiServer() throws RemoteException{


try{
address = (InetAddress.getLocalHost()).toString();
}
catch(Exception e){
System.out.println("can't get inet address.");
}
int port=8080;
System.out.println("this address=" + address + ",port=" + port);
try{
registry = LocateRegistry.createRegistry(port);
registry.rebind("rmiServer", this);
}
catch(RemoteException e){
System.out.println("remote exception"+ e);
}
}
static public void main(String args[]){
try{
RmiServer server = new RmiServer();
}
catch (Exception e){
e.printStackTrace();
System.exit(1);
}
}
}
DISTRIBUTED SYSTEM-CCS21303

ASSESSMENT:
Report will be evaluated based on the rubric attached
DISTRIBUTED SYSTEM-CCS21303

Report Assessment Rubrics (Assignment 3)


Name: KATHIKGESU JAYAMANI
Matrix No: 012020020841
Semester: SEPT-2021
Needs Below
Proficient Excellent Mark
Category Improvement Average/Developing
6-8 mark 9-10 mark s
0-2 mark 3-5 mark
Cannot understand Difficult to follow Information in Information in logical,
questions--no questions--student logical sequence interesting sequence
Organization /5
sequence of jumps around
information
Some relevant facts Facts identified, but Student covers Unavailable facts that
Knowledge of Topic not identified. some may not be most (at least 4) of were relative to the
and all parts of project Student is missing relevant to case or may required areas in ethical outcome were
are represented most of the required be slightly project, but a few also identified.
areas (3 or more) in misinterpreted. Student points are missing Facts were
1. Summary of the project. Pages is missing more than a and not explained assembled before. All
Person/Company contain little to no few (2 or 3) required fully. Student mostly five required areas
2. Define and explain information and the are as in the project. provides details are represented in
code of ethics and student does not Ethics and Law is not which show they did project. Student
Law elaborate on any fully explained. Less above average provides detail which
points outside of the than most of the research on the shows they did /10
3. Describe the
ethical issues report. Student did information contained person/ company sufficient research on
4. Able to Explain a very little research in the project is chosen and most of the person/company
situation for on a person/ accurate and justified. the computer chosen as well as the
potential ethical company for the crimes are Ethics and Law
problems project. explained and involved.
5. Identify the justified.
affected parties
(stakeholders)

Writing lacks logical Writing is coherent and Writing is coherent Writing shows high
organization. It logically organized. and Logically degree of attention to
shows some Some points remain organized with logic and reasoning of
coherence but ideas misplaced and transitions used points. Unity clearly
Organization /10
lack unity. Serious stray from the topic. between leads the reader to
errors. ideas and the conclusion and
paragraphs to stirs thought.
create coherence.
Does not justify Presents only evidence Uses a variety of Uses a variety of
conclusions with that supports a sources in reaching sources in reaching
Research /5
research evidence preconceived point of conclusions accurate conclusions
view
Presenter didn’t Student showed good Student showed a Extensive knowledge
understand topic. understanding of some good understanding of topic. Accurately
Comprehension Majority of parts of topic. of topic. answered all /10
questions answered questions posed.
incorrectly.
Following format, Following format and Following format, Not following format
include table of include reference but there is no and there is no
Formatting content, title of each reference reference /10
topic and include
reference

Total 50

You might also like