Docsity

Java RMI: Understanding Remote Method Invocation in Java, Slides of Java Programming

Partial preview of the text

Download Java RMI: Understanding Remote Method Invocation in Java and more Slides Java Programming in PDF only on Docsity!

Java RMI

Introduction to RMI

Java and the Web

  • Java’s popularity is due to its suitability for use on the World Wide Web (WWW).
  • Several Web browsers have support for Java:
    • Netscape Navigator
    • Internet Explorer
    • HotJava
  • Java incorporates audio, video, and animation directly on the web page.

Method Modifiers with Effect on

Scoping

  • public : Method can be accessed by any class
  • private : methods accessed only by class methods
  • friendly : methods accessed by other methods in the same package
  • protected : methods accessed by subclass methods.

Interfaces

  • A Java interface is similar to a class, except there is no data associated with the interface.
  • Example:

public interface MyInterface {

methods-with no implementation details final variables

}

Java Native Interface (JNI)

  • The Java Native Interface (JNI) is part of the core JDK and provides a framework for interfacing to native code. The native code is not easily portable across different hardware platforms. So using native code takes way one of the major advantages of java. JNI was developed to bridge the gap. (JNI section by Rekha Telkar)

When to use JNI

  • When the standard Java class library does not support the platform-dependent features needed by the application.
  • You need to use a library written in another language, and wish to make it accessible to Java code through the JNI.
  • You want to implement a small portion of time- critical code in a lower-level language such as assembly.

Enabling Java code with JNI

  • You can use the JNI with the Invocation API to enable an arbitrary native application to embed the Java VM. Programmers can make their existing applications Java-enabled without having to link with the VM source code.

Remote Method Invocation

  • RMI provides the means to invoke methods remotely.
  • RMI allows for applications to communicate and execute across multiple systems on a network.
  • RMI is supported by the java.rmi, java.rmi.server, and java.rmi.registry
  • Enhanced security of Java 2 requires a security policy implementation.

RMI process

Java Client Java Server

Client Stub Server Skeleton

Client Method (^) Called Method

Network transport Network Transport

arguments results

Network

Not needed In Java 2

RMI Server, Client, and Registry

  • The server process registers the remote object X with the registry using the Naming.bind() method.
  • The client calls Naming.lookup() , which contacts the registry and obtains a stub object for X.
  • The client then uses the stub as if it is a local object.

Stub Class Responsibilities

  • Initiating a call to the remote object (by calling the remote reference layer).
  • Marshaling arguments to a marshal stream (obtained from the remote reference layer).
  • Informing the remote reference layer that the call should be invoked.
  • Unmarshaling the return value or exception from a marshal stream.
  • Informing the remote reference layer that the call is complete.

Skeleton Class

  • A skeleton for a remote object is a server-side entity that contains a method which dispatches calls to the actual remote object implementation. The skeleton is responsible for: - Unmarshaling arguments from the marshal stream. - Making the up-call to the actual remote object implementation. - Marshaling the return value of the call or an exception (if one occurred) onto the marshal stream.

Remote Reference Layer (2)

  • The client-side component contains information specific to the remote server (or servers, if the remote reference is to a replicated object) and communicates via the transport to the server- side component. During each method invocation, the client and server-side components perform the specific remote reference semantics.

Remote Reference Layer (3)

  • For example, if a remote object is part of a replicated object, the client-side component can forward the invocation to each replica rather than just a single remote object.
  • In a corresponding manner, the server-side component implements the specific remote reference semantics prior to delivering a remote method invocation to the skeleton.