Module 11 At the end of this module you will be able to: 9 Describe the differences between EJB types 9 Deploy EJBs 9 Define an Enterprise Application 9 Dxplain the directory structure of an Enterprise Application 9 Work with -1 2004 BEA Systems, Inc. 1 This module discusses components, EJBs, and their structures. This module introduces the major EJB types and the EJB specification. The module also covers, their structure, their benefit, and configuring them. 1
Road Map 1. EJB Applications Major EJB Types and Their Purpose 2. -2 2004 BEA Systems, Inc. 2 2
Enterprise JavaBeans f Enterprise JavaBeans (EJB) standardizes development and deployment of Java server components. f The EJB specification defines relationships between: the EJB and its container the container and the application server the container and the client -3 2004 BEA Systems, Inc. 3 Enterprise JavaBeans (EJB) is a component architecture specification that defines the structure of beans, the structure of the containers in which they operate, and the methods for interaction with their clients. Infrastructure services, application server implementation, and client implementation are defined by the developer and application server vendor. For more information about EJBs and to view the EJB specification, see http://java.sun.com/ejb. 3
Types of EJBs EJB Type Stateless Session Stateful Session Entity Message Driven Description fdo not maintain state fare synchronous fdo not survive crashes fare maintained in memory fconversational interaction fmaintain state for client fare synchronous fdo not survive crashes frepresent persisted data fcan survive a crash fare synchronous fasynchronous & stateless fconsume JMS messages Example fcheck validity of stock symbol fcalculate billing of a phone call fbook a flight & car rental for travel fmanage a shopping cart frepresent a player s statistics frepresent a stock s history fstore logging messages -4 2004 BEA Systems, Inc. 4 Each of the EJBs has a particular design approach and requirements for its construction. There are many benefits that result from having a variety of EJB types. The differences in EJB types allow an application server to optimize performance by being able to make assumptions about the state and persistence level of the component. The EJBs that have no state management can have a higher degree of pooling than EJBs that have state. There are three levels of state behavior that a component can assume: no state, not persisted, persisted Stateless session EJBs are components that implement a single-use service. That service can be invoked many times, but since the component does not maintain any state, the resulting effect is that the invocation provided a single use. In a lot of ways, session beans provide a reusable single-use service. Stateful session beans are very similar to their stateless session bean counterparts. In fact, stateful session beans and stateless session beans are implemented in exactly the same manner. So, what is different about them? Stateful session beans are designed to maintain state across multiple client invocations on behalf of the client. The stateful session bean does this by storing stateful properties in the attributes of the component itself. An EJB container is then responsible for ensuring that subsequent client invocations for the same stateful bean are routed back to the object that hosts the stateful attributes. When we say an EJB is persistent, we mean that the data in the EJB will persist or exist whether the EJB is currently in memory or not. The persistence of an EJB can be implemented in a variety of ways. For instance, the object could be stored in a relational database, stored in a file, or placed in another form of media. 4
EJB Application Directory Structure f EJB components come packaged in JAR files. f EJBs are configured by modifying deployment descriptors. EJB App JAR Format: -5 2004 BEA Systems, Inc. 5 EJB are deployed in the form of a JAR archive file. As with Web applications, EJB applications must follow a specific structure and contains XML deployment descriptors. Here s an overview of the various files and folders involved: The staging directory: The staging directory is somewhere where the JAR file image is being built. This folder does not end up inside the JAR file, but instead its contents end up as the root of the JAR file. Class files for the EJBs. The root of the JAR file contains class files and folders that form the packages for these EJBs. META-INF: This folder contains the deployment descriptors and the utility classes and libraries: ejb-jar.xml: standard deployment descriptor weblogic-ejb-jar.xml: WebLogic-specific deployment descriptor weblogic-cmp-rdbms-jar.xml: WebLogic-specific deployment descriptor used for object-to-relational mapping of CMP Entity EJBs. classes folder: contains the class files for utility objects, and the folders that form the packages of these classes. lib folder: contains the library files for utility objects (JAR files) 5
EJB Administrator Tasks with WLS f EJB administrator tasks include: configure and deploy resolve JNDI and other infrastructure issues monitor EJB caches and pools -6 2004 BEA Systems, Inc. 6 So the different tasks that administrator should be aware of are: 1. Setting up stateless session EJBs pool size. 2. Setting up stateful session EJBs cache size and related information. 3. Setting up entity EJBs pool and cache size, and related information. Other administrative tasks include clustering settings, but this is the topic of another module. 6
EJB Deployment f Use the same methods as for Web Application deployment: auto-deployment console deployment command-line deployment -7 2004 BEA Systems, Inc. 7 Deployment of an EJB is similar to deployment of Resource Adaptors, Web applications, and Enterprise Applications. Like these deployment units, you can deploy an EJB in an exploded directory format or as an archive file. To view all the deployed EJB Applications OR to deploy a new EJB Application, Select Deployment > EJB Modules. 7
EJB Redeployment Considerations f To update EJB Applications from the console: 1 2 f Note that: only implementation classes can be updated interfaces cannot be updated -8 2004 BEA Systems, Inc. 8 Once an EJB has been successfully deployed, if you make a change to the deployed EJB, you must redeploy the EJB for the changes to take effect. From the WebLogic Server Administration Console update EJB as follows: 1. Choose EJB from the Deployments node in the left pane of the Console.. 2. Choose the Deploy tab from the dialog in the right pane and update the EJB by clicking the Redeploy b. You can update only the EJB implementation class, not the public interfaces or public support classes. If you change the contents of a compiled ejb.jar file in applications (by repackaging, recompiling, or copying over the existing ejb.jar), WebLogic Server automatically attempts to redeploy the ejb.jar file using the automatic deployment feature. Note: Because the automatic redeployment feature uses dynamic deployment, WebLogic Server can only redeploy an EJB s implementation classes. You cannot redeploy an EJB s public interfaces Should you ever modify an uncompiled ejbc.jar in the applications directory (either by repackaging or copying over the JAR file), WebLogic Server automatically recompiles and redeploys the JAR using the same steps. Note: Because the automatic redeployment feature uses dynamic deployment, WebLogic Server can only redeploy an EJB s implementation classes. You cannot redeploy an EJB s public interfaces. Take a look at http://e-docs.bea.com/wls/docs81/ejb/deploy.html 8
Monitoring EJB Applications -9 2004 BEA Systems, Inc. 9 To Monitor EJB Applications, select the Deployment > EJB Modules. Select the Monitoring tab to monitor tab to view different types of EJBs. 9
Monitoring EJBs -10 2004 BEA Systems, Inc. 10 To Monitor a specific EJB Application, select the EJB Application >Monitoring. You can selectively see the EJB monitoring information on a specific WebLogic Server under the Stateless EJBs, Stateful EJBs and Entity EJBs tab. 10
Section Review In this section we discussed: 9 EJB applications 9 Major types of Enterprise JavaBeans (EJBs) 9 EJB application configuration -11 2004 BEA Systems, Inc. 11 11
Road Map 1. EJB Applications 2. Enterprise Application Concepts Enterprise Archive (.ear) File Structure Enterprise Application Configuration Enterprise Application Deployment -12 2004 BEA Systems, Inc. 12 12
What Is an Enterprise Application? f An enterprise application is a grouping of several resources into one deployable unit packaged in an.ear file. f These resources include: Web applications (.war) EJB applications (.jar) Java applications (.jar) Resource adapters (.rar) -13 2004 BEA Systems, Inc. 13 An Enterprise Application is an archive file that packages up a Web Application along with any resources it might require. Typically, an enterprise application includes a.war file, one or more support.jar files, and any Enterprise JavaBeans the application may required. 13
Why? f Use enterprise applications to: avoid name space clashes declare Enterprise-wide security roles deploy an application as one unit share Enterprise-wide EJB resources configure local JDBC pools configure local XML resources -14 2004 BEA Systems, Inc. 14 Enterprise applications are more than a packaging mechanism. We must consider security, resources, and deployment issues when we deploy applications in a running system. We can package an application into a single coherent unit with enterprise applications. The application, its security constraints and its resources are packaged and deployed together to simplify system management. However, there are occasional reasons why you would NOT package an application into an.ear file. The most common reason is EJB use. If you have an EJB that is used by a large number of enterprise applications, it may be easier to deploy the EJB and Web applications that use it separately. 14
EAR File Structure f An example directory structure of an enterprise applicationtton is shown below: Directory / File Description Document root of enterprise application META-INF directory Enterprise application deployment descriptor WLS Enterprise application deployment descriptor An EJB module Another EJB module A Java module Another Java module A Web Application module Another Web Application module -15 2004 BEA Systems, Inc. 15 The table shows a sample enterprise application directory structure. 15
Configuring WLS Specific Features f Configure Enterprise-wide WLS specific features with weblogic-application.xml deployment descriptor: XML parsers XML entity mappings JDBC connection pools security realms -16 2004 BEA Systems, Inc. 16 Application scoping refers to configuring resources for a particular enterprise application rather than for an entire WebLogic Server configuration. In the case of XML, these resources include parser, transformer, external entity, and external entity cache configuration. The main advantage of application scoping is that it isolates the resources for a given application to the application itself. Using application scoping, you can configure different parsers for different applications, store the DTDs for an application within the EAR file or exploded enterprise directory, and so on. Another advantage of using application scoping is that by associating the resources with the EAR file, you can run this EAR file on another instance of WebLogic Server without having to configure the resources for that server. To configure XML resources for a particular application, you add information to the weblogicapplication.xml deployment descriptor file located in the META-INF directory of the EAR file or exploded enterprise application directory. For more information see: http://e-docs.bea.com/wls/docs81/xml/xml_appscop.html#1073644 http://e-docs.bea.com/wls/docs81/programming/app_xml.html#1039668 http://e-docs.bea.com/wls/docs81/ejb/ejb_environment.html 16
Deploying EJBs and Enterprise Applications f Use the same methods as for Web Application deployment: auto-deployment console deployment command-line deployment f Applications and EJBs can be deployed: in an archived file (.ear,.jar) or in exploded (open) directory format -17 2004 BEA Systems, Inc. 17 WebLogic Server 8.1 supports the same three distinct deployment methods as we discussed previously for Web Applications. The reason that different types of deployments are provided is because different types of scenarios exist in which applications execute. For instance, a WebLogic Server system could be used be used for development, staging, or production. The method of deployment could be dependent upon the domain that it is deployed to. 17
Deploying f are administered as a unit: WLS separates Web and EJB modules (.war,.jar) into deployment units modules can be individually deployed, redeployed and undeployed modules can be individually configured and monitored 1 2 3 4-18 2004 BEA Systems, Inc. 18 Using the Deployment Assistant, locate the EAR file you would like to configure for use with WebLogic Server. You can also configure an "exploded" Enterprise Application or component directory. Note that WebLogic Server will deploy all components it finds in and below the specified directory. When you have located the archive file to configure, if you want to deploy the whole application to server(s) click Target Application. If deploying the applications contained in the enterprise archive selectively to server(s) click Target Each Module. 18
Result of Enterprise Deployment -19 2004 BEA Systems, Inc. 19 When an Enterprise application is deployed, each module appears in the console as a deployment unit and can be administered separately (deployed, redeployed, undeployed and reconfigured). Web application and EJB components can be monitored in the same way as if they were deployed as separated units. 19
Redeployment and Classloaders f Classloaders: allow Java applications to add Java classes to an already executing Java process enable WLS to host several applications in the same JVM ensure that classes of one application do not clash with those of another application are created for each EJB, Web, or Enterprise Application f When a deployed EJB application is updated: classes for the EJB application are marked as unavailable in the server the EJB's classloader and associated classes are removed a new EJB classloader is created which loads and maintains the revised EJB classes -20 2004 BEA Systems, Inc. 20 Changing Classes in a Running Program: WebLogic Server allows application components such as EJBs to be changed to a newer version while the server is running. This process is known as hot-deploy or hot-redeploy and is closely related to classloading. Java classloaders do not have any standard mechanism to undeploy or unload a set of classes. Rather, an application-specific classloader is created as a child of the classpath classloader. When a new version of the application is deployed, a new application classloader is created. This scheme works as long as the application classes are being loaded by the new classloader. If a class is in the system classpath, it cannot be changed while the server is running. Application Classloader Hierarchy: WebLogic Server automatically creates a set of classloaders when an application is deployed. The base application classloader loads any EJB JAR files in the application. A child classloader is created for each Web Application WAR file. Because it is common for Web Applications to call EJBs, the WebLogic Server application classloader architecture allows JavaServer Page (JSP) files and servlets to see the EJB interfaces in their parent classloader. This architecture also allows Web Applications to be redeployed without redeploying the EJB tier. In practice, it is more common to change JSP files and servlets than to change the EJB tier. Refer to http://e-docs.bea.com/wls/docs81/programming/classloading.html for more information. 20
EAR Class Libraries f Extending the J2EE spec, 8.1 has added APP-INF/lib and APP-INF/classes to the standard J2EE ear file. f When the app is initialized, paths extracted are appended to the beginning of the app s $CLASSPATH f Classes are added to the root classloader of the application. -21 2004 BEA Systems, Inc. 21 21
Resource Connector Deployments f WebLogic Server also support the.rar standard for the deployment of J2CA compliant adapters. Inside WebLogic.RAR files are deployed as Resource Connectors RAR files contain all of the necessary information to deploy a J2CA adapter RAR files are deployed in the same manner as a EAR or WAR file Once the RAR files has been deployed it can be configured as a pool, just like a JDBC Connection Pool. -22 2004 BEA Systems, Inc. 22 22
Resource Connector Deployments -23 2004 BEA Systems, Inc. 23 23
Section Review In this section we discussed: 9 The structure of 9 Deploying -24 2004 BEA Systems, Inc. 24 24
Exercise ENTA 18 Deploying Enterprise JavaBeans f In this lab you will deploy Enterprise JavaBeans. f Ask the instructor for any clarification. f The instructor will determine the stop time. Lab Exercise -25 2004 BEA Systems, Inc. 25 25
Exercise ENTA 19 Deploying an Enterprise Application f In this lab you will configure resources used by an Enterprise Application and then deploy the Enterprise Application. f Ask the instructor for any clarification. f The instructor will determine the stop time. Lab Exercise -26 2004 BEA Systems, Inc. 26 26
Module Review In this module we discussed: 9 Enterprise JavaBeans concepts 9 EJB configuration 9 Enterprise Application concepts -27 2004 BEA Systems, Inc. 27 27