0% found this document useful (0 votes)
3 views

Unit 4 JavaRMI

This document outlines the syllabus and study materials for the Java Full Stack Technologies (JFST) course for Final Year BTech students at CCOEW. It includes detailed topics on Java 2 Enterprise Edition (J2EE) technologies, Java Messaging Service (JMS), and Remote Method Invocation (RMI), along with references and resources for further study. The document emphasizes the academic purpose of the compiled materials and acknowledges the original authors and sources.

Uploaded by

607Aditi Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 4 JavaRMI

This document outlines the syllabus and study materials for the Java Full Stack Technologies (JFST) course for Final Year BTech students at CCOEW. It includes detailed topics on Java 2 Enterprise Edition (J2EE) technologies, Java Messaging Service (JMS), and Remote Method Invocation (RMI), along with references and resources for further study. The document emphasizes the academic purpose of the compiled materials and acknowledges the original authors and sources.

Uploaded by

607Aditi Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

This document is for private circulation only,

For Final Year BTech. Computer 2021-22 CCOEW JFST


Elective students.

Subject: Java Full Stack Technologies (JFST)

PLEASE refer To All REFERENCES plus Study Material CIRCULATED


plus Lecture Recordings.
Feel free to use additional web sites/searches for understanding
if required.
ACKNOWLEDGEMENT
• This presentation contains pictures, contents taken
from multiple sources, authors and sites.

• We would like to appreciate and thank the authors,


artists and do not claim any of following work to be
ours, but it has been compiled here to use for academic
purpose only.
Unit 4 Syllabus
Java 2 Enterprise Edition (J2EE) Technologies

• Introduction to J2EE technologies

• JNDI, JCA, Java Mail API, JAAS, JAXP, JAXB, StAX

• Java Messaging Service (JMS)

• Remote Method Invocation (RMI)

• Enterprise Java Beans (EJB)


References
• https://docs.oracle.com/javaee/7/tutorial/:
- Java Platform, Enterprise Edition: The Java EE Tutorial
Release 7, September 2014. – Chapters 32, 45

• Kevin Mukhar, Chris Zelenak, James L. Weaver and Jim


Crume, 'Beginning Java EE5: From Novice to Professional',
Apress, 2006.

.
Web References

• https://www.oracle.com/technical-resources/articles/entarch/ejb3.html

• https://www.oracle.com/java/technologies/

• https://docs.oracle.com/javase/tutorial/index.html

• https://www.iitk.ac.in/esc101/05Aug/tutorial/rmi/overview.html

• https://www.journaldev.com/9731/jms-tutorial
Unit 4 Scope in terms of Sub-topics
• Introduction to J2EE Technologies
o J2SE Vs J2EE
o Enterprise Computing – Challenges/Requirements
o Monolithic Vs Object-based applications
o J2EE overview/Features
o J2EE technologies – role of each with examples
- EJB, RMI, Java Servlets, JSP, JDBC, JMS,
- JAAS, Java Mail API, JNDI, JCA
o J2EE Multi-tiered Architecture
- Examples and technologies at each tier
o J2EE Containers – roles, examples
o J2EE containers Vs components – responsibilities, examples
Unit 4 Scope in terms of Sub-topics…contd.
• JNDI
- Features/Advantages
- Naming service, Directory service - concepts, examples,
binding, lookup
- JNDI architecture

• JCA, Java Mail API, JAAS, JAXP, JAXB, StAX


