简体   繁体   中英

Where is the stub instantiated in RMI

I am not sure where the instance of a stub for a remote object is created. Is it created when registering it in the rmiregistry by calling calling Naming.bind ? This would make sense as the registry is also called via RMI.

But can't the stub also be created by calling UnicastRemoteObject.exportObject ?

This particular code snippet from oracle confused me:

Compute engine = new ComputeEngine();
Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
String name = "Compute";
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);

When using Naming.bind do I need to pass a stub or a remote object?

The stub is

  1. created when you export the remote object
  2. substituted for the remote object when you pass the remote object as a remote method parameter or result, eg when binding or looking up in the Registry.

When using Naming.bind() do I need to pass a stub or a remote object?

Either. It doesn't matter, because of (2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM