File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Question about RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Question about RMI" Watch "Question about RMI" New topic
Author

Question about RMI

Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
If I have stubs running on my machine, in order to call the methods running on some other machine somewhere in the world, I would
call lookup on context and
call narrow on PortableRemoteObject and
call create on the home object as follows:
InitialContext context = new InitialContext();
Object o = context.lookup(jndiNameOfHomeObject);
Home h =
(Home) PortableRemoteObject.narrow(
o,
com.ejb.bmpHome.class);
h.create(param1, param2,�.);

But how does the stub running on my client machine know where in the world is the skeleton is or where is the real method running (the machine name where the method is running). Where do I set that up in the server or where do I mention that in the program?
Thanks in advance.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

You would mention the JNDI lookup name on the DD and the container should take care of making this object available to you once the bean is deployed. I am talking about the EJB-JAR xml file.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Alex,

Q. the machine name where the method is running

A. it's all in the InitialContext. Please note that an instance of the InitialContext can be created
1) with the Hashtable populated with the key/value pairs, one of these pairs would have the provider url, on which the remote class is running
2) with no arguments; all initial context variables are picked up from jndi.properties file.

Eg, JBoss jndi properties file:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces


Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
Thank you for all the replies. So once I got the jar file (with the RMI code), I would have to put that in the build path, then put the jndi name in the ejb-jar.xml. But how do I map the jndi name in the ejb-jar file and the jndi properties file?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The container will take care of binding the JNDI name to its context. The JNDI properties will identify which JNDI initial context to connect to. Its for your client
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
I guess my question is if I get ejb client jars from developers sitting in the other side of the world, how do I set that up in order to call methods in them? I thing the first step is to put the jar file in the build path. Then I put the name in the deployment descriptor (In case of websphere this is ibm-ejb-jar-bnd.xmi. In case of jboss this is jboss.xml). Then where do I specify the name of the remote machine the real method is running (where the skeleton is)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about RMI