I am trying to understand where some of my application logic should go in my Java EE Application. I am new to Java EE and am looking at loading a lot of unstructured data from a legacy database and building a clean object model for use by my application. From my investigation I see Java EE apps have 2 components, Enterprise Bean and Web Application components. This part of my application will be responsible for loading the data, building the object model and sending messages via JMS based on the current state of the data to interested parties. The data will be updated by synchronisation with the database and from messages received via JMS from remote Java applications.
Is an EJB the correct place for this sort of functionality? How can I start the initialisation of my object model (main method Java App equivalent)? What is the best practice for creating a timed event to review the object model and send messages via JMS?
I have read a number of articles on Java EE, Glassfish, EJB's ... but still don't feel I have a clear picture of where I should be writing this functionality. Any examples I have seen of EJB tend to be around direct method calls on the beans from client applications.
At the moment I feel a Java application may do the job but we are looking at using RMI, and web clients in the future.
GlassFish Server implements Java platform, Enterprise Edition (Java EE) 6 technology. The Java EE platform is a set of standard specifications that describe application components, APIs, and the runtime containers and services of an application server.
Eclipse GlassFish Server provides a server for the development and deployment of Java Platform, Enterprise Edition (Java EE platform) applications and web technologies based on Java technology.
A Java EE server is a server application that the implements the Java EE platform APIs and provides the standard Java EE services. Java EE servers are sometimes called application servers, because they allow you to serve application data to clients, much like web servers serve web pages to web browsers.
Java EE is traditionally used for client/server architectural style. The business logic is implemented in EJB session beans, which are usually invoked either from a web request, a JMS message or a RMI-IIOP remote call.
Is an EJB the correct place for this sort of functionality?
The logic goes into the EJB. But there are different types of EJB.
How can I start the initialisation of my object model (main method Java App equivalent)?
There is no such thing as a main
method. But there are still some ways to be perform some processing corresponding to the application deployment and/or undeployment. You can look at ServletContextListener, Glassfish lifecycle module (non-standard) or maybe the newly introduced Singleton beans and @Startup
annotation.
What is the best practice for creating a timed event to review the object model and send messages via JMS?
You can create an EJB Timer which will be called periodically. If you need the model to be loaded once in memory, I would suggest you look at Singleton beans also. With EJB 3.0, the problem was how to start the timer automatically, but I think they improved that in EJB 3.1 and timers can be started automatically by the application server when the application is deployed using the @Scheduled
annotation. So it may somehow provide you with a desired starting point as you asked in your previous question.
You can send JMS message from any bean. JMS an external system just like the database. JMS message are received using special kind of EJB called Message-driven bean (MDB).
You application will not be a traditional web-EJB-database client-server application, but it should be feasible with Java EE which is definitively a very flexible model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With