Stateless Session Beans Session 3
Session Objectives <ul><li>Identify the constituents of an Enterprise JavaBean. </li></ul><ul><li>Define a bean class, EJB...
Review of Session 2-(1of 2) <ul><li>In session 2 we discussed </li></ul><ul><li>Four stages are followed while developing ...
Review of Session 2-(2 of 2) <ul><li>The server and the container provide following services to the developer   </li></ul>...
Components of an Enterprise Bean Components of an  enterprise bean  The bean class The EJB object The Remote  interface De...
The Bean class Well-defined interface The Bean Bound Communicates to the  client through the  interface Container Works in...
The EJB Object Client Code EJB Container/Server 1 .Calls a method 4.Returns method    to client The container is the middl...
The Remote Interface Remote Interfaces  derived from javax.ejb.EJBObject  Business  Methods Define Perform Functionality o...
Relationship between Java RMI and EJB Objects Location Transparency Remote Method Invocation Portability of Client Code Be...
Methods under javax.ejb.EJBObject javax.ejb.EJBObject getEJBHome() getPrimaryKey() remove() getHandle() isIdentical()
The Home Interface Home Interface  Find EJB  Objects Create EJB  Objects Destroy EJB Objects EJB specifies certain methods...
The Methods  in EJB Home getEJBMetaData():  It is this method that gets information about the  beans that are being worked...
The Home Object Client Code Home Object EJB  Object Enterprise Beans EJB Container/Server 1. Requests new EJB Object 3. Re...
Deployment Descriptors Deployment  Descriptors Life cycle requirements  and Bean management Persistence Requirements Trans...
Life Cycle of a Session Bean <ul><li>A session bean may last as long as the client session.  </li></ul><ul><li>Will not su...
Conversational and Non Conversational Beans <ul><li>A conversation stretches across a business process  with respect to th...
Writing a Session Bean The six methods to be followed while  writing a session bean  setSessionContext(SessionContext ctx)...
The  setSessionContext (SessionContext ctx) Container setSessionContext() Bean public class theBean implements SessionBean...
Business Methods <ul><li>import javax.ejb.*; </li></ul><ul><li>public class sess implements Sessionbean{ </li></ul><ul><li...
Using JNDI to lookup Home Objects Home  Object Enterprise  beans EJB  Object Client JNDI Naming Service 1. Retrieve  Home ...
Steps in accessing Home Objects The steps followed by the client code  to get a reference The setting up of the Environmen...
Pooling of Stateless Session Bean Client EJB  Object Invokes EJB Server/Container Invokes Bean Bean Bean Bean
Deployment Descriptors <ul><li>specifies how the container is supposed to create and manage the enterprise bean object.  <...
jboss.xml <ul><li>Provides the container information about the  JNDI mapping, persistence information and database mapping...
Creating the jar file Welcome.class Deployment  Descriptors Welcome.jar Welcomebean.class Welcomehome.class A jar file is ...
Deploying the bean <ul><li>the newly created  .jar file  has to be copied into the deploy directory on the server.  </li><...
Accessing from Client side Possible Clients JNDI lookup create() Ordinary JavaBean Enterprise JavaBean JSP Page Servlet Ap...
Summary - 1 <ul><li>The bean class, the EJB object, the remote interface, the home interface, the home object, the deploym...
Summary - 2 <ul><li>Responsibilities of the EJB home object: </li></ul><ul><ul><ul><li>* Creating EJB objects </li></ul></...
Summary - 3 <ul><li>Three classes are essential for deployment:  </li></ul><ul><ul><ul><li>* Home Interface </li></ul></ul...
Upcoming SlideShare
Loading in...5
×

Session 3 Tp3

1,604

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,604
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
116
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Approach:
  • Session 3 Tp3

    1. 1. Stateless Session Beans Session 3
    2. 2. Session Objectives <ul><li>Identify the constituents of an Enterprise JavaBean. </li></ul><ul><li>Define a bean class, EJB object, home interface, home object and deployment descriptors. </li></ul><ul><li>Define a stateless session bean </li></ul><ul><li>Write programs related to stateless session beans </li></ul><ul><li>Compile and deploy stateless session beans </li></ul>
    3. 3. Review of Session 2-(1of 2) <ul><li>In session 2 we discussed </li></ul><ul><li>Four stages are followed while developing business solutions </li></ul><ul><li>Six parties are involved while deploying Enterprise JavaBeans </li></ul><ul><li>Logical three-tier architecture of EJB: </li></ul><ul><ul><li>The Client </li></ul></ul><ul><ul><li>The EJB Server </li></ul></ul><ul><ul><li>The Database </li></ul></ul><ul><li>The EJB Container resides inside the EJB server. The container acts as a buffer between the bean and the outside world. </li></ul><ul><li>The responsibility of the EJB Server and Container </li></ul>
    4. 4. Review of Session 2-(2 of 2) <ul><li>The server and the container provide following services to the developer </li></ul><ul><li>* Transaction support </li></ul><ul><li>* Security support </li></ul><ul><li>* Persistence support </li></ul><ul><li>* Support for management of multiple instances . </li></ul><ul><li>An Enterprise Java Bean can be classified into: </li></ul><ul><li>* Session Beans </li></ul><ul><li>* Entity Beans </li></ul><ul><li>* Message-Driven Beans </li></ul>
    5. 5. Components of an Enterprise Bean Components of an enterprise bean The bean class The EJB object The Remote interface Deployment Descriptors The Home Interface The EJB-jar file The Home object The Local Interface The LocalHome Interface
    6. 6. The Bean class Well-defined interface The Bean Bound Communicates to the client through the interface Container Works in any container with the help of these interfaces public interface javax. ejb. EnterpriseBean extends java.io.Serializable { } Once the above interface is implemented, the bean class is confirmed
    7. 7. The EJB Object Client Code EJB Container/Server 1 .Calls a method 4.Returns method to client The container is the middleman between the client and the bean. It manifests itself as a single network-aware object. This network-aware object is called the EJB Object Home Object EJB Object 3. Returns the Method Enterprise Bean Instance 2. Delegates method to bean
    8. 8. The Remote Interface Remote Interfaces derived from javax.ejb.EJBObject Business Methods Define Perform Functionality of the bean javax.ejb.EJBObject public interface java.rmi.RemoteInterface extends javax.ejb.EJBObject { public abstract javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException; }
    9. 9. Relationship between Java RMI and EJB Objects Location Transparency Remote Method Invocation Portability of Client Code Bean Java Virtual Machine Bean Java Virtual Machine EJB Object java.rmi.Remote Remote Object JVM JVM
    10. 10. Methods under javax.ejb.EJBObject javax.ejb.EJBObject getEJBHome() getPrimaryKey() remove() getHandle() isIdentical()
    11. 11. The Home Interface Home Interface Find EJB Objects Create EJB Objects Destroy EJB Objects EJB specifies certain methods that the home interface has to support. These methods are defined in the javax.ejb.EJBHome public interface javax.ejb.EJBHome extends java.rmi.Remote { public abstract EJBMetaData getEJBMetaData() throws java.rmi.RemoteException; }
    12. 12. The Methods in EJB Home getEJBMetaData(): It is this method that gets information about the beans that are being worked on remove(): This method destroys an EJB object The methods that fall under the EJB Home are
    13. 13. The Home Object Client Code Home Object EJB Object Enterprise Beans EJB Container/Server 1. Requests new EJB Object 3. Returns the objects 2. Creates new object
    14. 14. Deployment Descriptors Deployment Descriptors Life cycle requirements and Bean management Persistence Requirements Transaction Requirements Security Management Classes that form the bean Home Interface Remote Interface EJB Server
    15. 15. Life Cycle of a Session Bean <ul><li>A session bean may last as long as the client session. </li></ul><ul><li>Will not survive if the application server changes or crashes. </li></ul><ul><li>They are objects which are present in-memory which die along with the surrounding environment and are not persisted in a database. </li></ul>
    16. 16. Conversational and Non Conversational Beans <ul><li>A conversation stretches across a business process with respect to the client. </li></ul><ul><li>A stateless session bean conducts a conversation that spreads over a single method call. </li></ul><ul><li>Stateful session beans can retain their conversational state. </li></ul>Client Conversation Bean
    17. 17. Writing a Session Bean The six methods to be followed while writing a session bean setSessionContext(SessionContext ctx) ejbCreate() ejbPassivate() Business methods ejbRemove() ejbActivate()
    18. 18. The setSessionContext (SessionContext ctx) Container setSessionContext() Bean public class theBean implements SessionBean { private SessionContext ctx; public void setSessionContext(SessionContext ctx) { this.ctx=ctx; } . . . . . . . } Session Context (Gateway) Associates
    19. 19. Business Methods <ul><li>import javax.ejb.*; </li></ul><ul><li>public class sess implements Sessionbean{ </li></ul><ul><li>public int multiply(int a, int b){ </li></ul><ul><li>return (a*b); </li></ul><ul><li>} </li></ul><ul><li> ejbPassivate() </li></ul><ul><li>ejbCreate() </li></ul><ul><li>ejbActivate() </li></ul><ul><li>ejbRemove() </li></ul><ul><li>. . . . . . . </li></ul><ul><li>} </li></ul><ul><li>Business methods are written to solve business logic problems. </li></ul><ul><li>Business methods are contained in the remote interface of </li></ul><ul><li>the bean for the client to access them. </li></ul>
    20. 20. Using JNDI to lookup Home Objects Home Object Enterprise beans EJB Object Client JNDI Naming Service 1. Retrieve Home Object 3. Creates an EJB Object 5. Return Object reference 6. Invokes business methods EJB Container/Server 4. Create EJB Object 2. Returns reference to the home object 7. Delegates request to bean
    21. 21. Steps in accessing Home Objects The steps followed by the client code to get a reference The setting up of the Environment Destroying the EJB Object Calling a Method Creating an Object Retrieving the home objects The Initial Context
    22. 22. Pooling of Stateless Session Bean Client EJB Object Invokes EJB Server/Container Invokes Bean Bean Bean Bean
    23. 23. Deployment Descriptors <ul><li>specifies how the container is supposed to create and manage the enterprise bean object. </li></ul><ul><li>defines the name of the enterprise bean class, and the names of the home and remote interfaces. </li></ul><ul><li>ejb-jar file provides naming information about enterprise bean, remote interface and home interface. </li></ul><ul><li>ejb.jar has to be present in the directory called META-INF. </li></ul>
    24. 24. jboss.xml <ul><li>Provides the container information about the JNDI mapping, persistence information and database mapping. </li></ul><ul><li>This file also has to be put into the META-INF file. </li></ul><jboss> <enterprise-beans> <session> <ejb-name>Welcome</ejb-name> <jndi-name>Welcome</jndi-name> </session> </enterprise-beans> </jboss>
    25. 25. Creating the jar file Welcome.class Deployment Descriptors Welcome.jar Welcomebean.class Welcomehome.class A jar file is created to package the three java files, namely the bean class, the home interface and the remote interface . The XML files Namely ejb-jar.xml and jboss.xml are also present in the jar file.
    26. 26. Deploying the bean <ul><li>the newly created .jar file has to be copied into the deploy directory on the server. </li></ul>D:injbossdeploy .jar file jar cvf welcome.jar Welcome.class Welcomehome.class Welcomebean.class META-INF
    27. 27. Accessing from Client side Possible Clients JNDI lookup create() Ordinary JavaBean Enterprise JavaBean JSP Page Servlet Applet Enterprise JavaBean Home Object EJB Object Business Methods
    28. 28. Summary - 1 <ul><li>The bean class, the EJB object, the remote interface, the home interface, the home object, the deployment descriptors, and the jar files constitute the enterprise bean. </li></ul><ul><li>The bean class contains the implementation of the business logic methods. </li></ul><ul><li>The EJB container performs certain important management functions when it intercepts client requests. These management functions are: </li></ul><ul><ul><ul><li>* Transaction logic </li></ul></ul></ul><ul><ul><ul><li>* Security logic </li></ul></ul></ul><ul><ul><ul><li>* Bean instance logic </li></ul></ul></ul><ul><li>The Remote interface duplicates the methods exposed by the bean class. </li></ul>
    29. 29. Summary - 2 <ul><li>Responsibilities of the EJB home object: </li></ul><ul><ul><ul><li>* Creating EJB objects </li></ul></ul></ul><ul><ul><ul><li>* Searching for existing EJB Objects </li></ul></ul></ul><ul><ul><ul><li>* Removing EJB Objects </li></ul></ul></ul><ul><li>The deployment descriptor: A file that tells the EJB server about the classes, the home interface, and the remote interface that form the bean. </li></ul><ul><li>The lifetime of a session bean may last till such time as that of a client session. It could be as long as a window is open or as long as an application is open. Session beans do not, therefore, survive application server crashes or machine crashes . </li></ul>
    30. 30. Summary - 3 <ul><li>Three classes are essential for deployment: </li></ul><ul><ul><ul><li>* Home Interface </li></ul></ul></ul><ul><ul><ul><li>* Remote Interface </li></ul></ul></ul><ul><ul><ul><li>* Bean class </li></ul></ul></ul><ul><li>The ejb-jar.xml file is a compressed file that contains the declarations of the enterprise bean class, the remote interface and the home interface. </li></ul><ul><li>It is important to have a client because EJB will not function without the client. This client can be: </li></ul><ul><ul><ul><li>* An ordinary JavaBean </li></ul></ul></ul><ul><ul><ul><li>* Another EJB </li></ul></ul></ul><ul><ul><ul><li>* A JSP Page </li></ul></ul></ul><ul><ul><ul><li>* A servlet </li></ul></ul></ul><ul><ul><ul><li>* An applet </li></ul></ul></ul><ul><ul><ul><li>*A stand-alone application </li></ul></ul></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×