Monday, December 14, 2015

Business Component Development with EJB Technology - Module 03

Module 3

 Implementing EJB 3.0 Session Beans


Objectives
Upon completion of this module, you should be able to:



  • Create session beans: Essential tasks 
  • Create session beans: Add life-cycle event handlers 
  • Package and deploy session beans 
  • Create a session bean client




Comparison of Stateless and Stateful Behaviors

Session beans can be state lessor stateful.Thestatefulnessofa bean depends on the type of business function it performs:

  • In a stateless client-service interaction, no client-specific information is maintained beyond the duration of a single method invocation. 
Stateful services require that information obtained during one method invocation be available during subsequent method calls: 
  • Shopping Carts 
  • Multi-page data entry 
  • Online banking



Stateless Session Bean Operational Characteristics

With stateless session beans:
  • The bean does not retain client-specific information. 
  • A client might not get the same session bean instance. 
  • Any number of client requests can be handled by the same session bean instance. This has profound performance advantages.



Stateless Session Bean Cardinality






Stateful Session Bean Operational Characteristics

With stateful session beans:
  • The bean belongs to a particular client for an entire conversation.
  • The client connection exists until the client removes the bean or the session times out. 
  • The container maintains a separate session object and EJB instance for each client.



Stateful Session Bean Cardinality







Creating Session Beans : Essential Tasks

  • Declare a business interface for the session bean. 
  • Create the session bean class that implements the business interface. 
  • Configure the session bean by either annotating the session bean class or providing a deployment descriptor (DD).



Declaring a Business Interface for the Session Bean


1    public interface Calculator { 
2          int add(int a, int b); 
3          int subtract(int a, int b); 
4    } 

  • What are the requirements for the session bean business interface? 
  • How are business interfaces classified? 
                               Local interface 
                               Remote interface

  • How can a business interface be designated a local interface? 
@Local public interface Calculator {...} 
@Local public class CalculatorBean implements Calculator

  • How can a business interface be designated a remote interface? 
@Remote public interface Calculator {...} 
@Remote public class CalculatorBean implements Calculator 

  • Are there any additional requirements for remote interfaces? 
  • Can a session bean have more than one business interface?


Creating the Session Bean Class that Implements the Business Interface


1        @Remote public interface Calculator { 
2                       int add(int a, int b); 
3                       int subtract(int a, int b); 
4         }




1      @Stateless public class CalculatorBean implements Calculator { 
2             public int add(int a, int b) { 
3                    return a + b; 
4             } 
6             public int subtract(int a, int b) { 
7                    return a - b; 
8             } 
9      }



Requirements for a Session Bean Class


  • The class must be a top level class.In addition the class must be defined as public,must not be final,and must not be abstract. 
  • The class must have a public constructor that takes no parameters. The container uses this constructor to create instances of the session bean class. 
  • The class must not define thefinalize method. 
  • The class must implement the methods of the bean s business interface(s), if any.



Annotating the Session Bean Class




Other common annotations
  • Transaction-related annotations 
  • Security-related annotations 
  • Life-cycle callback handler method annotations



Life Cycle of a Stateless Session Bean





  • PostConstruct callback 
  • PreDestroy callback



Life Cycle of a Stateful Session Bean



  • PostConstruct callback 
  • PreDestroy callback 
  • PostActivate callback 
  • PrePassivate callback


Defining Life-Cycle Event Handlers

  • A call back method is designated using the appropriate callback annotation. 
  • The same method can be designated to handle multiple callback events. 
  • Each call back event can only have one callback method designated to handle it. 
  • A callback method can access entries in the bean’s environment. 
  • Callback methods can throw runtime exceptions. 
  • Callback methods must not throw application exceptions. 
  • Callback methods can have any type of access modifier.


Example of a Callback Method in Bean Class


