What is the workflow for application startup and configuration when using Apache TomEE
Asked Answered
M

1

7

I understand that Apache TomEE is a regular Tomcat installation with openejb as a web app.

I am trying to understand how all this bootstraps. I will try and ask a few directed questions:

  • Is it important to have an application startup order ? Should openejb start before my web app, or the other way round, or does it not matter ?
  • Related to the earlier question. How does an enterprise application register it's beans with openejb, or is it that openejb goes around hunting for enterprise applications in the same server, for EJB's ?
  • At a very layman level, how were they able to provide openejb as the EJB container, when it is a different web app. (IIRC every webapp in Tomcat gets a different classpath and they cannot step on each other's toes)

Any other important information.

Mello answered 18/4, 2012 at 8:42 Comment(0)
S
8

The integration is bootstrapped via this line in the conf/server.xml:

<Listener className="org.apache.tomee.loader.OpenEJBListener" />

This happens immediately at startup before any applications are started. The libraries from the <tomcat-home>/webapps/openejb/lib directory are added to the Tomcat system classloader, another listener is installed to participate in deployment and from then on out everything happens using events in the Tomcat lifecycle. Tomcat will issue several events at application startup (deploy) and shutdown. Tomcat itself uses them for deployment of servlets and essentially the integration is just more of the same. Other vendors that include Tomcat also use these hooks. From that perspective the integration is really quite boring :)

The only interesting twist is putting the extra libraries in a war file. That's really only done to make delivering the and adding the extra libraries to an existing Tomcat install as easy as possible (and as easy as possible to remove). All the libraries from <tomcat-home>/webapps/openejb/lib could just as easily go right in <tomcat-home>/lib. At which point, the only thing you might want the webapss/openejb/ war for is to be able to invoke EJBs over HTTP.

So the short answers are:

  • Appliction startup order doesn't matter
  • EJB Deployment happens side-by-side with Servlet deployment
  • Jars are added to the Tomcat system classloader immediately on Tomcat itself starts up

Interesting thing to note in the other answer is that Tomcat actually starts up with only two jars in the classpath. Tomcat itself actually adds all the jars from <tomcat-home>/lib/ automatically at startup. We're basically doing the same thing, just from <tomcat-home>/webapps/openejb/lib

I don't think we've actually tested moving the libraries into <tomcat-home>/lib/ and deleting the openejb webapp (which is called tomee.war in the coming final release), but I'll make a note to try that. Seems like a good thing to support or maybe even do by default. You can delete the Tomcat manager and ROOT webapps, so it seems like a good idea to make it easy to delete the openejb.war as well.

Shote answered 19/4, 2012 at 8:7 Comment(4)
You mention 'At which point, the only thing you might want the webapss/openejb/ war for is to be able to invoke EJBs over HTTP.' I am sorry if the answer is obvious, but why would we not be able to service HTTP requests for EJB's if we have all openejb jars in <tomcat-home>/lib ?Mello
What I meant was if the libs were moved and the webapps/openejb war was deleted, then EJB over HTTP functionality would be removed.Shote
Couldn't resist trying the moved libs thing. I had to tweak the Listener we use, but it works great and makes the Eclipse tooling so much easier and a bit faster actually. Running it through the TCK now and if it looks good, we might see this in the final release -- the vote goes up in 4 hours. Thanks so much for the your question -- who knew it would lead to this.Shote
Thanks for doing the experiment and also running it through the TCK. The ease of tooling support is always very welcome :-)Mello

© 2022 - 2024 — McMap. All rights reserved.