- Purpose, Advantages, Examples, Java Mail Architecture
Unit 4 Scope in terms of Sub-topics…contd.
• Enterprise Java Beans (EJB)
o Enterprise applications – Examples, Requirements/Features
o Role of EJBs
o EJB 2.1 Vs EJB 3.0
o Application server, EJB container – services/responsibilities
o Types of EJBs – need of each, advantage, examples of each
- Session Beans: Stateful, Stateless; Stateless Vs Stateful
- Message-Driven Beans
- Entity Beans: Bean Managed Persistence,
Container Managed Persistence.
o Session Bean Vs Entity Bean
Unit 4 Scope in terms of Sub-topics…contd.
• Enterprise Java Beans (EJB)
o Java Beans Vs EJBs
o EJB container services and examples
o EJB client - JNDI lookup, Dependency Injection
o EJB server
o Basic steps of creating EJB Application
o Uses of EJBs
o Deployment Descriptors
o Annotations
o EJB Architecture
o Simplified functionalities of EJB3
Unit 4 Scope in terms of
Sub-topics…contd.
• Enterprise Java Beans (EJB)
o EJB3 Features
- Annotations
- Elimination of Home Interfaces
- Elimination of component (local/remote) Interfaces
- Callback methods
- Simple POJO model
- Java Persistence API (JPA)
- Dependency Injection (DI)
- Timer service
- Interceptors
Unit 4 Scope in terms of
Sub-topics…contd.
• Java Messaging Service (JMS)
o Need/Purpose, Examples
o Benefits/Features
o Message Oriented Middleware (MOM)
o Asynchronous messaging
o Point-to-point Messaging: working, examples
o Publish-Subscribe Messaging: working, examples
o Comparison of two messaging models
o Examples for use of JMS Queue, JMS Topic
o Message Producer, Message Consumer, JMS Provider
o JMS API: Connection, Session, Message Producer, Message
Consumer, Destination
Unit 4 Scope in terms of Sub-topics…contd.
• Application development using Sockets Vs RMI
• Java Remote Method Invocation (RMI)
o Basic concepts/features, Advantages over sockets and RPC
o RMI architecture
o Remote Object – examples
o Remote Interfaces – examples
o Stub and Skeleton – roles
o Object serialization and deserialization
o Marshaling and Unmarshaling – concepts, examples
o Client-server application using RMI – Steps, Examples
o RMI Registry – Role
o Security Manager, Dynamic loading of stub classes
o JRMP, IIOP
Java Remote Method Invocation
(RMI)
Client Server Communication

Source: Internet
Socket-based Client and Server
programming

Source: Internet
Socket: Example
• A socket-based math server and clients

Source: Internet
Source: Internet
Why Not develop applications at TCP/IP level
using socket APIs?
• Say you want a function at other end to perform
something, then…
• What about complex parameters from client side ,
response from server side?
• What about network error handling?
• What about machine differences?
• What about synchronization of responses?
• What if server is not UP and running?
• How about movement of server functionality?
• What about transparencies?
• What about differences in socket APIs?
Why Not develop applications at TCP/IP level
using socket APIs?...contd.

• How do we develop such distributed applications?


• Who will handle the network complexities?
• Who will handle the plumbing, infrastructure?
• Who will handle the advanced issues like
transactions…?
• What about the nonfunctional requirements like
performance?
The Solution is…

Source: Internet
What about RPC – as a middleware?
• Remote Procedural Call
• Telephone like : Synchronous
• Server side register your process/function to be
listening to a port
• RPC service running at some well known port
• Client request- response
• Client stub may even search another machine table
for the remote procedure
• RPC stubs and skeletons : XDR
• Acknowledgement and even transaction support
RPC

Source: Internet
Why not develop applications at RPC level then?
• Not Object Oriented
• Passing references
• Vendor RPC implementations may not talk to each other
• RPC security primitive
• RPC transaction support primitive: once only semantics? What if
client dies after making request? Need transactional RPC
• RPC not reflexive
• No asynchronous mode unless manage threads…
• Server up before client, How about server restart? start/stop?
• request priorities?
• load balancing? May need a separate TP Monitor
• Threads Vs processes?
• Need higher abstractions : e. g. Stateless Vs Stateful (File next read)
Java RMI as a Middleware
Source: Internet
Source: Internet
JAVA RMI
• Across JVMs

• Object Oriented

• Parameters can be Objects

• Underlying still TCP/IP

• Java Serialization
Remote Method Invocation (RMI)
▪ Distributed Applications
- remote method calls between objects in different
Java Virtual Machines

▪ Language (Java) centric


- Multi-platform
- Truly OO

▪ Easy to use
Source: Internet
RMI architecture
Client Server

JVM 1 JVM 2

Remote RemoteObject

method ( ) method ( )

Stub Skeleton

Source: Java Network Programming, Second Edition


Merlin Hughes, Michael Shoffner, and Derek Hamner
Source: Internet
Marshaling
▪ Breaking data down into bytes

▪ Marshaling of java primitive types : DataOutputStream class

▪ Object serialization
- marshaling of objects
- ObjectOutputStream class
- an object must implement Serializable interface

ObjectOutputStream out = new ObjectOutputStream


(socket.getOutputStream( ));
Color c = new Color(240,240,240);
Out.writeObject( c );
Marshaling
contd…

Object
writeObject
bytes

ObjectOutputStream OutputStream

Source: Java Network Programming, Second Edition


Merlin Hughes, Michael Shoffner, and Derek Hamner
Unmarshaling

▪ Unpacking data into original form at the other end

▪ Unmarshaling of java primitive types : DataInputStream class

▪ Object deserialization
- unmarshaling of objects
- ObjectInputStream class

ObjectInputStream in = new ObjectInputStream