1       @Stateful public class ShoppingCartBean implements                   ShoppingCart { 
2            private float total; 
3            private Vector productCodes; 
4            public int someShoppingMethod(){...}; 
5            //... 
6       @PreDestroy private void endShoppingCart() {...}; 
7



Session Bean Packaging and Deployment

Packaging and deployment tasks

  • Optionally create a DD file for the session bean component 
  • Create a deployable session bean component archive 
  • Deploy the session bean component archive


Session Bean DD Example
























Creating a Session Bean Archive

1. Create a working directory structure. 
2. Copy the EJB component class files and helper classes into their corresponding sub             directories.For example,you should include the following classes
3. Create a META - INF sub directory off the root directory.
4. From a command line, execute the jar utility to create the EJB JAR archive.



Example of the EJB Module JAR File





Creating a Session Bean Client

Creating a client using container services














Creating a client without using container services














Sunday, December 13, 2015

Business Component Development with EJB Technology - Module 02

Module 2

 Introducing the Auction Application


Objectives

Upon completion of this module, you should be able to:
  • Describe the auction application 
  • Define the domain objects of the auction application 
  • Describe the implementation model for the auction system


Auction Application Use Cases




Auction Application Domain Objects







The Auction Domain Object






The AuctionUser Domain Object








The Bid Domain Object






The Item Domain Object







The BookItem Domain Object










Examining the Implementation Model







Business Core Implementation








Business Component Development with EJB Technology - Module 01

Module 1
Examining Enterprise Java Beans (EJB) Applications

Objectives
Upon completion of this module, you should be able to:


  • Introduce the Java Platform Enterprise Edition (Java EE) 
  • Examine the Java EE application architecture 
  • Examine the EJB Application creation process 
  • Compare the Java EE application development with traditional enterprise application development



Introducing the Java Platform Enterprise Edition(Java EE)–Overview
  • A set of specifications
  • Java EE 5 Software Development Kit (Java EE 5 SDK)
  • Commercial and open source Java EE application servers and tools
  • Java EE components and applications


Introducing the Java Platform Enterprise Edition(Java EE)–Specifications
  • Web services technologies
  • Web application technologies
  • Enterprise application technologies
  • Management and security technologies


Introducing the Java Platform Enterprise Edition(Java EE)– SDK
  • Sun Java System Application Server Platform Edition9 (application server 9 PE)
  • Java EE 5 Samples 
  • Java 2 Platform, Standard Edition 5.0 (Java SE 5)
  • Java BluePrints
  • Application Programmer Interface (API) documentation (Java docs)


Examining the Java EE Application Architecture

  • Generic Component-Container Architecture





  • Java EE Application Architecture: Generic Elements





  • Complete EJB Application Architecture






Examining Java EE Container Services  –


Deployment and Inherent Services


Deployment based services
  • Persistence
  • Transaction 
  • Security 
  • Injection 
Inherent services: 
  • Life-cycle 
  • Threading 
  • Remote object communication, such as RMI and CORBA


Vendor Specific Functionality

  • Scalability 
  • Failover 
  • Load balancing



Examining Java EE Container – API Services






Examine the EJB Application Creation Process

1. Use your preferred object oriented methodology to analyze the business problem you are working on:
  • The functional requirements of the application that is the business use cases. 
  • The non functional requirements of the application such as scalability requirements, 
  • The business logic that services the use cases 
  • Persistence data required by the application
2. Analyze the inter-tier communications requirements. 
  • Identify the synchronous communication requirements of the application.
  • identify the asynchronous communication requirements of the application.
3. Use entity classes to model the persistence data. 

4. Use session beans to model the server side business logic and synchronous service facade for the server side components.

5. Use the JMS API and message - driven beans to model the asynchronous communication requirements of the application.

6. Create the client. 

7. Assemble and package the application. 

8. Deploy the server side components. 

9. Package and distribute the client.







Java EE Platform Roles

  • Application component provider 
  • Application assembler 
  • Deployer 
  • System administrator 
  • Java EE product provider 
  • Tool provider


Comparing Java EE Application Development With Traditional Enterprise Application Development