I’ve been in the Microsoft world for a while, there are a lot distributed technology in the Microsoft stack. DCOM, COM+,Remoting, ASMX/WCF. What’s the equivalent term for EJB? I would say that’s dot net remoting.
for a typical remoting project, we need define the MBR Object, Host it ( single call, singleton or Client control activation.) using different options, (IIS or in-process hosting. the runtime will take care the proxy/sub stuff.)
here I will put a hello world EJB. Jboss will be the role of IIS.
like remoting,First define a Interface (shared as a contract between server and client. )
public interface ICalculatorBusinessObjects { |
then Implement a MBR like remoting. @Stateless @Override } |
like the Microsoft attribute, those @xx are annotations. the runtime will check thos annotation and enforce some ad-hoc logic. like provide different hosting control, transaction control,etc.
Once Done, need deployed it to a container or server . for .net , it’s just a assembly or a dll. for J2ee, a zip file called EJB jar. you can click eclipse and export the build to a jar file firstEjb.jar
then deploy the jar to Jboss. drag and drop the jar to c:\jboss6\server\default\deploy folder. ( for standard configuration, c:\jboss6\server\all\deploy if you run with –c all option.)
the server discovers new bits and host it, also register a JDNI entry. like the remoting .rem stuff.
the ejb is hosted and ready for client connection now.
for client code, just find the proxy by querying the JNDI server and call the biz logic.
import javax.naming.Context; public class main { public static void main(String[] args) throws NamingException { } |
when you run the jboss, Jboss is also one JNDI server listening one a specific port , 1099 by default.
so you need tell the client, which jndi server we should talk to by put some environment variables like the following.
-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djnp.timeout=0 |
When you run the client, you will get the result as you expected, a simple calculator. but all logic runs on server, the Jboss jvm.
Jboss log.
here concludes the basic tutorial. have fun.
2 comments:
Hi, nice, but @Override are incorrect here, since the bean arent overriding anything, but only implementing the biz interface.
@marcelo
@override here just make sure it overrides the method defined in the interface.
Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.
Post a Comment