Unit 4 JavaRMI
Unit 4 JavaRMI
.
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
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.
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
• Java Serialization
Remote Method Invocation (RMI)
▪ Distributed Applications
- remote method calls between objects in different
Java Virtual Machines
▪ Easy to use
Source: Internet
RMI architecture
Client Server
JVM 1 JVM 2
Remote RemoteObject
method ( ) method ( )
Stub Skeleton
▪ Object serialization
- marshaling of objects
- ObjectOutputStream class
- an object must implement Serializable interface
Object
writeObject
bytes
ObjectOutputStream OutputStream
▪ Object deserialization
- unmarshaling of objects
- ObjectInputStream class
Object
bytes readObject
InputStream ObjectInputStream
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
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
Client RemoteObject1
rmi://server/name
Naming Registry
Naming
name name
lookup( )
Source: Internet
RMI - Example
Source: Internet
Source: Internet
Java RMI
• 1099: default port of rmi registry
• Naming.rebind(“rmi://localhost:1099/Add”, a);
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager()); }
Dynamic class loading