Tutorial for building J2ee Applications Using Jboss and Eclipse Chapter 4

zhaozj2021-02-16  115

All the way, the STATEFULE Seesion Bean and Stateless Session Beand is done, and it is still a little blur, so he reused "Mastering EJB 2nd" and Sun training tutorial SL - 351 finally has a new understanding of EJB.

First look at the picture below:

EJB's entire request process

The above figure completes the specific process of requesting the EJB method. The home interface of this process is an EJBHOME interface, which uses the EJBOBJECT interface. What interfaces I have described here is to add an efficient interface EjblocalHome and EjBlocalobject in EJB 2.0. In fact, it is a reference to EJBHOME and EJBOBJECT, get the reference to EjBlocalObject by ejblocalhome. These two different ways are mainly efficient in the "Mastering EJB" book.

EjbHome-> EjbOjbect1. The client calls a local stub.2. The stub marshals parameters into a form suitable for the network.3. The stub goes over a network connection to the skeleton.4. The skeleton demarshals parameters into a form suitable for Java.5. The skeleton calls the EJB object.6. The EJB object performs needed middleware, such as connection pooling, transactions, security, and lifecycle services.7. Once the EJB object calls the enterprise bean instance, and the bean doesits work Each of the preceding steps must be used for the return host.

EjbLocalHome-> EjbLocalObject1. The client calls a local object.2. The local object performs needed middleware, such as connection pooling, transactions, security, and lifecycle services.3. Once the enterprise bean instance does its work, it returns control to the Local Object, Which the returns control to the client.

From the above process, you can know that you can save a few steps using the Local interface. I have not understood how it is applied to this interface. I will put it down first, wait for the opportunity to try.

The EJB Model of the figure shows all interfaces that EJB2.0 can use.

For example, the STATELESS SESSION bean of the Tutorial, the STATELESS Session Bean, I refer to the tutorial of Sun SL-351. The picture of these two beans is good, I will pick it up.

Container Creates A stateless session bean

In the figure, Step 1 is Contariner instantiation an EJB Object, which is to save more resources until the Session bean is called, or it has been removed from Pool. In the "Mastering EJB" P48, how many beans correspond to an EJBHOME, how many beans correspond to the container used, may be 1: N, may be M: N, and these For those who write beans are transparent, it is mainly to choose a high-performance container. STEP 2 1. CLIENT calls a business method, if it is STATELESS BEAN not found in pool, follow these steps: a. Container initializes session context. (Session Context is still not figured out now, and then study again) b. If you find Beans in pool, move it to Working Area. Otherwise, instantiate it with a non-parameter constructor. C. Session Context is initialized, and the reference is passed to the new bean via setSessionContext. D. To call EjbCreate in the Create method, these two methods are one or one, and there must be an EJBCREATE in the bean. 2. Call the business method in the bean instance. Container Creates a Statelful Session Bean

When a Client end calls Home's Create, the following steps will happen. 1. Container initializes EJB Object. 2. Container initializes session context. 3. Bean will create (as long as you do not define other constructor) 4. Session Context is initialized, and the reference is passed to bean via setSessionContext. 5. The CREATE parameter is passed by the client through Home Object, and then passed to the corresponding EJBCREATE corresponding to the bean.

One obvious difference between the two bean types is that when the Client calls Home Object's Create method, StateFule can take parameters, and Stateless does not allow with parameters.

The Remove of the session bean can also pass the server through the client.

Summary: Reference "MASTERING EJB"

The enterprise bean instance is a Java object instance of an enterprise bean class. It contains business method implementations of the methods defined in the remote and / or local interface. The enterprise bean instance is networkless in that it contains no networked logic.The remote interface is a Java interface that enumerates the business methods exposed by the enterprise bean class. in EJB, client code always goes through the remote interface and never interacts with the enterprise beaninstance. The remote interface is network-aware in that the interface obeys the rules for Java RMI-IIOP.The local interface is the high-performing version of the remote interface.Use the local interface when you are calling enterprise beans that live in the same process. Your calls will not undergo stubs, skeletons, network calls, or marshaling / demarshaling of parameters.The EJB Object Is The Container-Generated Implement OF THE Remote Interface. The EJB Object IS A Network-Aware Intermediate Betw een the client and the bean instance, handling necessary middleware issues. All client invocations go through the EJB object. The EJB object delegates calls to enterprise bean instances and implements the remote interface.The local object is the high-performing version of the EJB object . The local object implements the local interface.The home interface is a Java interface that serves as a factory for EJB objects.Client code that wants to work with EJB objects must use the home interface to generate them. The home interface is network-aware .

转载请注明原文地址:https://www.9cbs.com/read-13974.html

New Post(0)