Professional Documents
Culture Documents
Session 2019-2020
I.E.T.BU;Jhansi (161381030040)
CONTENTS
S.No. Program Page no.
1. Design and implemention RMI using Java 3
2. Design and implemention of a sequencer 6
multicast protocol using java
2
Program -1
Design and implemention RMI using Java
Step1: Creating a Search interface
// Creating a Search interface
import java.rmi.*;
public interface Search extends Remote
{
// Declaring the method prototype
public String query(String search) throws RemoteException;
}
Step 2: Implementing the remote interface
// Java program to implement the Search interface
import java.rmi.*;
import java.rmi.server.*;
public class SearchQuery extends UnicastRemoteObject
implements Search
{
// Default constructor to throw RemoteException
// from its parent constructor
SearchQuery() throws RemoteException
{
super();
}
// Implementation of the query interface
public String query(String search) throws RemoteException
{
String result;
if (search.equals("Reflection in Java"))
result = "Found";
else
result = "Not Found";
return result;
}
}
Step 3: Creating Stub and Skeleton objects from the implementation class using rmic
3
public static void main(String args[])
{
try
{
// Create an object of the interface
// implementation class
Search obj = new SearchQuery();
// rmiregistry within the server JVM with
// port number 1900
LocateRegistry.createRegistry(1900);
// Binds the remote object by the name
// geeksforgeeks
Naming.rebind("rmi://localhost:1900"+"/geeksforge
eks",obj);
}
catch(Exception ae)
{
System.out.println(ae);
}
}
}
Step 6: Create and execute the client application program
4
5
Program -2
Design and implemention of a sequencer multicast protocol
using java
Sequencer.java (complete)
package sequencer;
import java.rmi.*;
import java.net.*;
import java.io.*;
// leave -- tell sequencer that "sender" will no longer need its services
public void leave(String sender) throws RemoteException;
// getMissing -- ask sequencer for the message whose sequence number is "sequence"
public byte[] getMissing(String sender, long sequencer)throws RemoteException,
SequencerException;
SequencerJoinInfo.java (complete)
package sequencer;
import java.io.*;
import java.net.*;
6
public InetAddress addr;
public long sequence;
package sequencer;
import java.io.*;
package sequencer;
import java.net.*;
import java.util.*;
import java.io.*;
import java.rmi.*;
7
public void leave()
{
// leave group
}
}
8
Program-3
Design and implemention of a Task Bag Server using CORBA
or java RMI
module tasks
{
interface TaskReadyCallback
{
oneway void taskReady();
};
interface TaskMasterControllerCallbacks
{
oneway void taskStarted(in string workerName, in string task);
oneway void taskFinished(in string workerName, in string task);
oneway void addWorker(in string workerName);
oneway void removeWorker(in string workerName);
};
interface TaskBag
{
oneway void pairOut(in string key, in string value);
oneway void pairOutTask(in string key, in string value);
oneway void pairOutResult(in string key, in string value, in string workerName);
string pairIn(in string key);
string pairInTask(in string key, in string workerName);
string readPair(in string key);
void clear();
void registerTaskMasterCallbacks(in TaskMasterControllerCallbacks callback);
void addWorker(in string workerName, in TaskReadyCallback callback);
void removeWorker(in string workerName);
};
};
9
Program-4
Use of unix interface to UDP sockets to implement a simple
RPC framework in C++
class Message {
public:
Message(unsigned char *, unsigned int ); // message and
length supplied
Message(unsigned int ); // length supplied
private:
unsigned char * data;
unsigned int length;
};
class Socket {
public:
Socket();
Socket(int); // port given as argument
status UDPsend(UDPMessage *m, SocketAddress *
destination);
status UDPreceive(UDPMessage **m, SocketAddress *
origin);
private:
int s;
SocketAddress * socketAddress;
};
10
status SendReply (UDPMessage *replyMessage,
SocketAddress * client);
};
extern "C" {
char * inet_ntoa(struct in_addr);
}
The prototypes for DoOperation, GetRequest and SendReply (to which you must adhere)
are as follows:
Status DoOperation (Message *message, Message *reply,
int s, SocketAddress serverSA);
Status GetRequest (Message *callMessage, int s,
SocketAddress *clientSA);
Status SendReply (Message *replyMessage, int s,
SocketAddress clientSA);
The prototypes for UDPsend and UDPreceive are as follows:
Status UDPsend(int s, Message *m, SocketAddress
destination);
Status UDPreceive(int s, Message *m, SocketAddress
*origin);
11
Program-5
Operating System Experiments
1 Timing
Do apropos time to obtain a list of all commands, system calls and library calls related to the
topic of time. Take a while to browse documentation on some of these, using
the man command.
Produce a modified version of the fork+wait program, so that each child process execs fred.
Attach this program. Run this program several times and record the values obtained.
Input the following simple program, compile it, use size on the binary and convert size’s
output to hexadecimal representation.
static char *aStaticString = "fred";
static int aStaticDataItem;
static int anInitialisedStaticDataItem = 0x666;
main(int argc, char *argv[])
{
unsigned char *cp;
unsigned char aCharacter;
cp = &aCharacter;
printf("address of character on stack = 0x%x\n", cp);
printf("address of initialised string = 0x%x\n", aStaticString );
printf("address of uninitialised int = 0x%x\n", &aStaticDataItem);
printf("address of initialised int = 0x%x\n", &anInitialisedStaticDataItem);
printf("address of procedure main = 0x%x\n", main);
}
4.1 Apart from the address of aCharacter, account for the address values printed by this
program, relating them to the output of size.
12
4.2 Discuss whether you have sufficient evidence to determine the top of the stack’s address
range.
Add the following code to the program above.
for(cp = &aCharacter; ; cp -= PAGESIZE) /* you need to #define PAGESIZE */
{
aCharacter = *cp;
printf("made it to 0x%x!\n", cp);
}
Run a client and server together at the same machine, and test that they work together.
7 Inter-machine invocation
Run the server program and the client program between two different, dedicated machines.
7.2 send to uses UDP. This places an 8-byte header onto an IP packet, which in turn uses a
20-byte header. An Ethernet packet carries 18 bytes of its own header and checksum. The
minimum Ethernet packet size is 64 bytes. Ethernet bandwidth is 10 or 100 Mbits/sec (find
out about your Ethernet).
Run a client and server at separate, dedicated machines. NB You may find that sendto fails
for lack of buffer space after a certain number of sends. Try to accommodate this by reducing
the number of attempted sends each time.
13
avoids a problem of your program not working because the bound address otherwise stays
"in use" for a considerable time after the program has terminated:
14
Program-6
A proto type for stateless file server and its cache
mechanism
Introduction
This project concerns the design and implementation of a simple stateless file
server and its client-side API. It will give you experience in the use of TCP for
communication between client and server and in the design of a client-side
cache.The interface of the client-side API (which you should implement) is
provided below, together with a default client and a data file with which you can
test your software.
The Java interface for the client API for the file system
/* This is the interface to the client-side file system. We assume
that, once you open the file, you keep a pointer, and whenever
you write or read, that pointer moves to the next byte. */
import filehandle;
/* close file. you should flush the data (over the network). */
public abstract boolean close(filehandle fh)
throws java.io.IOException;
15
}
The program used to check whether the filehandle class works correctly
import java.io.*;
import filehandle;
fh1=new filehandle();
System.out.println("one made.");
if (fh1.isAlive())
System.out.println("one is alive.");
fh2=new filehandle();
System.out.println("two made.");
if (fh2.isAlive())
System.out.println("two is alive.");
if (fh1.Equals(fh2))
System.out.println("one and two are same, this is
strange..");
else
System.out.println("one and two are not equal.");
fh1.discard();
fh2.discard();
if (fh1.Equals(fh2))
System.out.println("one and two are discarded and are
equal.");
else
System.out.println("one and two are not equal, this is
strange.");
}
}
The client program is for testing the communication between client API and
the file server.
/* standard java classes. */
import java.io.*;
import java.util.*;
/* There are two methods, main and readField. The latter does the
following.
(1) It reads one field upto, but not including, a specified delimiter.
(2) It also converts the byte array to String and returns it.
(3) The pointer should reside after the delimeter.
16
It does NOT expect the file can be in a wrong format... */
// variables used.
filehandle fh;
String city, weather, date, updatetime;
long startTime, endTime;
long turnAround;
// open file.
fh=fs.open(IPadr+":"+Port+"/"+Filename);
while (true){
while (!fs.isEOF(fh)){
// read data.
city=readField(fs, fh, ';');
weather=readField(fs, fh, ';');
date=readField(fs, fh, ';');
updatetime=readField(fs, fh, '.');
// print data.
System.out.println(city+", "+weather+", "+date+",
"+updatetime);
}
endTime=Calendar.getInstance().getTime().getTime();
turnAround=endTime-startTime;
// wait a bit.
Thread.sleep(500);
17
/* We need to convert between bytes and chars. we do this by
simply getting ascii values and storing them as bytes.
*/
18