Published on

Advanced Java Programming - III CSE Anna University Syllabus

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Unit – III Roy Antony Arnold G Sr. Lecturer Einstein College of Engineering Tirunelveli, Tamilnadu, India
  2. 2. <ul><li>In RMI, activation allows objects to begin execution on an as-needed basis . </li></ul><ul><li>When an activatable remote object is accessed (via a method invocation) if that remote object is not currently executing, the system initiates the object's execution inside an appropriate JVM </li></ul>
  3. 3. <ul><li>An active object is a remote object that is instantiated and exported in a JVM on some system. </li></ul><ul><li>A passive object is one that is not yet instantiated (or exported) in a JVM, but which can be brought into an active state. </li></ul><ul><li>Transforming a passive object into an active object is a process known as activation . </li></ul><ul><li>Activation requires that an object be associated with a JVM, which may entail loading the class for that object into a JVM and the object restoring its persistent state (if any). </li></ul><ul><li>In the RMI system, we use lazy activation. Lazy activation defers activating an object until a client's first use (i.e., the first method invocation). </li></ul>
  4. 4. <ul><li>Lazy activation of remote objects is implemented using a faulting remote reference (sometimes referred to as a fault block). </li></ul><ul><li>A faulting remote reference to a remote object “faults in” the active object’s reference upon the first method invocation to the object . </li></ul><ul><li>Each faulting reference maintains both a persistent handle (an activation identifier) and a transient remote reference to the target remote object. </li></ul><ul><li>The remote object’s activation identifier contains enough information to engage a third party in activating the object. </li></ul>
  5. 5. <ul><li>A remote object’s stub contains a “faulting” remote reference type that contains both: </li></ul><ul><ul><li>an activation identifier for a remote object, and </li></ul></ul><ul><ul><li>a “live” reference (possibly null) containing the “active” remote reference type of the remote object </li></ul></ul>
  6. 7. <ul><li>When a client receives a stub for an activatable server, the stub contains a special form of RemoteRef which initially contains a null &quot;real&quot; RemoteRef and an ActivationID for the remote object. </li></ul><ul><li>When the stub is first used for a remote method invocation the RemoteRef is null, so the stub engages in a protocol interaction with the activation system daemon rmid in the remote host. </li></ul><ul><li>The result of this protocol interaction is a live RemoteRef which the stub can then use to invoke the remote method. </li></ul><ul><li>Behind the scenes, the activation system has taken the following steps: </li></ul><ul><ul><li>looked up the ActivationID </li></ul></ul><ul><ul><li>found the ActivationGroup associated with it </li></ul></ul><ul><ul><li>activated the group if necessary </li></ul></ul><ul><ul><li>told the group to activate the activatable server if necessary </li></ul></ul><ul><ul><li>obtained the activatable server's RemoteReffrom the group, and returned it to the client stub. </li></ul></ul>
  7. 8. <ul><li>During a remote method invocation, if the “live” reference for a target object is unknown, the faulting reference engages in the activation protocol. </li></ul><ul><li>The activation protocol involves several entities: the faulting reference, the activator, an activation group, and the remote object being activated . </li></ul><ul><li>The activator (usually one per host) is the entity which supervises activation by being both: </li></ul><ul><ul><li>a database of information that maps activation identifiers to the information necessary to activate an object (the object's class, the location--a URL path-- from which the class can be loaded, specific data the object may need to bootstrap, etc.), and </li></ul></ul><ul><ul><li>a manager of Java virtual machines, that starts up JVMs (when necessary) and forwards requests for object activation to the correct activation group inside a remote JVM. </li></ul></ul>
  8. 9. <ul><li>A faulting reference uses an activation identifier and calls the activator (an internal RMI interface) to activate the object associated with the identifier. </li></ul><ul><li>The activator looks up the object’s activation descriptor (registered previously). </li></ul><ul><li>The object’s descriptor contains: </li></ul><ul><ul><li>the object’s group identifier, specifying the JVM in which it is activated, </li></ul></ul><ul><ul><li>the object’s class name, </li></ul></ul><ul><ul><li>a URL path from which to load the object’s class code, and </li></ul></ul><ul><ul><li>object-specific initialization data in marshalled form. </li></ul></ul><ul><li>When the object is finished activating, the activation group passes back a marshalled object reference to the activator that then records the activation identifier and active reference pairing and returns the active (live) reference to the faulting reference. </li></ul><ul><li>The faulting reference (inside the stub) then forwards method invocations via the live reference directly to the remote object. </li></ul>
  9. 10. <ul><li>Unit – 3 </li></ul>
  10. 11. <ul><li>A socket factory is a class which enables you to provide your own Sockets or ServerSockets to RMI. </li></ul><ul><li>Applications using RMI can provide their own socket factories, which RMI will use when constructing server and client sockets on behalf of RMI servers and clients. </li></ul><ul><li>This facility has two principal uses: </li></ul><ul><ul><li>To superimpose a custom protocol, e.g. an authenticating or encrypting protocol, over the RMI transport protocol. </li></ul></ul><ul><ul><li>To control the Socket or ServerSocket itself: e.g. to set a client timeout, or to use a specific serverside listening network interface in &quot;multihomed” hosts. </li></ul></ul>
  11. 12. <ul><li>Server socket factory classes must implement the interface java.rmi.server.RMIServerSocketFactory and therefore must provide an implementation of its createServerSocket method. </li></ul>import java.rmi.server.*; import*; import*; public class MyServerSocketFactory implements MIServerSocketFactory { public createServerSocket(int port) throws IOException { return new ServerSocket(port); } }
  12. 13. <ul><li>A client socket factory must implement the interface java.rmi.server.RMIClientSocketFactory and therefore provide an implementation of its createSocket method. </li></ul>import java.rmi.server.*; import*; import*; public class MyClientSocketFactory implements RMIClientSocketFactory, Serializable { public createSocket(String host,int port) throws IOException { return new Socket(host,port); } }
  13. 14. <ul><li>Secure sockets </li></ul><ul><ul><li>The Secure Sockets Layer (SSL) superimposes a measure of security over TCP. </li></ul></ul><ul><ul><li>SSL can be enabled for an RMI service by defining SSL client and server socket factories. </li></ul></ul><ul><li>HTTP Tunnelling </li></ul><ul><ul><li>The default RMI socket factory, which is returned by the RMISocketFactory.getDefaultFactory method, implements a three stage Connection technique to penetrate clientside firewalls. (a) direct TCP connection; (b) direct HTTP tunnel; and (c) indirect HTTP tunnel, and that it may be desired to short-circuit this process and go straight to step (c). </li></ul></ul><ul><li>Multihoming </li></ul><ul><ul><li>A network host is said to be &quot;multihomed” if it supports more than one network interface—more than one IP address. </li></ul></ul><ul><ul><li>Such a host might be used at the junction of two IP subnets to act as a router between them, or to virtualize two or more &quot;logical&quot; hosts on a single physical host. </li></ul></ul><ul><ul><li>By default, a server socket listens at—is bound to—all available network interfaces. You can force a server socket to listen at a specific network interface by using the constructor for ServerSocket which takes three arguments: a port, a backlog, and an InetAddress. </li></ul></ul>
  14. 15. <ul><li>public class MultiHomedServerSocketFactory implements RMIServerSocketFactory </li></ul><ul><li>{ </li></ul><ul><li>private InetAddressbindAddr; </li></ul><ul><li>// Constructor </li></ul><ul><li>public MultiHomedServerSocketFactory(InetAddress bindAddr) </li></ul><ul><li>{ </li></ul><ul><li>this.bindAddr = bindAddr; </li></ul><ul><li>} </li></ul><ul><li>public ServerSocket createServerSocket(int port) throws IOException </li></ul><ul><li>{ </li></ul><ul><li>return new ServerSocket(port,0,bindAddr); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>