EJB (Enterprise Java Beans)

Slides:



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

Session #, Speaker Name1 Enterprise JavaBeans Architecture Vlada Matena Sun Microsystems Inc.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
J2EE Java 2 Enterprise Edition. Relevant Topics in The Java Tutorial Topic Web Page JDBC orial/jdbc
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
CS 483 Enterprise and Web Application Programming
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Distributed System Using Java 2 Enterprise Edition (J2EE)
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
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.
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
Replication & EJB Graham Morgan. EJB goals Ease development of applications –Hide low-level details such as transactions. Provide framework defining the.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
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.
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.
第十四章 J2EE 入门 Introduction What is J2EE ?
J2EE Structure & Definitions Catie Welsh CSE 432
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
1 Java EE Programming Enterprise JavaBeans. 2 Topics J2EE Overview Enterprise JavaBeans Overview Enterprise Entity Beans Case Study How to build them.
Distribution and components. 2 What is the problem? Enterprise computing is Large scale & complex: It supports large scale and complex organisations Spanning.
Introduction to Enterprise JavaBeans Topics In Systems Architecture Barry Herbold
© 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.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
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.
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.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
©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.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Copyright © 2004, Keith D Swenson, All Rights Reserved. OASIS Asynchronous Service Access Protocol (ASAP) Tutorial Overview, OASIS ASAP TC May 4, 2004.
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.
J2EE Platform Overview (Application Architecture)
Chapter 1 Introduction to Computers, Programs, and Java
Distribution and components
Introduction to J2EE Architecture
Enterprise Application Architecture
Enterprise Java Bean. Overview of EJB View of EJB Conversation Roles in EJB, Types of Enterprise Beans Lifecycle of Beans Developing Applications using.
Introduction to Enterprise JavaBean
Distributed System Using Java 2 Enterprise Edition (J2EE)
Understanding and Designing with EJB
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
Objectives In this lesson you will learn about: Need for servlets
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Component-based Applications
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Intro to J2EE Concepts.
Presentation transcript:

EJB (Enterprise Java Beans)

Overview Of RMI Vs EJB

What is EJB Technology? A server-side component technology Easy development and deployment of Java technology-based application that are: Transactional, distributed, multi-tier, portable, scalable, secure, … What is EJB? In short, it is a server-side component technology, which enable the easy development and deployment of Java-based enterprise applications in the form of components that have to be enterprise-quality, meaning they are transactional, distributed, multi- tier, portable, scalable, secure, and reliable, and the list can go on.

Why we need Enterprise JavaBeans The client-server model of application development has enjoyed considerable popularity. The client application resides on a local machine and accesses the data in a data store such as a relational database management system (RDMS). This model works well as long as the system has only a few users. As more and more users need access to the data, these applications don’t scale well to meet the demands. Because the client contains the logic, it must be installed on each machine. Management becomes increasingly difficult.

Gradually the benefits of dividing applications into more than the two tiers of the client-server model becomes apparent. In a multi-tier application, only the user interface stays on local machines while the logic of the application runs in the middle tier on a server. The final tier is still the stored data. When the logic of an application needs updating, changes are made to the software of the middle tier on the server, greatly simplifying the management of updates. But creating reliable, secure, and easily managed distributed applications is notoriously difficult.

For example, managing transactions over a distributed system is a major task. Fortunately, using components that follow the EJB specification to build distributed systems relieves much of the burden Dividing the development of a distributed system into specific tasks that are assigned to specialists. For example, if the application is an accounting system, the enterprise bean developer would need to understand accounting. The system administrator must know about monitoring a deployed and running application.

Each specialist assumes a particular role. Making EJB server and container services available to the enterprise bean and application developers. The EJB server provider and EJB container provider (who are often the same vendor) handle many of the more difficult tasks so the developers don’t have to. For example, the container an enterprise bean runs in can provide transaction and security services to the bean automatically. Making enterprise beans portable. Once a bean is written, it can be deployed on any EJB server that adheres to the Enterprise JavaBeans standard. Each bean is likely to include vendor-specific elements, however.

EJB architecture

