Download RMI - Chintan Dave

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Lag wikipedia , lookup

Remote Desktop Services wikipedia , lookup

Transcript
RMI
Prof.Chintan Dave
What to A hie e…???
•
•
•
•
•
•
•
RMI Architecture
Concept of RMI Registry
Distributed Application Using RMI
Naming and Directory Services
JNDI
Object Serialization
Internationalization
What is RMI?
• Java RMI is a mechanism that allows one to invoke a method
on an object that exists in another address space.
• The other address space could be on the same machine or a
different one.
• The RMI mechanism is basically an object-oriented RPC
mechanism.
• API that provides a mechanism to create distributed
application(distributed application is software that is
executed or run on multiple computers within a network) in
java.
• What is CORBA(Common Object Broker Request ArchitectureProgramming Language Independent)
• DCOM(Distributed Component Object Model-.NET Platform)?
Need to K o …
Skeleton is a server side proxy,
the purpose of ... carrying out
the method call on the remote
object
stub for a remote object acts
as a client's local
representative or proxy for the
remote object.
RMI Architecture
• The server must first bind
its name to the registry
• The client lookup the server
name in the registry to
establish remote
references.
• The Stub serializing the
parameters to skeleton, the
skeleton invoking the
remote method and
serializing the result back to
the stub.
Remote Machine
bind
RMI Server
Registry
skeleton
return
call
stub
RMI Client
Local Machine
lookup
The Stub and Skeleton
Stub
RMI Client
skeleton
call
RMI Server
return
• A client invokes a remote method, the call is first
forwarded to stub.
• The stub is responsible for sending the remote call over to
the server-side skeleton
• The stub opening a socket to the remote server,
marshaling the object parameters and forwarding the
data stream to the skeleton.
• A skeleton contains a method that receives the remote
calls, unmarshals the parameters, and invokes the actual
remote object implementation.
What is RMI Registry?
• Remote object registry is a bootstrap naming
service that is used by RMI servers on the
same host to bind remote objects to names.
Clients on local and remote hosts can then
look up remote objects and make remote
method invocations.
• Client Retrieves Remote Objects Registered in
RMI Registry.
Creating Distributed Application with -
RMI
• Create the Remote Interface.
• Create Remote Object that Implements the
remote interface and Register it.
• Create the Client Program
• Compile the Source File
• Start RMI Registry
• Start Remote Server Object and Run Client
Program
1.Create the Remote Interface
• Remote Interface Contains a declaration of the methods to be
invoked remotely by client program.
/* DemoInterface.java*/
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface DemoInterface extends Remote
{
public String SayDemo() throws RemoteException;
}
2. Implementing Remote Object
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
public class DemoServer implements DemoInterface
{
public DemoServer()
{
super();
}
private String message;
public DemoServer(String msg) throws RemoteException {
message = msg;
}
public String SayDemo() throws RemoteException {
return message;
}
2. Implementing Remote Object
Co ti…
public static void main (String[] argv)
{
try {
DemoInterface h = new DemoServer("Hello");
Registry registry = LocateRegistry.getRegistry();
registry.rebind ("Hello", stub);
}
catch (Exception e) {
System.out.println ("Server not connected: " + e);
}
}
}
3.Create the Client Program
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class DemoClient
{
public static void main (String[] args) {
try
{
Registry reg = LocateRegistry.getRegistry(args[0]);
DemoInterface h = (DemoInterface) reg.lookup("Hello"); // Name Passed Should be same as
//remote object name(server)
System.out.println (h.SayDemo());
}
catch (Exception e){
System.out.println ("DemoClient exception: " + e);
}
}
}
4. Compilation of Files
• Javac Democlient.java
• Javac DemoInterface.java
• Javac DemoServer.java
5.Start Registry
• Start rmiregistry
Run Java code by
Java DemoServer
Java DemoClient IPAddress
Ex. Java demoClient 192.168.2.25
Naming and Directory Services-JNDI
• JNDI is the acronym of Java Naming
and Directory Interface. JNDI is a Java API
which is using by Java applications to find
objects or data with a specific name
naming/directory services
• Lightweight Directory ACCESS Protocol (LDAP)
• Common Object Request BROKER Architecture
(CORBA) Common Object Services (COS) name
service
• Java Remote Method Invocation (RMI)
Registry
• Domain Name Service (DNS)
DNS(JNDI)
•
•
•
•
Mapping DNS Content to JNDI
Names
Nodes and Resource Records
Attribute Identifiers
LDAP
• LDAP defines how clients should access data
on the server, not how
• that data is stored on the server. This allows
LDAP to become a frontend to any type of
data store.
NIS
• Network Information Services.
Object Serialization
• An object can be represented as a sequence of bytes that includes
the object's data as well as information about the object's type and
the types of data stored in the object.
• After a serialized object has been written into a file, it can be read
from the file and deserialize.
• Entire process is JVM independent, meaning an object can be
serialized on one platform and deserialized on an entirely different
platform.
• Classes ObjectInputStream and ObjectOutputStream are high-level
streams that contain the methods for serializing and deserializing an
object.
• public final void writeObject(Object x) throws IOException (Method
of Serialization)
• public final Object readObject() throws IOException,
ClassNotFoundException (Method of deSerialization)
Class to be Serialized
Serialization
Internationalization
• Internationalization is the process of designing an application so that
it can be adapted to different languages and regions, without
requiring engineering changes.
• Advantages:
I.
Build o e, sell a
here…
II. Modularity demands it!
III. Ease of translation
IV. With the additio of lo alizatio data, the sa e e e uta le a
orld ide.
•
Features:
I.
II.
III.
Locale
Resource bundles
Character sets
e ru
I ter atio alizatio Co ti…
• Locale :how data is presented and formatted. They affect language choice, collation,
calendar usage, date and time formats, number and currency formats, and many
other culturally sensitive data representations.
• Language:A Locale's language is specified by the ISO 639 standard, which describes valid
language codes that can be used to construct a Locale object.
• Resource Bundle:simply assign a mnemonic name (also known as a key) to your String
and define the corresponding values for different locales in separate
properties files.
ResourceBundle then gets the appropriate translation for you at runtime.
Example
(Before)
System.out.println("Hello.");
System.out.println("How are you?");
System.out.println("Goodbye.");
(After)
Ru …
% java I18NSample fr FR
Bonjour.
Comment allez-vous?
Au revoir.
% java I18NSample en US
Hello.
How are you?
Goodbye.
1. So What Just Happened?
• Created MessagesBundle_fr_FR.properties,
which contains these lines:
greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?
(What the translator deals with.)
• In the English one?
2. Define the locale...
• Look!
3. Create a ResourceBundle...
• Look!
4. Get the Text from the
ResourceBundle...
• Look!