4_RMI - Part-1

Video created from my 734(http://www.cs.unc.edu/~dewan/734/current/) Fall 13 lecture. See https://mix.office.com/watch/1g1zlqrk76246 dor a slide-based structured video, http://www.cs.unc.edu/~dewan/734/current/lectures/4-RMI.pptx for the original PPT and http://www.cs.unc.edu/~dewan/734/current/lectures/4-RMI.pdf for the pdf version

1.0x

4_RMI - Part-1

Created 2 years ago

Duration 0:50:21
lesson view count 6
Video created from my 734(http://www.cs.unc.edu/~dewan/734/current/) Fall 13 lecture. See https://mix.office.com/watch/1g1zlqrk76246 dor a slide-based structured video, http://www.cs.unc.edu/~dewan/734/current/lectures/4-RMI.pptx for the original PPT and http://www.cs.unc.edu/~dewan/734/current/lectures/4-RMI.pdf for the pdf version
Select the file type you wish to download
Slide Content
  1. Java Remote Method Invocation (RMI)

    Slide 1 - Java Remote Method Invocation (RMI)

    • Prasun Dewan
    • Department of Computer Science
    • University of North Carolina at Chapel Hill
    • dewan@cs.unc.edu
  2. Slide 2

    • Communication Layers
    • Client Object
    • Server Object
    • Network Layers (e.g. TCP/IP)
    • OS Layers (e.g. Sockets)
    • Language Layer (e.g. Java Remote Method Invocation)
    • Higher layer, higher abstraction, lower OS and language interoperability.
  3. Slide 3

    • Remote Method Invocation
    • Client Object
    • Server Object
    • Language Layer (Java Remote Method Invocation)
  4. Counter

    Slide 4 - Counter

    • public interface Counter {
    • void increment(int val);
    • int getValue() throws RemoteException;
    • }
  5. Counter

    Slide 5 - Counter

    • public class ACounter implements Counter{
    • public ACounter() {
    • super();
    • }
    • Integer value = 0;
    • public Object getValue() {
    • return value;
    • }
    • public void increment(int val) {
    • value += val;
    • }
    • public String toString() {
    • return "Counter:" + value;
    • }
    • public boolean equals(Object otherObject) {
    • if (!(otherObject instanceof Counter))
    • return false;
    • return getValue() == ((Counter) otherObject).getValue();
    • }
    • }
  6. Slide 6

    • Remote Method Invocation
    • Client Object
    • Server Object
    • How do separate processes share object references?
  7. Slide 7

    • Local References in Both Address Spaces
    • Client Object
    • Server Object
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • Proxy is generate by RMI System.
    • Proxy and server objects connected through external name
  8. Slide 8

    • Local References in Both Address Spaces
    • Client Object
    • Server Object
    • However, caller and callee are distribution-aware
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • Remote method invocation has the same syntax as local method invocation.
  9. Slide 9

    • Checked RemoteException
    • Client Object
    • Server Object
    • Method call must catch RemoteException
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • Method declaration must indicate it may throw RemoteException in header
    • Checked RemoteException occurs if network or server errors occur
    • Something the client programmer cannot control, so it is checked
    • How to make programmer put the throws clause?
  10. Slide 10

    • Labeling Remote Methods
    • Client Object
    • Server Object
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • If an interface “extends” or a class “implements” the Remote interface, then every method in that class/interface labeled as Remote
    • Java ensures that every labeled method has the throws clause and generates proxy method for only such a method
    • Programmer must label methods as remotely invokable
  11. Local vs. Distributed Counter

    Slide 11 - Local vs. Distributed Counter

    • public interface Counter {
    • void increment(int val);
    • Object getValue();
    • }
    • public interface DistributedRMICounter extends Remote {
    • void increment(int val) throws RemoteException;
    • Object getValue() throws RemoteException;
    • }
    • Caller should handle errors
    • Checked exceptions
    • Distribution awareness
  12. public class ACounter implements Counter{

    Slide 12 - public class ACounter implements Counter{

    • public ACounter() {
    • super();
    • }
    • Integer value = 0;
    • public Object getValue() {
    • return value;
    • }
    • public void increment(int val) {
    • value += val;
    • }
    • public String toString() {
    • return "Counter:" + value;
    • }
    • public boolean equals(Object otherObject) {
    • if (!(otherObject instanceof Counter))
    • return false;
    • return getValue() == ((Counter) otherObject).getValue();
    • }
    • }
    • ACounter
    • Class header need not have throws class as interface is used by client.
    • DistributedRMICounter does not extend Counter
    • How is it changed?
  13. DistributedRMICounter

    Slide 13 - DistributedRMICounter

    • public class ADistributedInheritingRMICounter extends ACounter implements DistributedRMICounter{
    • @Override
    • public boolean equals(Object otherObject) {
    • if (!(otherObject instanceof DistributedRMICounter))
    • return super.equals(otherObject);
    • try {
    • return getValue().equals(
    • ((DistributedRMICounter) otherObject).getValue());
    • } catch (RemoteException e) {
    • e.printStackTrace();
    • return false;
    • }
    • }
    • }
    • Inherited methods implement two different methods, with and without throws clause
    • How to do client specific processing?
  14. Caller-Specific Processing

    Slide 14 - Caller-Specific Processing

    • public class ADistributedInheritingRMICounter extends ACounter implements DistributedRMICounter{
    • @Override
    • public boolean equals(Object otherObject) {
    • }
    • public int getValue() {
    • try {
    • System.out.println(RemoteServer.getClientHost());
    • } catch (ServerNotActiveException e) {
    • e.printStackTrace();
    • }
    • return super.equals(otherObject); }
    • }
    • RemoteServer
    • static String getClientHost()
  15. Slide 15

    • How to create a local proxy
    • Client Object
    • Server Object
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • How to connect the two?
    • Proxy and server objects connected through external name and transfer of serialized proxies
  16. External Name and Internal Name Binding

    Slide 16 - External Name and Internal Name Binding

    • A mechanism is provided to bind the external name to local reference
    • Objects shared among processes have external names.
    • file name for files
    • File is opened in read mode giving file name
    • A mechanism is provided to bind a local reference to an external name
    • File is opened in write mode giving file name
    • <machine, port> for socket
    • Server socket is bound to <machine, port>
    • Clients socket is connected to server socket using <machine, port>
  17. Slide 17

    • Local References in Both Address Spaces
    • Client Object
    • Server Object
    • Server Proxy
    • m(p1, … pN)
    • m(p1, … pN)
    • How exactly?
    • How to connect the two?
    • Proxy and server objects connected through external name and transfer of serialized proxies
  18. Name Server

    Slide 18 - Name Server

    • Caller
    • RMI Registry
    • Name server keeps (name, object) pairs
    • Callee
    • Caller registers (name, proxy) pair
    • Caller gets object registered for name
  19. Name Server Methods

    Slide 19 - Name Server Methods

    • RMIRegistry must have specific subtype of Remote in path so it can store it in memory
    • Caller
    • RMI Registry
    • rebind(String name,  Remote obj)
    • Remote lookup(String name)
    • Callee
    •  Registry
    • Only instances of Remote can be registered because of special error handling requirement
  20. Name Server Methods

    Slide 20 - Name Server Methods

    • Caller
    • RMI Registry
    • rebind(String name,  Remote obj)
    • Remote lookup(String name)
    • Callee
    •  Registry
    • How to start RMI Registry Server?
    • How to get proxy reference to name server?
    • Bootstrapping problem!
    • Name server keeps (name, object) pairs
  21. Starting RMI Registry From Console

    Slide 21 - Starting RMI Registry From Console

    • LocateRegistry
    • static void createRegistry(int port)
    • static Registry getRegistry(String host, int port)
    • RMI Registry is started as part of calling process
    • set javabin=D:\"Program Files"\Java\jre1.6.0_03\bin
    • set CLASSPATH=D:/dewan_backup/java/gipc/bin
    • %javabin%\rmiregistry 1099
  22. Starting RMI Server From a Program

    Slide 22 - Starting RMI Server From a Program

    • public class RMIRegistryStarter {
    • public static void main (String[] args) {
    • try {
    • LocateRegistry.createRegistry(1099);
    • Scanner scanner = new Scanner(System.in);
    • scanner.nextLine();
    • } catch (Exception e) {
    • e.printStackTrace();
    • }
    • }
    • }
    • Prevents termination
    • Usually RMIRegistry started though LocateRegistry is part of server process
  23. Name Server

    Slide 23 - Name Server

    • RMI Registry simply stores what was sent to it by rebind
    • How to create and store references rather than copies?
    • If a stub has been created, then instance of stub is sent as reference
    • Caller
    • RMI Registry
    • rebind(String name,  Remote obj)
    • Remote lookup(String name)
    • Callee
    •  Registry