Multi-tier distributed applications often consist of a client that runs on a local machine, a middle-tier that runs on a server that contains the business logic, and a backend-tier consisting of an enterprise information system (EIS). An EIS can be a relational database system, an ERP system, a legacy application, or any data store that holds the data that needs to be accessed. This figure shows a typical EJB multi-tier distributed system with three tiers: the client; the server, the container, and the beans deployed on them; and the enterprise information system.

The EJB server The EJB server provides system services to enterprise beans and manages the containers in which the beans run. It must make available a JNDIaccessible naming service and a transaction service. Frequently an EJB server provides additional features that distinguish it from its competitors. The Borland AppServer is an example of an EJB server.

The EJB container A container is a runtime system for one or more enterprise beans. It provides the communication between the beans and the EJB server. It provides transaction, security, and network distribution management. A container is both code and a tool that generates code specific for a particular enterprise bean. A container also provides tools for the deployment of an enterprise bean, and a means for the container to monitor and manage the application.

The EJB server and EJB container together provide the environment for the bean to run in. The container provides management services to one or more beans. The server provides services to the bean, but the container interacts on behalf of the beans to obtain those services. Although it is a vital part of the Enterprise JavaBeans architecture, enterprise bean developers and application assemblers don’t have to think about the container. It remains a behind-the-scenes player in an EJB distributed system. Therefore, this book goes no further explaining what a container is and how it works.

How an enterprise bean works The bean developer must create these interfaces and classes: The home interface for the bean The home interface defines the methods a client uses to create, locate,and destroy instances of an enterprise bean. The remote interface for the bean The remote interface defines the business methods implemented in the bean. A client accesses these methods through the remote interface. The enterprise bean class The enterprise bean class implements the business logic for the bean. The client accesses these methods through the bean’s remote interface

Roles in the development of an EJB application Application roles Bean provider Application assembler Infrastructure roles EJB server provider EJB container provider Deployment and operation roles Deployer System administrator

Types of enterprise beans An enterprise bean can be a session bean or an entity bean. Session beans An enterprise session bean executes on behalf of a single client. In a sense,the session bean represents the client in the EJB server. Session beans can maintain the client’s state, which means they can retain information for the client. The classic example where a session bean might be used is a shopping cart for an individual shopping at an online store on the web.

As the shopper selects items to put in the “cart,” the session bean retains a list of the selected items. Session beans can be short-lived. Usually when the client ends the session, the bean is removed by the client. Session beans can be either stateful or stateless. Stateless beans don’t maintain state for a particular client. Because they don’t maintain conversational state, stateless beans can be used to support multiple clients.

Entity beans An entity bean provides an object view of data in a database. Usually the bean represents a row in a set of relational database tables. An entity bean usually serves more than one client. Unlike session beans, entity beans are considered to be long-lived. They maintain a persistent state, living as long as the data remains in the database, rather than as long as a particular client needs it. The container can manage the bean’s persistence, or the bean can manage it itself. If the persistence is bean-managed, the bean developer must write code that includes calls to the database.

Session Bean Session bean encapsulates business logic only, it can be invoked by local, remote and webservice client. It can be used for calculations, database access etc. The life cycle of session bean is maintained by the application server (EJB Container). Types of Session Bean 1) Stateless Session Bean: It doesn't maintain state of a client between multiple method calls. 2) Stateful Session Bean: It maintains state of a client across multiple requests. 3) Singleton Session Bean: One instance per application, it is shared between clients and supports concurrent access.

Stateless Session Bean Stateless Session bean is a business object that represents business logic only. It doesn't have state (data). In other words, conversational state between multiple method calls is not maintained by the container in case of stateless session bean. The stateless bean objects are pooled by the EJB container to service the request on demand. It can be accessed by one client at a time. In case of concurrent access, EJB container routes each request to different instance. Annotations used in Stateless Session Bean @Stateless @PostConstruct @PreDestroy

Life cycle of Stateless Session Bean There is only two states of stateless session bean: does not exist and ready.

EJB Container creates and maintains a pool of session bean first EJB Container creates and maintains a pool of session bean first. It injects the dependency if then calls the @PostConstruct method if any. Now actual business logic method is invoked by the client. Then, container calls @PreDestory method if any. Now bean is ready for garbage collection.