(socket.getInputStream( ));
Color col ;
col = (Color) in.readObject( );
Unmarshaling contd…

Object
bytes readObject
InputStream ObjectInputStream

Source: Java Network Programming, Second Edition


Merlin Hughes, Michael Shoffner, and Derek Hamner
Source: Internet
Source: Internet
Source: Internet
Client/Server application using RMI

▪ Define the remote interface

- must be declared public


- extends java.rmi.Remote interface
- all remote methods can throw java.rmi.RemoteExcepion

import java.rmi.* ;
public interface Hello extends Remote
{
String sayHello( ) throws RemoteException ;
}
Client/Server application using RMI contd…
▪ Implement the remote interface
• Implementation class must extend UnicastRemoteObject
- use sockets-based transport for communication

• Define the constructor for the remote object


- Export the object so that it can accept incoming
method calls
- must throw java.rmi.RemoteException

• Provide an implementation for each remote method

• Only those methods declared in the remote I/F


are accessible to the client.
Client/Server application using RMI contd…
▪ Implement the remote interface – Example

import java.rmi.* ;
import java.rmi.server.* ;
public class HelloImpl extends UnicastRemoteObject
implements Hello
{
public HelloImpl( ) throws RemoteException
{
super( );
}
public String sayHello( )
{
return “Hello world!”;
}
}
Client/Server application using RMI contd…
▪ Register the remote object with the RMI registry
- update RMI registry using rebind( ) method of the Naming class
public class HelloServer
{
public static void main(String args[ ])
{
try{
HelloImpl hi = new HelloImpl( );
Naming.rebind(“HelloServer”, hi);
}
catch(Exception e)
{
System.out.println(“Exception: “ + e);
}
}
}
Registering with the naming service

RemoteObject1 Naming
name rebind ( )

RemoteObject2 name2

Naming Registry
name
name2

Source: Java Network Programming, Second Edition


Merlin Hughes, Michael Shoffner, and Derek Hamner
Client/Server application using RMI contd…
▪ Write the client program
- connect to the registry
- get a reference to the remote object by lookup( )
method of the Naming class
public class HelloClient
{
public static void main(String args[ ])
{
try{
Hello h = (Hello) Naming.lookup(“HelloServer”);
System.out.println(“The message is: “ + h.sayHello( ));
}
catch(Exception e)
{ System.out.println(“Exception: “ + e);
}
}
}
Locating a remote object with the naming service

Client RemoteObject1

rmi://server/name

Naming Registry
Naming
name name
lookup( )

Source: Java Network Programming, Second Edition


Merlin Hughes, Michael Shoffner, and Derek Hamner
Client/Server application using RMI contd…
Steps to follow…

▪ Enter and compile the source code


- an interface, implementation, server , client

▪ Generate the stub and skeleton using rmic

▪ Start the RMI registry on the Server machine

▪ Start the Server

▪ Start the Client


Source: Internet
RMI REGISTRY

Source: Internet
RMI - Example

Source: Internet
Source: Internet
Java RMI
• 1099: default port of rmi registry

• Naming.rebind(“rmi://localhost:1099/Add”, a);

• For some other port, say 2001:


- start rmiregistry 2001
- Rebind and lookup should explicitly use port 2001 in
the URL.
Security manager

• RMI clients need to download RMI stubs (as well as any


other custom classes or interfaces needed to communicate
with the RMI server).
• A security manager needs to be running so that it can
guarantee that the classes that get loaded do not perform
operations that they are not allowed to perform.
• Required in any JVM that needs to download code.

if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager()); }
Dynamic class loading

• Stub class can be dynamically downloaded to the


registry and then to the client by specifying
java.rmi.server.codebase property, specifying
where the class files are located on the server,
when starting the server.
RMI Communication Protocol
• RMI over JRMP (Java Remote Method Protocol)
- Default protocol
- rmic generates stub and skeleton

• RMI over IIOP (Internet Inter-ORB Protocol)


- For interoperability,

Source: Internet rmic –iiop : generates stub and tie classes


Is JAVA RMI final solution?
• What about a C++ client?
• Can we ensure use of one language only?
• What about transaction support?
• What about security?
• What about discovering components?
• Vendor Neutrality? Other middleware?
• What about message delivery guarantees ,
abstractions like publish subscribe?
• What about legacy applications?
ACKNOWLEDGEMENT
• This presentation contains pictures, contents taken
from multiple sources, authors and sites.

• We would like to appreciate and thank the authors,


artists and do not claim any of the above work to be
ours, but it has been compiled here to use for academic
purpose only.

You might also like