Openejb :: container :: core framework source interpretation and development guide
Openejb :: container :: core framework source interpretation and development guide
Openejb is an open source enterprise Javaee application container and server.OpenEjb Container Core is the core component of OpenEjb, which provides complete container services and functions, including EJB containers, web containers, JMS containers, etc.This article will interpret the source code of the OpenEjb Container Core framework and provide development guidelines and example code to help readers better understand and use the framework.
1. Openejb Container Core framework structure
OpenEjb Container Core framework is mainly composed of the following modules:
1.1. Core container module (OpenEjb-Core): For the life cycle of managing containers, the resources required to load and initialize the container, and provide the function of the container start and close.
1.2. EJB container module (OpenEjb-EJB-core): It is used to manage the life cycle of EJB components, including EJB creation, injecting dependence, transaction management, safety inspection, etc.This module also handles events and callbacks in the EJB life cycle.
1.3. Web container module (OpenEjb-Web): It is used to manage the life cycle of web applications, including deployment, loading and uninstallation of Web applications.This module also provides support for web components such as Servlet, Filter, Listener.
1.4. JMS container module (OpenEjb-JMS): It is used to manage the JMS (Java Message Service) message queue and theme.This module provides the ability to send, receive and process the JMS message.
2. OpenEjb Container Core Framework Source Interpretation and Development Guide
2.1. Container life cycle management
The core of the OpenEjb Container Core framework is the life cycle management of the container.Container life cycle management includes the process of creation, initialization, starting, and closing of containers.In OpenEjb Container Core, the life cycle management of the container is implemented by the core container module.The following is a simple example code, which demonstrates how to create and start an EJB container:
import org.apache.openejb.OpenEjbContainer;
import org.apache.openejb.loader.Options;
import javax.ejb.embeddable.EJBContainer;
public class ContainerManager {
public static void main(String[] args) {
Options options = new Options();
options.put(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, Boolean.TRUE.toString());
EJBContainer container = EJBContainer.createEJBContainer(options);
// Treatment logic after the container startup
// ...
container.close (); // Close the container
}
}
2.2. EJB container management
OpenEjb Container Core framework provides a complete EJB container management function.Through the EJB container module (OpenJB-EJB-core), you can manage the life cycle, dependency injection, transaction management, etc. of the EJB component.The following is an example code of a simple stateless session bean:
import javax.ejb.Stateless;
@Stateless
public class HelloBean {
public String sayHello(String name) {
return "Hello, " + name + "!";
}
}
2.3. Web application management
OpenEjb Container Core framework also provides management functions for web applications.Through the web container module (OpenEjb-Web), we can deploy, load and uninstall the web application.The following is a simple Servlet example code:
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.getWriter().print("Hello, World!");
}
}
2.4. JMS Message Management
OpenEjb Container Core framework also provides management functions of JMS messages.Through the JMS container module (OpenEjb-JMS), JMS messages can be sent, received and processed.The following is a simple example code sent by a simple JMS message:
import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Queue;
public class MessageSender {
@Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "java:comp/DefaultJMSQueue")
private static Queue queue;
public static void main(String[] args) {
try (JMSContext context = connectionFactory.createContext()) {
context.createProducer().send(queue, "Hello, World!");
}
}
}
3. Summary
This article introduces the source code interpretation and development guide for OpenEjb Container Core framework.Through the interpretation of the source code, readers can better understand and use the OpenEjb Container core framework, and use it flexibly in actual development.It is hoped that this article can help readers with a certain help when developing the OpenEjb Container Core framework.