Example of Stateless Session Bean To develop stateless bean application, we are going to use Eclipse IDE and glassfish 3 server. To create EJB application, you need to create bean component and bean client. 1) Create stateless bean component To create the stateless bean component, you need to create a remote interface and a bean class

File: AdderImplRemote.java package com.javatpoint;   import javax.ejb.Remote;      @Remote   public interface AdderImplRemote {   int add(int a,int b);   }  

File: AdderImpl.java package com.javatpoint; import javax.ejb.Stateless;      @Stateless(mappedName="st1")   public class AdderImpl implements AdderImplRemote {     public int add(int a,int b){         return a+b;     }   }  

2) Create stateless bean client The stateless bean client may be local, remote or webservice client. Here, we are going to create remote client. It is console based application. Here, we are not using dependency injection. The dependency injection can be used with web based client only. File: AdderImpl.java package com.javatpoint;   import javax.naming.Context;   import javax.naming.InitialContext;      public class Test {   public static void main(String[] args)throws Exception {       Context context=new InitialContext();       AdderImplRemote remote=(AdderImplRemote)context.lookup("st1");       System.out.println(remote.add(32,32));   }   Output: 64

EJB Architecture This picture shows a somewhat simplified architecture of EJB. We will talk about the concept of containers and components later on. But a key architectural concept of EJB is that there is a separation of business logic components from the hosting execution environment in which those components are running. The business logic components under EJB architecture are represented as EJB beans while the hosting environment is represented by EJB container (sometimes called as EJB server). As a business component developer, you have to write three Java files and a deployment descriptor. First you have to write EJB home interface which defines the methods that will be used by clients in order to create and locate your bean through the container. Second, you have to write EJB remote interface which defines the business methods of your bean. Finally, you will build your bean and deployment descriptor which specifies which Java interface is home interface and which Java interface is remote interface, and which class is in fact your bean class. Now container, at the time of deployment of your beans, will create two internal and intermediary objects, EJB home object and EJB remote object. These objects are implementation of home and remote interface you have defined. So when the client wants to invoke some business methods of the EJB bean you created, it is actually talking to these two intermediary objects instead. Why this indirection? This is to allow the container to intercept the calls so that it can provide system services such as security, transaction, persistence, resource management, life cycle management, and so on.

Why EJB Technology? Leverages the benefits of component-model on the server side Separates business logic from system code Container provides system services Provides framework for portable components Over different J2EE-compliant servers Over different operational environments Enables deployment-time configuration Deployment descriptor Why EJB? By providing a standard component model on the server side, it leverages all the benefits that are inherent in component technology, for example, simplified development and deployment and reuse of the code. Another key benefit of EJB is the separation of business logic from system code. That is, the EJB server platform provides all the system services such as resource management, transaction coordination and persistence management. Since the system services are provided by the server platform itself, you, as a developer, can now focus your development effort to building business logic components rather than system code. Because EJB is built around industry-standard component framework, because it is based on Java, it allows portability of your components. That is, the business logic components you build will be portable across different vendors’ server platforms as well as different operational environments without any change in your code or without even recompiling. It is truly binary portability we are talking about. Now you might want to ask? How do these components adapt themselves to the different operational environments? That is, different operational environments have different requirements on security policy, they have different databases in place , different transactional model maybe have to be used. How do you instruct your business components to a different behavior without actual change of code? It is done by what is called deployment descriptor. The deployment descriptor is essentially an XML file that specifies the runtime behavioral characteristics of your business component. And it gets constructed or changed at the time of deployment not at the time of code development.

Enterprise JavaBeans Enterprise JavaBeans Entity Bean Message-Driven Bean Synchronous communication Asynchronous communication Stateless Stateful Bean managed Persistence (BMP) Container managed (CMP) Session Bean Now EJB has three bean type - session bean, entity bean, and message driven bean. And session bean can be either stateful or stateless session bean. And entity bean can be either bean managed or container managed. And you as a developer choose which bean type to use depending on the needs and requirements of your application. For example, you use session bean when you have to have a client session and you use entity beans to reflect persistent data and you use message driven bean to receive messages in an asynchronous fashion. And we will talk about these bean types and their usage in gory detail later in this course.