120 likes | 229 Vues
This article explores the Java RMI (Remote Method Invocation) Registry, a crucial component for establishing remote connections between clients and servers. It outlines common bootstrapping problems, such as server location discovery and the use of naming services for dynamic server migration and partitioning. Key methods for binding, unbinding, and listing remote objects are examined, including examples of URL formatting for remote registry access. Additionally, the advantages of using RMI Registry, such as ease of administration and client accessibility, are discussed.
E N D
RMI Registry Celsina Bignoli bignolic@smccd.net
Bootstrapping Problem • clients on a machine need to connect to servers on another machine • How does the client know where the server is? • server location hard-coded in client code or stored in a configuration file • user tells client where server is located • use a service in a well-known location as a point of indirection -> NAMING SERVICE
Why using Naming Services • servers migrate • there may be many servers • servers are partitioned and replicated • there may be many servers running on a machine
RMI Registry • methods are in java.rmi.Naming class public static void bind(String name, Remote object) public static void rebind(String name, Remote object) public static void unbind(String name) public static String[] list(String name) public static Remote lookup(String name) • above methods are declared in interface java.rmi.registry.Registry which extends java.rmi.Remote and implemented by sun.rmi.registry.RegistryImpl
bind(), rebind() and unbind() • parse name to find out where the registry is running • name is a URL with the following format //registryHost:port/logical_name Host optional (defaults to localhost) port optional (defaults to 1099) • open socket to registry (which is a server running on the specified host and listening on the indicated port) • serialize stub implementing remote object • bind it to name
lookup() and list() • name is a URL as for bind(). • name for list() only specifies the host and port where the registry is located • lookup() returns the stub bound to it • list() returns complete URLs of all servers bound to the registry see code example
RMI Registry is a RMI Server • Underlying Naming static methods there are a Remote interface and its implementation class: java.rmi.registry.Registry (interface) • defines 5 methods each of which maps to the corresponding static method in Naming java.rmi.registry.RegistryImpl (class)
How Naming works • a static method on naming is called with a given URL • URL is parsed and the machine/port information is to class LocateRegistry which has methods for returning the stub for the given registry • Naming uses this stub to invoke the appropriate method on the registry
Application-specific Registry • start a registry at an application-specific port • using the rmiregistry program: rmiregistry 10345 • from within the code, using static method of LocateRegistry class: public static createRegistry(int port)
Advantages of the RMI Registry • easy to administer • launch it with rmiregistry, provided as part of the JDK distribution • easy for clients to find • only need to know on which machine it runs • easy for clients to use • only 5 easy to use methods • fast
The Need for Directory Service • When there are many similar servers between which the user can choose • ex: choosing a printer based on features
Security Issues • Each process binding a server to the registry must run on the same machine where the registry runs