EJB core technology and its application Author: Anonymous Published: 2004-9-22 12:30:07
EJB core technology and its application: cycle Abstract: EJB stands for Enterprise java bean. It is a commercial application component technology in Java. The role EJB component structure in the EJB structure is a component-based distributed computing structure, which is a component in a distributed application ... 1. EJB technology introduction EJB's full name is Enterprise Java Bean. It is a commercial application component technology in Java. The role EJB component structure in the EJB structure is a component-based distributed computing structure, which is a component in a distributed application. A complete EJB-based distributed computing structure consists of six roles, which can be provided by different developers, and every role must follow the EJB specification provided by Sun to ensure compatibility between each other. Sex. These six characters are EJB component developers, Application ASSEMBLERs, deployers, EJB server providers, EJB container providers (EJB container providers, System Administrator: Second, the analysis of each role in EJB 1. EJB component developer (Enterprise Bean Provider) EJB component developer is responsible for the development of EJB components that perform business logic rules, and the developed EJB component is packaged into EJB- JAR file. The EJB component developer is responsible for defining the EJB's REMOTE and HOME interface, writing EJB Class, executing business logic, providing deployment descriptor. The deployment file contains the name of EJB, and the resource configuration used by EJB, such as JDBC, etc. EJB Components Developers are typical business application development field experts. EJB component developers do not need to be proficient in system-level programming, so you don't need to know some system-level processing details, such as transactions, synchronization, security, distributed calculations. 2. Application ASSEMBLER Application Components is responsible for using a complete application system using various EJBs. Application portfoliors sometimes need to provide some related programs, such as in an e-commerce system, application portfoliors need to provide JSP (Java Server Page). Application portfoliors must master the EJB HOME and REMOTE interface used, but do not need to know the implementation of these interfaces. 3. Deployer deployers are responsible for deploying the EJB-JAR file to the user's system environment. The system environment contains some EJB Server and EJB Container. Deployers must guarantee that all resources declared by the EJB component developer in the deployment file, for example, deployers must configure the database resources required for EJB. Deployment procedures Two steps: Deployers first use the tools provided by EJB Container to generate some classes and interfaces, so that EJB Container can use these classes and interfaces to manage EJBs in operation. Deployers Install the EJB component and other classes generated in the previous step to EJB Container. Deployers are an expert in an EJB operating environment. In some cases, deployers need to understand the business methods included in EJB in deployment to write some simple program tests after deployment. 4, EJB Server Provider (EJB Server Provider) EJB server provider is an expert in the system, proficient in distributed transaction management, distributed object management, and other system-level services. EJB server providers are generally provided by operating system developers, middleware developers, or database developers. In the current EJB specification, assume that the EJB server provider and the EJB container provider come from the same developer, so no interface criteria between the EJB server provider and the EJB container provider are defined. 5. EJB Container Provider (EJB Container Provider) EJB container provider provides the following features: Provide EJB deployment tools to provide an operational environment for deploying EJB components.
The EJB container is responsible for providing transaction management, safety management such as EJB. The EJB container provider must be a system-level programming expert, but also have some experience in the application. The work of the EJB container provider is mainly focused on the development of a retractable and transaction management functionality in the EJB server. EJB container providers provide a set of standards for EJB component developers, easy-to-use API access to EJB containers, so that EJB component developers do not need to understand various technical details in the EJB server. The EJB container provider is responsible for providing system monitoring tools to monitor EJB containers in real time and the state of EJB components running in the container. 6. System administrator system administrators are responsible for providing an enterprise-level computing and network environment for EJB servers and containers. System administrators are responsible for monitoring the operation of EJB components using the Monitoring Management Tools provided by EJB servers and containers. Third, EJB architecture: EJB distributed application is an API technology based on the object component model, the low-level transaction service. EJB technology simplifies the development and configuration of enterprise application systems written in Java language. EJB technology defines a set of reusable components: Enterprise Beans. You can take advantage of these components, build your distributed application like wood. When you write the code, these components are combined into a specific file. Each file has one or more Enterprise Beans, plus some configuration parameters. Finally, these Enterprise Beans are configured to a platform with EJB containers. Customers are able to locate a beans through these beans's Home interface, and generate an instance of this beans. In this way, customers can call Beans Application and Remote Interface. The EJB server manages EJB containers and functions as bridges of the container and low-level platforms. It provides the ability to access system services to the EJB container. For example: the management and transaction management of the database, or for other Enterprise application servers. All EJB instances run in the EJB container. The container provides a system-level service that controls the life cycle of EJB. There are some easy-to-use management tools in EJB, such as: The Deployment Descriptor defines different application functions that customers accessible. The container reaches this effect by accessing these functions that only allow authorized customers. The Remote Connectivity-Container manages the low-level communication Issues for remote links, and has hidden communications details for Enterprise Beas developers and customers. EJB developers are like a local platform when writing application methods. Customers are not clear that the methods they call may be processed remotely. Life Cycle Managing - Customer Create an instance of Enterprise Beans and typically cancel an instance. The container manages instances of Enterprise Beans, enabling Enterprise Beans to maximize the maximum efficiency and memory utilization. The container can activate and make Enterprise Beans to maintain the instance pool shared by many customers. and many more. The TRASCTION Management-Configuration Description Defines the needs of the transaction processing of Enterprise Beans. The container manages complex Issues that manages distributed transactions. These transactions may have to update the database between different platforms. The container makes each of these transactions independently and does not interfere with each other. Ensure that all updated databases are successful, and whether they are rolled back to the state before transaction. The EJB component is a component of an enterprise-class application based on distributed transactions. All EJBs have the following features: EJB contains application logic for processing corporate data. Define the EJB customer interface. Such interfaces are not affected by the containers and servers. Thus, when an EJB is set to an application, do not change the code and recompile.
EJB can be customized for various system-level services, such as security and transactional characteristics, are not belonging to the EJB class. Instead, it is implemented by a tool for configuring and assembling an application. There are two types of EJB: Session Beans and Entity Beans.Session Beans are an object that is performed as a single user. As a corresponding to the remote task request, the container generates an instance of a session beans. A session beans have a user. From a certain extent, a session bean represents the user of the user. Thesession beans can also be used for transactions, it can update the shared data, but it does not depict these Shared data. The life cycle of Session Beans is relatively short. Typically, the session beans are only living when the user keeps a session. Once the user quits, Session Beans will no longer be associated with the user. Session Beans is seen as instantaneous because if the container crashes, the user must re-establish a new session object to continue the session. Session bean is typical to declare interoperability or session with users. That is, the session bean masters the user's information through the customer session. A stateful session bean called a stateful Session bean. When the user terminates interoperability with the session beans. The session is terminated, and the bean no longer has a status value. Session bean may also be a stateless session bean. The stateless session beans do not have information or status of its customers. Users can call Beans to complete some operations. However, Beans only knows the user's parameter variable when the method is called. Beans do not continue to maintain these parameter variables after the method call is completed. Thus, all instances of all stateful session beans are the same unless it is in the method call. In this way, the SESSION Beans that can be supported by the stateless session beans. The container can declare a stateless session beans. You can specify any session beans to any user. Entity Beans provides an object of the database. For example: an Entity bean can simulate a line of data in a database table. Multiple clients can share access to the same entity bean. Multiple Client can also access the same Entity Bean.EnTity Beans to access or update the underlying data through the context of the transaction. In this way, the integrity of the data can be guaranteed. Entity Beans can survive the time of relatively long, and the status is continuous. Entity Beans has always survive as long as the data in the database exists. Not in accordance with the application or service process. Even if the EJB container crashes, Entity Beans is also survived. The Entity Beans life cycle can be managed by the container or Beans. If the container is controlled to ensure continuous ISSUS for Entity Beans. If you manage it yourself by Beans, you must write the code of Entity Beans, including access to the database. Entity Beans is identified by the primary key (a unique object identifier) of Primary Key). Typically, the primary key is the same as one of the data in the identity database, such as one line in a table, and the primary key. The primary key is that the client is able to locate a specific data block. V. EJB programming environment: 1, using JBuilder JBuilder and EJB Container can perform seamless connection.
JBuilder and Inprise application servers include tools for developing and configuring Enterprise Beans, and libraries required: Run and Manage Enterprise Beans, Naming Services, Transaction Services, Java Databases, APIs needed to develop Enterprise Beans, an enhancement Java-to-IIOP compiler, support value type, and RMI signal, etc. JBuilder also provides a tool and wizard for fast development applications Enterprise Beans. By simple and intuitive steps, the wizard helps you build an Enterprise Bean. I set some default values, generated the template of the bean. Only, we can add our own application logic. JBuilder also provides an EJB interface generation wizard. The wizard generates a Remote interface and a Home interface based on the public method of Enterprise Bean. JBuilder also provides a wizard of a configurator to help us build an XML descriptor file step by step. And generate the Stubs to a JAR file. 2. Use an integrated environment other than JBuilder: If you use other integrated environments (IDEs). To determine the container tools that integrated analog environment IDE. Also verify that the IDE supports the corresponding version of the EJB specification, and it is necessary to determine if it is correctly supporting the EJB API. To determine the version of the JD to the supported EJB container. You can determine the version of the support JDK supported by the EJB container by checking the installation instructions of the Inprise. When configuring Enterprise Beans, you must use the tools provided by the INPRISE application server. These tools can edit and modify the INPRISE configuration descriptor provided by third-party agents. It is also possible to verify the configuration descriptor to verify the source code of the bean. Six, a simple Hello Example 1, install the APUSIC Application Server Note: The following uses Linux as an example to illustrate the installation process of the Apusic Application Server. For other platforms, please refer to the APUSIC Application Server installation manual. Download JDK1.2, Apusic Application Server must run in a JDK 1.2 environment. You can download the latest JDK from the following site. Http://java.sun.com Download APUSIC Application ServerApusic Application Server Trial Edition You can get from the following URL: http://www.apusic.com/download/enter.jsp After downloading, you can get a parcel file APUSIC .zip, select the installation directory, assume it installed to / usr, use the following command: CD / usrjar XVF apusic.zip / usr will appear under the APUSIC Application Server all programs are extracted to / usr / apusic under. Add the following path to classpath /usr/apusic/lib/apusic.jar $java_home/lib/tools.jar Run APusic Application Server Java -XMS64M com.apusic.server.main -root / usr / apusic 2 with the following command Defining an EJB Remote Interface Any EJB is called via Remote Interface, and EJB developers first define this EJB can be called all methods of being called in the Remote Interface. The class executing the Remote Interface is generated by the EJB generation tool.
The following are HelloBean of Remote Inteface program: package ejb.hello; import java.rmi.RemoteException; import java.rmi.Remote; import javax.ejb *; public interface Hello extends EJBObject, Remote {// this method just get "Hello. World "from hellobean.public string getHello () throws remoteException;} 3, Define Home Interface EJB Container Create an EJB instance via EJB's Home Interface, like Remote Interface, and execute Home Interface is generated by EJB generation tool. The following are HelloBean the Home Interface program: package ejb.hello; import javax.ejb *; import java.rmi.Remote; import java.rmi.RemoteException; import java.util *; / *** This interface is extremely simple.. . it declares only * one create method * / public interface HelloHome extends EJBHome {public Hello create () throws CreateException, RemoteException;} 4, EJB class written in an EJB class, the programmer must be given remote method defined in the remote interface Specific implementation. The EJB class also includes a method that must be implemented in some EJB specification. These methods have a more unified implementation template, and the programmer only costs in the implementation of the specific business method.
The following code is HelloBean: package ejb.hello; import javax.ejb *; import java.util *; import java.rmi *; public class HelloBean implements SessionBean {static final boolean verbose = true; private transient SessionContext ctx;... // Implement the methods in the SessionBean // interfacepublic void ejbActivate () {if (verbose) System.out.println ( "ejbActivate called");} public void ejbRemove () {if (verbose) System.out.println ( " ejbRemove called ");} public void ejbPassivate () {if (verbose) System.out.println (" ejbPassivate called ");} / *** Sets the session context ** @param SessionContext * / public void setSessionContext (SessionContext. CTX) {if (verbose) System.out.println; this.ctx = ctx;} / *** this method in * The home interface hellohod in * the home interface hellohome.java. * The parameter sets of the two methods are * identical. When the client calls * HelloHome.create (), the container allocates an * instance of the EJBean and calls ejbCreate (). * / public void ejbCreate () {if (verbose) Syst Em.out.println ("ejbcreate caled");} / *** **** Here is the business logic ****** The getHello Just Return A "Hello World" string. * / public string getHello () THROWS RemoteException {return ("Hello World");}} 5, create an EJB-JAR.XML file EJB-jar.xml file is the deployment description file of EJB, including the various configuration information of EJB, such as state bean (stateful bean ) Or stateless bean, transaction type, etc. See the EJB specification for more information on EJB-JAR.XML files.
The following is the configuration file of Hellobean: XML Version = "1.0"?>