Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
EJB Design. Server-side components Perform –complex algorithms –high volume transactions Run in –highly available environment (365 days/year) –fault tolerant.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
Enterprise Java Beans CS-422. Application Servers In the late 1980s and though the mid 1990s a number of corporations (Broadvision, Netscape…) marketed.
1 Java Programming II Java Network II (Distributed Objects in Java)
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 6 Session Beans.
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Middleware Technology (J2EE/EJB) Stateful Session Bean.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Session Beans INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
J2EE Structure & Definitions Catie Welsh CSE 432
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
1 Lecture 16 George Koutsogiannakis/SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
Java Servlets & Java Server Pages Lecture July 2013.
Fall CIS 764 Database Systems Engineering L7. EJB’s.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
Java Servlets and Java Server Pages Norman White Stern School of Business.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
EJB Enterprise Java Beans JAVA Enterprise Edition
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Callbacks and Interceptors. Contents  Session Beans Life Cycle  Interceptors.
Java Servlets By: Tejashri Udavant..
EJB (Enterprise Java Beans)
Introduction to Enterprise JavaBean
Understanding and Designing with EJB
Objectives In this lesson, you will learn to:
Component-based Applications
Understanding and Designing with EJB
Introduction to Session beans
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0

Enterprise Java Beans (EJB) An EJB is a component that provides reusable business logic functionality and/or a representation of a persistent business entity An EJB Container executes an EJB on behalf of clients.  Container provides the plumbing necessary to execute the EJB including non-business logic related functionality such as transactions, security, concurrency, remote access, etc. life cycle functions, e.g., creating, destroying, etc. Client uses an interface to access the Bean indirectly A deployment descriptor describes the structure of the Bean and how to execute the Bean as part of an application

Session Beans Session Beans are one type of EJBs  other types are Entity Beans and Message Driven Beans A session bean executes on behalf of a single client  Focus on functionality, application logic and application state May be transaction aware May access shared data in an underlying DB but does not directly represent this shared data Is relatively short-lived Is removed when the EJB Container crashes

Stateless Session Beans A Stateless Session Bean executes a request and returns a result without saving any client specific state information  Can use instance variables only if they are not client related (do not expect instance variables value to remain the same) All Stateless Session Beans are equivalent  A container can choose To serve the same instance of a Bean to multiple clients To serve difference Bean instances to the same client at different times  A container may maintain a pool of Stateless Session Beans No necessary relation between when a client creates the Bean and when the Container creates the Bean Provide very high scalability

Stateful Session Beans Maintain per client state across multiple client requests May be “passivated” – allows a degree of pooling  The container serializes the state of a Bean non currently being used and writes it to a secondary storage  Frees JVM resources held for Bean  When a new request arrives for the Bean, it must be “activated” State read from secondary storage and deserialized  Can only passivate a Bean if it is not in a transaction

Stateful Session Beans PassiveReadyDoes Not Exist create In Transaction commit or rollback start transaction timeout remove passivate activate

EJB Development Steps 1.Write Business Interface  Plain Java Interface exposing the EJB business methods can be local or remote 2.Write Bean Class  Implementation of Business Interface  Use annotations (e.g. to specify type of EJB)  Use resource injection (e.g. for persistence access) 3.Provide deployment descriptor (if needed) 4.Package and deploy on container  Usually done by a container provided tool

EJB Development Steps Local versus Remote Interface There are two types of Interface to EJBs  local interface – for clients running in the same Java Virtual Machine (JVM) as the EJB  remote interface – for clients running in different (JVM) than the EJB A local interface should be used whenever possible local interface provides a better performance (an actual reference to an instance of EJB is used) remote interface involves RMI (creation of stub and skeleton objects, marshalling/unmarshalling messages,...)

EJB Development Steps package helloejb; import javax.ejb.Remote; /** * This is the business interface for HelloEJB enterprise bean. // specify as a remote interface public interface Hello { public String hello(); } Interface The annotation for the type of interface could be omited from the interface and specified in the EJB implementation.

EJB Development Steps Stateless Session EJB Implementation package helloejb; import // for a stateless session EJB public class HelloEJBBean implements helloejb.Hello { /** Creates a new instance of HelloEJBBean */ public HelloEJBBean() { } /** Implementation of business method */ public String hello() { return "Hello from ejb !!!"; }

EJB Client An EJB client can be managed by the same container as the EJB (e.g. a Servlet or another EJB) or external.  Container managed clients can use ressource injection for access (using  Non-container managed clients must use JNDI to locate the EJB.

EJB Client Web application client, managed by the same container package servlet; import helloejb.Hello;... public class HelloClientServlet extends HttpServlet // EJB ressource injection private Hello hello; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" EJB returns " + hello.hello()); out.println(" "); out.close(); }... }

EJB Client Stand-alone client, managed outside of container. Need to use JNDI to lookup. import helloejb.Hello; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class HelloClient { public static void main(String[] args) { Context ctx; try { /** Use JNDI to lookup */ ctx = new InitialContext(); Hello helloEjb = (Hello) ctx.lookup("helloejb.Hello"); System.out.println(helloEjb.hello()); } catch (NamingException ex) { ex.printStackTrace(); } }

Session EJBs declares a stateless session public class TaxRateBean implements TaxRate { }  By default, name is the same as the class declares a stateful session can be use to annotate public class TaxRateBean implements TaxRate { }  In that case, the interface do not have annotation

Session EJBs Annotations Annotations are also used for dependency injection  mechanism allowing to obtain object references on resources from the set up a dependency to a resource in the bean's SessionContext context; TaxRate tr = (TaxRate)context.lookup(TaxRate.class.getName());  Any resource available to the application server can be referred to (javax.sql.DataSource, javax.transaction.UserTransaction,...)

Session EJBs can be used to inject a reference to an EJB or bind a name in the EJB environment  Injection of a EJB private Pricer pricer;  Binding a name in the public class PricerBean implements Pricer {... public double getFinalPrice() { InitialContext ctx = new InitialContext(); TaxRate tr = (TaxRate)context.lookup(“java:comp/env/ejb/TaxRate”); }

Session EJBs to inject an entity manager object or bind a name at the class level  Injection of an entity manager EntityManager em;  Binding public class HelloWorldBean implements HelloWorld SessionContext context; public void hello() { EntityManager em = (EntityManager)context.lookup(“HelloWorldEntity”); }

StateFul Session EJBs Activation and Passivation annotate a Stateful Session EJB method as a callback that is called just before the EJB is public class AstatefulBean public void passivate() { // close socket connections,... }

StateFul Session EJBs Activation and Passivation annotate a Stateful Session EJB method as a callback that is called just before the EJB is public class AstatefulBean public void passivate() { // open socket connections,... }

Session EJBs Construction and Destruction annotate a method as a callback called right after a new instance of a bean class is created by the container  can be used for initializations needed by the annotate a method as a callback called right before a bean class is destroyed  can be used to free allocated resources