Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code you have written doesn't start a registry. <code>LocateRegistry.getRegistry()</code> doesn't do that. Check the Javadoc. It assumes the Registry is already running. <code>LocateRegistry.getRegistry()</code> just constructs a Registry stub according to the host and port you provide. It doesn't even do any network operations.</p> <p>To start a Registry from within your JVM, use <code>LocateRegistry.createRegistry(),</code> as its Javadoc states.</p> <p>EDIT: There's a lot of misinformation in your edit.</p> <blockquote> <p>Remote is a "marker" interface that identifies interfaces whose methods may be invoked from a non-local virtual machine. </p> </blockquote> <p>Only if implemented by an exported remote object whose stub has been transmitted to that VM. The remote interface itself doesn't have any such magical property. All methods defined in a remote interface must be declared to throw <code>RemoteException,</code> although the implementations of these methods generally don't need to be so declared (i.e. unless they perform remote operations themselves: the compiler will tell you).</p> <blockquote> <p>We need class that create a Remote object's so we crate class object implement the Remote Interface to make the object's that created by this class object</p> </blockquote> <p>Far too much confusion here. We need a <em>class.</em> The <em>class</em> must implement the remote interface. This is not an 'object' yet: it is a piece of code that must be compiled to a .class file. A class doesn't 'make objects'. An application does that, with the <code>new</code> operator.</p> <blockquote> <p>we link this object's to the RMI System by extends from this class UnicastRemoteObjec so When a class extends from UnicastRemoteObject, it must provide a constructor declaring this constructor calls super(), it activates code in UnicastRemoteObject, which performs the RMI linking and remote object initialization</p> </blockquote> <p>There is no 'link' step in RMI. There is an 'export' step. It is performed <em>either</em> by extending <code>UnicastRemoteObject</code> <em>or</em> by calling <code>UnicastRemoteObject.exportObject().</code> If you don't extend <code>UnicastRemoteObject</code> you don't need the constructor you described.</p> <blockquote> <p>The server's job is to accept requests from a client, perform some service, and then send the results back to the client.</p> </blockquote> <p>The server's job is to implement the methods in the remote interface. RMI does all the rest for you.</p> <blockquote> <p>The server creates the remote object, registers it under some arbitrary name, then waits for remote requests</p> </blockquote> <p>Or else the server <em>is</em> the remote object and it registers itself.</p> <blockquote> <p>for register The remote object we use java.rmi.registry.LocateRegistry class allows the RMI registry service (provided as part of the JVM) to be started within the code by calling its createRegistry() method.</p> </blockquote> <p>Or you can use an external Registry via the <code>rmiregistry</code> command. Or you can use an LDAP server via JNDI.</p> <pre><code>LocateRegistry.createRegistry(1099); Naming.rebind("TheCalendar", new CalendarImpl()); </code></pre> <p>This won't work unless you store the result of <code>createRegistry()</code> into a static variable. And having stored it, you may as well <em>use</em> it to do the bind, instead of using the <code>Naming</code> class. If you don't store it into a static variable it will be garbage-collected and so will the remote object.</p> <blockquote> <p>The java.rmi.registry.LocateRegistry class allows the RMI registry service to be located by a client by its getRegistry() method</p> </blockquote> <p>Or you can use the <code>Naming</code> class, see below.</p> <blockquote> <p>The java.rmi.registry.Registry class provides a lookup() method that takes the "ArbitraryName" the remote object was bound to by the server.</p> </blockquote> <p>So does the <code>Naming</code> class. It takes an rmi: URL which specifies the host and port and bind-name. You can omit the <code>rmi://</code> part. If you omit the host it defaults to 'localhost', but this is only useful if the client is running in the same host as the server, which isn't itself very useful. If you omit the port it defaults to 1099.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload