Reputation: 11251
I am playing around with JBoss and EJB, I use jboss-eap-quickstarts
I have server-side
class:
package org.jboss.as.quickstarts.ejb.remote.stateless;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Remote(RemoteCalculator.class)
public class CalculatorBean implements RemoteCalculator {
@Override
public int add(int a, int b) {
return a + b;
}
@Override
public int subtract(int a, int b) {
return a - b;
}
}
And I have client-side
method:
private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
return (RemoteCalculator) context.lookup(
"ejb:/jboss-as-ejb-remote-server-side/CalculatorBean!" + RemoteCalculator.class.getName()
);
}
The questions are:
Class
/ Object
/ both? How
did client find classes/objects? ejb:/jboss-as-ejb-remote-server-side/CalculatorBean!" +
RemoteCalculator.class.getName()
help hence it doesn't know
host:port
? CalculatorBean
logic on the server
or
client
side? Again if it was executed at the Server
, how did
exchange of values between two jvm
s worked?Upvotes: 5
Views: 12825
Reputation: 2991
EJBs are based on the concept of RMI (remote method invocation) over IIOP that helps bring corba into the java world.
On the server side, there are three parts:
javax.ejb.EJBHome
that must contain a create()
method. Used by client code to create a bean instance.javax.ejb.EJBObject
that declares all methods that you'd wish your client code should be able to access. On the client side, you must first lookup
the ejb. This is where JNDI comes in picture. There is no need of host:port
because you have to register the bean in the Java Naming Directory on the server side. This registry is made with a name (represented by ejb:/jboss-as-ejb-remote-server-side/CalculatorBean!" + RemoteCalculator.class.getName()
) in your case.
This is published by the server and the client uses it to access the Home interface. This in turn gives you access to all the implemented methods in the bean, that are declared in the remote interface.
Hope this addresses your three questions.
Upvotes: 3
Reputation: 1067
The client finds the classes/objects because the client have dependencies to the interfaces of the server-side (pom.xml
file).
It finds the host:port thanks to the file jboss-eap-quickstarts/ejb-remote/client/src/main/resources/jboss-ejb-client.properties
Note that you can configure your server to expose your services on a different port.
CalculatorBean
logic will be executed on the server side.
For all questions that i've not answered, (What's deployed where, exchange of values between jvm and how the JNDI address (ejb:/ ...
) allow the client to find the correct service), you should read about how JNDI and EJBs work.
Here is a good start :
Upvotes: 5