Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Easy understanding notes of enterprise javascript

Rating
-
Sold
-
Pages
19
Uploaded on
07-04-2025
Written in
2024/2025

Provide depth of the module

Institution
Course

Content preview

Module II
Remote Method Invocation: RMI architecture; RMI Object services; Naming/registry service,
object activation service, distributed garbage collection; Defining Remote objects; Key RMI classes for
remote object implementations; Stubs and skeletons; Accessing remote object as a client; Remote
method arguments and return values; Factory classes; Dynamically loaded classes; Configuring clients
and servers for remote class loading;

Remote Method Invocation
Java RMI provides the following elements:

 Remote object implementations

 Client interfaces, or stubs, to remote objects


 A remote object registry for finding objects on the network


 A network protocol for communication between remote objects and their client


 A facility for automatically creating (activating) remote objects on−demand



Introduction to RMI
RMI is the distributed object system that is built into the core Java environment. RMI is a
built−in facility for Java that allows us to interact with objects that are actually running in Java
virtual machines on remote hosts on the network. With RMI wecan get a reference to an object
that "lives" in a remote process and invoke methods on it as if it were a local object running
within the same virtual machine as your code (hence the name, "Remote Method Invocation
API").

RMI was added to the core Java API in Version 1.1 of the JDK (and enhanced for Version 1.2
of the Java 2 platform), in recognition of the critical need for support for distributed objects in
distributed−application development.
Java RMI is a Java−only distributed object scheme; the objects in an RMI−based distributed
application have to be implemented in Java.


The advantages of RMI primarily revolve around the fact that it is "Java−native." Since RMI is
part of the core Java API and is built to work directly with Java objects within the Java VM.
You really can use RMI−enabled objects as if they live in the local Java environment. And
since Java RMI is built on the assumption that both the client and server are Java objects, RMI
can extend the internal garbage−collection mechanisms of the standard Java VM to provide
distributed garbage collection of remotely exported objects.
RMI in Action

, As an example, we can create an Account object that represents some kind of bank account
and then use RMI to export it as a remote object so that remote clients (e.g., ATMs, personal
finance software running on a PC) can access it and carry out transactions.

The first step is to define the interface for our remote object. The following example shows the
Account interface. You can tell that it's an RMI object because it extends the
java.rmi.Remote interface. Another signal that this is meant for remote access is that
each method can throw a java.rmi.RemoteException. The Account interface
includes methods to get the account name and balance and to make deposits, withdrawals, and
transfers.
Steps:
1. Create an interface & compile.
Eg:- vi Account.java
javac Account.java
2. Write the implementation class & compile. Also compile with rmic compiler to
generate stub and skelton.
Eg:- vi AccountImpl.java
javac AccountImpl.java
rmic −d /home/classes AccountImpl
3. Write the registration file, compile. Run the registry and run the program.
Eg:- vi AccountReg.java
javac AccountReg.java
rmiregistry &
java AccountReg
4. Write the client program, compile & run.
Eg:- vi AccountClient.java
javac AccountClient.java
java AccountClient


Example 3−1. A Remote Account Interface

import java.rmi.Remote;
import java.rmi.RemoteException;



public interface Account extends Remote
{
public String getName() throws RemoteException;
public float getBalance() throws RemoteException;
public void withdraw(float amt) throws RemoteException;
public void deposit(float amt) throws RemoteException;

}


Compile the program:

, $javac Account.java

The next step is to create an implementation of this interface, which leads to the
AccountImpl class shown in the following example. This class implements all the methods
listed in the Account interface and adds a constructor that takes the name of the new account
to be created. Notice that the AccountImpl class implements the Account interface, but
it also extends the java.rmi.UnicastRemoteObject class. This RMI class provides
some of the basic remote functionality for server objects.



Example 3−2. Implementation of the Remote Account Interface

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class AccountImpl extends UnicastRemoteObject implements Account
{
private float mBalance = 0;
private String mName = "";

// Create a new account with the given name
public AccountImpl(String name) throws RemoteException
{
mName = name;
}

public String getName() throws RemoteException
{
return mName;
}

public float getBalance() throws RemoteException
{
return mBalance;
}

// Withdraw some funds
public void withdraw(float amt) throws RemoteException
{
mBalance −= amt;
// Make sure balance never drops below zero
mBalance = Math.max(mBalance, 0);
}

// Deposit some funds
public void deposit(float amt) throws RemoteException
{
mBalance += amt;
}


}
}

 Compile the program:

$javac AccountImpl.java

 Export the CLASSPATH by adding path to the current directory

$ export CLASSPATH=$CLASSPATH:/home/bca3/

 Compile the program using rmic compiler to generate stub and skelton:

Written for

Institution
Course

Document information

Uploaded on
April 7, 2025
Number of pages
19
Written in
2024/2025
Type
Class notes
Professor(s)
Ram
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
devika5

Get to know the seller

Seller avatar
devika5
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions