Java remote method invocation: Difference between revisions

Content deleted Content added
m Disambiguating links to External (link removed) using DisamAssist.
Example: ; : fix syntaxhighlight error
Line 16:
==Jini version==
[[Jini]] offers a more advanced version of RMI in Java. It functions similarly but provides more advanced security, object discovery capabilities, and other mechanisms for distributed object applications.<ref name="From P2P to Web Services and Grids 2005">{{cite book |first=Ian J |last=Taylor |title=From P2P to Web Services and Grids : Peers in a Client/Server World |series=Computer Communications and Networks |publisher=Springer-Verlag |___location=London |year=2005 |isbn=1852338695 |doi=10.1007/b138333 |url=https://archive.org/details/fromp2ptowebserv0000tayl |oclc=827073874 |url-access=registration }}{{page needed|date=September 2017}}</ref>
 
 
==Example==
The following classes implement a simple client-server program using RMI that displays a message.
 
'''; <code>RmiServerIntf</code> interface''' : defines the interface that is used by the client and implemented by the server.
 
<syntaxhighlight lang=java>
Line 31 ⟶ 32:
</syntaxhighlight>
 
'''; <code>RmiServer</code> class''' &mdash;: listens to RMI requests and implements the interface which is used by the client to invoke remote methods.
 
<syntaxhighlight lang=java>
Line 71 ⟶ 72:
</syntaxhighlight>
 
'''; <code>RmiClient</code> class''' &mdash;: this is the client which gets the reference (a proxy) to the remote object living on the server and invokes its method to get a message. If the server object implemented java.io.Serializable instead of java.rmi.Remote, it would be serialized and passed to the client as a value.<ref>{{cite web |last1=Wilson |first1=M. Jeff |date=2000-11-10 |df=mdy |url=https://www.infoworld.com/article/2076234/get-smart-with-proxies-and-rmi.html |title=Get smart with proxies and RMI |work=[[JavaWorld]] |access-date=2020-07-18}}</ref>
 
<syntaxhighlight lang=java>
Line 86 ⟶ 87:
Before running this example, we need to make a 'stub' file for the interface we used. For this task we have the RMI compiler - 'rmic'
*Note: we make a stub file from the '*.class' file with the implementation of the remote interface, not from the '*.java' file.
 
<syntaxhighlight lang=dos>
rmic RmiServer
 
</syntaxhighlight>
Note that since version 5.0 of J2SE support for dynamically generated stub files has been added, and rmic is only provided for backwards compatibility with earlier runtimes,<ref>{{cite web|title=Java RMI Release Notes|url=http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/relnotes.html|publisher=Oracle|access-date=9 May 2012}}</ref> or for programs that don't provide an explicit port number (or zero) when exporting remote objects, which is required for generated stubs to be possible, as described in the Javadoc for UnicastRemoteObject. See the comment in the constructor above.