Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

Java 2 Enterprise Edition

Document Sample
Java 2 Enterprise Edition Powered By Docstoc
					Java 2 Enterprise Edition


            Introduction to
            Enterprise JavaBeans
            (EJB)
    What is EJB?

       A specification for creating server-side scalable,
        transactional, multi-user secure enterprise-level
        applications
       A component architecture for deployable server-side
        components in Java
       Framework for creating middleware
       Cornerstone of J2EE




2                        (c) 2002, NCST            Introduction to EJB
    Overall Goals

       To create a standard component architecture for
        building distributed object-oriented business
        applications
       Hide low-level details
       Follow the “Write Once, Run Anywhere” philosophy of
        Java programming language
       Interoperability with other vendor products
       Architectural independence




3                        (c) 2002, NCST             Introduction to EJB
    JavaBeans Vs EJB

    JavaBeans                                Enterprise JavaBeans
    JavaBeans may be visible or non-         An EJB is a non-visual, remote
    visible at runtime                       object


    JavaBeans are intended to be local       EJBs are remotely executable
    to a single process and are primarily    components or business objects that
    intended to run on the client side.      can be deployed only on the server.



    JavaBeans have an external               EJBs have a deployment descriptor
    interface called the Properties          that describes its functionality to an
    interface, which allows a builder tool   external builder tool or IDE.
    to interpret the functionality of the
    bean.
                                                                                       More …

4                                 (c) 2002, NCST                            Introduction to EJB
    JavaBeans Vs EJB
    Contd …
     JavaBeans                                    Enterprise JavaBeans
     JavaBeans may have BeanInfo                  EJBs have no concept of BeanInfo
     classes, property editors, or                classes, property editors ,or
     customizers.                                 customizers and provide no additional
                                                  information other than that described
                                                  in the deployment descriptor.

     No explicit support exists for               EJBs may be transactional and the
     transactions in JavaBeans                    EJB Servers provide transactional
                                                  support


     JavaBeans are not typed                      EJBs are of two types—session beans
                                                  and entity beans.




5                                     (c) 2002, NCST                        Introduction to EJB
    Introducing
    Component Transaction Monitors (CTM)

       Transaction Processing Monitors, not a new term

       CTM, evolved as a hybrid of traditional TP monitor and component
        technology
       Implements robust server-side component models for creating,
        using and deploying business systems

       Application servers with CTM provides framework for managing
        transactions, object distribution, concurrency, security,
        persistance, multi-threading and resource management
       With application servers, developer can focus on business logic
       However, vendor specific application servers limit portability

6                            (c) 2002, NCST                 Introduction to EJB
    Enterprise JavaBeans

       Combines best aspects of distributed components and CTM
        application servers
       Standarizes API for components and application servers
       Provides a framework




7                          (c) 2002, NCST               Introduction to EJB
        N-tier EJB Architecture

                                           EJB Application Server

                   RMI-IIOP
                                                         Container
    Application                                                      Database Server
      Client                                                            (RBDMS)




                  HTTP


                              Web Server
    Web-Client                                                        Legacy Systems

8                              (c) 2002, NCST                         Introduction to EJB
    Container & Components

    Container                     Components

       Concurrency                    Web-tier [JSP/Servlets]
       Consistency                    Business Logic [EJB]
       Security                       Data access logic
       Availability                    [EJB]
       Scalability
       Integration
       Distribution




9                      (c) 2002, NCST                     Introduction to EJB
     Container: Implicit Services

        Resource & Life-cycle management
         –   Process allocation, threads, activation and deactivation of
             objects automated
        State management
        Persistence
        Security
        Distribute transaction management
        Location transparency



10                             (c) 2002, NCST                  Introduction to EJB
     EJB Architecture



       create,
       lookup,
       remove
                  create,
                  lookup,
                  remove
       Call to
       Business      methods
       methods




11                 (c) 2002, NCST   Introduction to EJB
     EJB Architecture - Explained



            Client                                             EJB Application Server

                                                                            Container
                     create     RMI / IIOP
     Client Stub                             EJB Home
                                                            create



                     Business   RMI / IIOP                           Bean Instance
     Object Stub                             EJB Object
                     methods                                         Instance Pool
                                                          method
                                                          calls

12                                   (c) 2002, NCST                          Introduction to EJB
     Instance Pooling

        Reusing resource across heterogeneous requests
        Container manages the life-cycle of enterprise beans
         –   Rather than creating instances of beans for each client
             request, it maintains a pool of already created instances and
             assigns it to requesting clients, as and when required
         –   # client request <> # instances
        Optimizes system resource usage




13                             (c) 2002, NCST                  Introduction to EJB
     EJB Component Model

        A server-side component
        A flexible component model
        Can be assembled and customized at deployment time
         using EJB compliant application server




14                       (c) 2002, NCST          Introduction to EJB
     EJB Server

        Provides execution environment for EJB containers
        Makes available system services for multiprocessing,
         load balancing, and device access for EJB Containers
        May also provide vendor-specific features
        EJB server is required to provide availability of a JNDI -
         accessible naming service




15                         (c) 2002, NCST              Introduction to EJB
     EJB Container

        interface between EJB and outside world
        acts as a layer of indirection between an enterprise
         bean and low-level details
        an abstraction that manages one or more EJB classes
        makes the required services available through a set of
         standard interfaces




16                        (c) 2002, NCST             Introduction to EJB
     Enterprise Bean ingredients

        The collection of files that constitute an enterprise
         bean:
         –   Enterprise Bean Class
         –   Interfaces
                 Remote and Home interface for remote access
                 Local and Local Home interface for local access
         –   Deployment Descriptor
         –   Helper classes




17                               (c) 2002, NCST                     Introduction to EJB
         Enterprise Bean



        A class confirming to a well-defined interface
        Contains business implementation details
        Types of Beans:
          –   Entity Beans - Models a business object
          –   Session Beans – Models a business process
          –   Message-Driven Beans – beans acting as messaging agents
        Extends a common base interface EnterpriseBean




18                              (c) 2002, NCST              Introduction to EJB
     The EJB Object

        A surrogate object which knows about networking,
         transactions, security, etc
        A client request interceptor
        Contains methods for client interaction, as per the EJB
         specification
        Additionally, exposes every business method
         implemented by the bean




19                         (c) 2002, NCST            Introduction to EJB
            Remote Interface

               All remote interfaces must extend …
        <<interface>>      public interface javax.ejb.EJBObject
      java.rmi.Remote                     extends java.rmi.Remote {
                                  public javax.ejb.EJBHome getEJBHome()
                                         throws java.rmi.RemoteException;
                                  public java.lang.Object getPrimaryKey()
                                                 throws java.rmi.RemoteException;
        <<interface>>             public void remove()
     javax.ejb.EJBObject          throws java.rmi.RemoteException,
                                  javax.ejb.RemoveException;
     + getEJBHome()               public javax.ejb.Handle getHandle()
                                         throws java.rmi.RemoteException;
     + getPrimaryKey()
     + remove()                   public boolean isIdentical(javax.ejb.EJBObject)
                                         throws java.rmi.RemoteException;
     + getHandle()
     + isIdentical()       }



20                                      (c) 2002, NCST                Introduction to EJB
     Remote Interface

        Must confirm to RMI-IIOP rules
        All remote interface extends java.rmi.Remote
        Methods callable across virtual machines must throw
         java.rmi.RemoteException




21                        (c) 2002, NCST           Introduction to EJB
     The Home Object

        A factory for creating EJB Object for enterprise beans
        Network aware object
        Responsibilities:
         –   Create EJB objects
         –   Finding available EJB objects
         –   Remove EJB objects




22                            (c) 2002, NCST         Introduction to EJB
           Home Interface

                          public interface javax.ejb.EJBHome
        <<interface>>                 extends java.rmi.Remote {
      java.rmi.Remote
                              public javax.ejb.EJBMetaData getEJBMetaData()
                                             throws java.rmi.RemoteException;
                              public javax.ejb.HomeHandle getHomeHandle()
                                     throws java.rmi.RemoteException;
        <<interface>>         public void remove(javax.ejb.Handle handle)
     javax.ejb.EJBHome               throws java.rmi.RemoteException,
                                             javax.ejb.RemoveException;
     + getEJBMetaData()       public void remove(java.lang.Object primaryKey)
                                     throws java.rmi.RemoteException,
     + getHomeHandle()                       javax.ejb.RemoveException;
     + remove()
                      }




23                                    (c) 2002, NCST              Introduction to EJB
     EJB Client

        Finds EJB Home Object through JNDI lookup
        Uses the EJB Object to invoke bean methods
        The EJB client only gets a reference to an EJBObject
         instance




24                        (c) 2002, NCST            Introduction to EJB
     Local Interfaces

        EJB 2.0 onwards, the enterprise bean can be called
         using local objects, rather than remote
        Entirely optional, can be used as a replacement or as a
         complement to remote interfaces
        Local objects implement a local interface
        This reduces the steps of the stub, skeleton, network
         and marshaling/demarshaling
        Requires to be called within the same JVM




26                        (c) 2002, NCST             Introduction to EJB
     Local Object and
     Local Home Interface

     public interface javax.ejb.EJBLocalObject {
        public javax.ejb.EJBLocalHome getEJBLocalHome()                    throws
        javax.ejb.EJBException;
        public java.lang.Object getPrimaryKey()
              throws javax.ejb.EJBException;
        public boolean isIdentical(javax.ejb.EJBLocalObject)               throws
        javax.ejb.EJBException;
        public void remove()                                               throws
        javax.ejb.EJBException,
              javax.ejb.RemoveException;
     }
     public interface javax.ejb.EJBLocalHome {
        public void remove(java.lang.Object)                               throws
        javax.ejb.RemoveException, javax.ejb.EJBException;
     }




27                            (c) 2002, NCST                   Introduction to EJB
     Deployment Descriptor

        A contract between the producer and consumer
        Describes the structural and assembly information
         about the application
        Specifies
         –   Bean management and life-cycle requirements
         –   Persistence requirements
         –   Transaction requirements
         –   Security requirements
        In EJB 2.0, these details are captured in an XML file



28                           (c) 2002, NCST                Introduction to EJB
     Vendor-specific files

        Ejb-jar file
          –   A standard format for packaging the enterprise bean and
              applications clients
          –   It packages all the necessary files in a .ZIP compression
              format




29                              (c) 2002, NCST                  Introduction to EJB
        Packaging the Beans




          Home          Enterprise Bean    Deployment
        Interfaces          Classes         Descriptor      Jar file
                                                            Creator
                                                                       ejb-jar file




     Local Interfaces      Remote         Vendor Specific
                          Interfaces           files

30                                         (c) 2002, NCST               Introduction to EJB
     References

        Mastering Enterprise JavaBeans, 2nd Edition
         By Ed Roman
        Enterprise JavaBeans Specification, V 2.0
         Sun Microsystems
        EJB Architecture, SunTech Days presentation, 2001
        The J2EE Tutorial
         Sun Microsystems




31                          (c) 2002, NCST           Introduction to EJB

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:6/22/2012
language:
pages:30