EJB Development and Support Services. EJB Development and Support Services Topics to be Covered: EJB Design Bean/Container Interaction Java Naming and.

Slides:



Advertisements
Similar presentations
Communicating in J2EE.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
JNDI Java Naming Directory Interface JNDI is an API specified in Java that provides naming and directory functionality to applications written in Java.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
JBoss Seam: Contextual Components Jason Bechtel
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Entities and Persistence. Entity Beans Topics to be Covered: Entities are POJOs Managed/Unmanaged Entities Persistence Unit EntityManager Basic Relational.
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.
Basics of JNDI Alessio Bechini June Naming and Directory Services: Rationale A fundamental element in every application is the capability to find.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Distributed System Using Java 2 Enterprise Edition (J2EE)
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.
Brad Rippe Fullerton College. What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container.
Enterprise Java Beans CS-422. Application Servers In the late 1980s and though the mid 1990s a number of corporations (Broadvision, Netscape…) marketed.
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,
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
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.
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.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li
J2EE Structure & Definitions Catie Welsh CSE 432
Enterprise Java v120131Intro to JavaEE1 Java EE 5 TM Introduction.
Enterprise Java Beans Java for the Enterprise Server-based platform for Enterprise Applications Designed for “medium-to-large scale business, enterprise-wide.
Topic : JNDI Kaster Nurmukan. JNDI2(c)CDAC(Formerly NCST) What is JNDI? Naming and Directory Services Naming Concepts Issues JNDI Architecture Programming.
Java Naming and Directory Interfaces. A naming service is an entity that performs the following tasks:  It associates names with objects. Similar to.
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Ch 2 – Application Assembly and Deployment COSC 617 Jeff Schmitt September 14, 2006.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
Databases JDBC (Java Database Connectivity) –Thin clients – servlet,JavaServer Pages (JSP) –Thick clients – RMI to remote databases –most recommended way.
© jGuru.com Enterprise JavaBeans Fundamentals.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
Assignment of JAVA id : BSSE-F10-M-10-JAVA1 Overview of J2EE/Session 2/Slide 1 of 38.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
© 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.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
©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.
Alan L. Batongbacal CS 4244 / 01 Nov 2000
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
IS-907 Java EE Introduction to JPA. Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes,
Middleware Technology (J2EE/EJB) EJB Fundamentals.
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.
J2EE Lecture 10: EJB 3.0 Overview
EJB (Enterprise Java Beans)
Knowledge Byte In this section, you will learn about:
Understanding and Designing with EJB
Objectives In this lesson, you will learn to:
Understanding and Designing with EJB
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

EJB Development and Support Services

EJB Development and Support Services Topics to be Covered: EJB Design Bean/Container Interaction Java Naming and Directory Interface (JNDI) Using Enterprise Beans Server Side Services

EJB Development and Support Services EJB Design

Class and Interface Review javax.ejb package –Core of the EJB API Remote interface –Defines bean’s remote business methods Local interface –Defines bean’s local business methods Endpoint interface –Defines SOAP-accessible business methods Message interface –Defines methods for asynchronous messages Bean class –Implementation of business and lifecycle methods

Remote Interface Defines business methods import public interface CalculatorRemote { public int add(int x, int y); public int subtract(int x, int y); }

Bean Class Actual implementation of business methods import public class CalculatorBean implements CalculatorRemote { public int add(int x, int y) { return x + y; } public int subtract(int x, int y) { return x – y; }

Entity Java Persistence API public class Cabin { private int id; private String name; private int deckLevel;

@Column(name=“ID”) public int getId() { return id; } public void setId(int pk) { this.id = pk; }

Remaining public String getName() { return name; } public void setName(String str) { this.name = str; public int getDeckLevel() { return deckLevel; } public void setDeckLevel(int level) { this.deckLevel = level; } }

Primary Keys Pointer that locates an enterprise bean Defined by the bean developer Must map to one of the following types: –Any Java primitive type (including wrappers) –java.lang.String –Primary-key class composed of primitives and/or Strings

Primary Key Class Composed of primitives and/or strings Must be serializable Must have a public no-arg constructor Must implement the equals() and hashCode() methods

Deployment Descriptors Specifies how to apply primary services –security –transactions –naming Specifies persistence unit and associated database Describe runtime attributes of server-side component

EJB Packaging JAR Files used for packaging –Applets –Applications –JavaBeans –Web Application –Enterprise JavaBeans Bean classes Component interfaces Supporting Classes Appropriate Deployment Descriptors

Example Deployment Descriptor ProcPayBean com.relaxalot.ProcPayRemote com.relaxalot.ProcPayLocal com.relaxalot.ProcPayBean Stateless

XML and/or Annotations Defaults make XML deployment descriptors optional –Default transaction property REQUIRED –Default security semantics UNCHECKED Annotations provide further information –Metadata placed directly in the bean class file –Deployment descriptors can override annotations

Example persistence.xml java:/TitanDB

EJB Development and Support Services Bean/Container Interaction

EJB Container Implementation Component interfaces allow external or co- located clients to interact with session bean class Component interfaces interact with instances of the session bean class Proxy Stub –Interacts with client, sends message to EJB Container EJB Object –Implements remote interface –Wraps enterprise bean instance –Generated by the container

bean remote interface EJB object EJB Architecture EJB Container remote interface EJB object proxy Client

EJB Container Intermediary between bean and server Interaction defined by SessionBean interface, and JMS-MessageDrivenBean onMessage() method javax.ejb.EJBContext interface implemented by the container. Bean uses EJBContext interface to communicate with EJB environment JNDI namespace

EJB Development and Support Services Java Naming and Directory Interface (JNDI)

Naming and Directory Services Naming Service –Associates names with Objects –Provides facility to find an object based on a name –Examples: DNS, File System Directory Object –Contains attributes –Like a record in a database Directory Service –Provides directory object operations for manipulating attributes

JNDI Architecture JNDI Application Filesystem Service Provider Filesystem LDAP Service Provider LDAP Directory RMI Service Provider RMI Registry

JNDI API Benefits Standard Java Extension –javax.naming –javax.naming.directory Unified system for resource access Insulates application from naming and directory service protocols Extensible Composite or federated namespaces

Naming Concepts Binding –Association of a name with an object Context –Set of bindings Subcontext –Binding one context within another usr bin tom Context Subcontext Binding

Context & InitialContext javax.naming.Context interface –Collection of bindings –Operations apply only to bindings, not to Context itself javax.naming.InitialContext class –Implements the Context interface –Starting point for exploring a namespace –Requires an initial context factory com.sun.jndi.fscontext.RefFSContextFactory

InitialContext Properties InitialContext constructor takes a set of properties Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.fscontext.RefFSContextFactory”); props.put(Context.PROVIDER_URL,”file:///”); Context initialContext = new InitialContext(props);

Looking Up Objects lookup() method Specify the name of the child Type of returned object determined by service provider Container with children should implement javax.naming.Context Object obj = initialContext.lookup(name);

Listing Objects list() method Returns a list of names of an object’s children as an instance of javax.naming.NamingEnumeration NamingEnumeration contains a collection of javax.naming.NameClassPair objects Browsing is a combination of list() and lookup() calls NamingEnumberation kids = initialContext.list(name);

Binding Objects bind() method Creates a Binding object Use rebind() if name already exists Use unbind() to remove a binding File newfile = File(“c:\temp\newfile”); tempContext.bind(“newfile”, newfile);

JNDI and JDBC JDBC 2.0 DataSource –Provides Database connections –Information to create connections are stored as properties –Registered with a directory service Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(“jdbc/EmployeeDB”); Connection con = ds.getConnection(); con.close();

JNDI and EJB JNDI used to locate a specific EJB Home Context ctx = new InitialContext(); Object ref = ctx.lookup(“TravelAgntBean”); TravelAgntRemote dao = (TravelAgntRemote) PortableRemoteObject.narrow(ref, TravelAgntRemote.class); dao.makeReservation();

JNDI Environment Naming Context Part of Bean-Container Contract Common naming context –java:comp/env Declare resources using XML deployment descriptor or Annotation –EJBs –JDBC DataSource –Java Message Service –Environment Properties Context ctx = new InitialContext();

ENC Example (Deployment Descriptor) – Describing the Resource DataSource for Relaxalot Database theDataSource javax.sql.DataSource Container java:/DefaultDS edu.weber.ProcessPaymentBean dataSource

ENC Example (Annotation) – Describing the Resource public class ProcessPaymentBean implements ProcessPaymentRemote DataSource dataSource

ENC Example – Use the Resource public class ProcessPaymentBean implements ProcessPayment Remote {... private boolean process() { Connection con = dataSource.getConnection();... con.close(); }

EJB Development and Support Services Using Enterpise Beans

Entities Model data and behavior –Provide interface to data –Business rules that directly affect data –Relationships with other entities // Use javax.persistence.PersistenceContext // annotation to get access to entities // using an EntityManager service that // references a persistence private EntityManager manager;... public void createCabin(Cabin cabin) { manager.persist(cabin); }

Session Beans Model processes and tasks –Functions of the business Inappropriate for client application or entity beans Provide business logic Control workflow // Lookup session bean TravelAgent tAgent = (TravelAgent)... // Create a reservation tAgent.setCustomer(customer); tAgent.setRoomID(roomID); tAgent.setHotelID(hotelID); Ticket ticket = tAgent.bookReserve(creditCard, price);

Session Beans Stateful –Maintain conversational state State kept in memory Dedicated to a single client Stateless –No conversational state Method calls are independent –Provide higher performance A few stateless beans can service many clients

EJB Development and Support Services Server Side Services

Resource Management Instance Pooling –Clients do not directly access EJB’s –Number of instances can be efficiently managed and minimized –Reuse existing beans for different client requests Activation Mechanism –Used for stateful session beans –Passivation Serialize bean’s state to storage –Activation Restore a stateful bean instance’s state

Concurrency Multiple clients accessing the same bean at the same time Not supported by session beans Entities represent shared data –Java Persistence spec: persistence container protects shared data by making a copy of the entity bean on a per-transaction basis –Defense against stale reads or simultaneous updates is vendor specific –EJB prohibits synchronized keyword –EJB prohibits beans from creating threads

Transactions Set of tasks executed together –Atomic Reservation and Payment must both be successful Manage automatically –Declare transactional attribute Manage explicitly –Use javax.transaction.UserTransaction object

Persistence Applies to Entities –Java Persistence specification Plain Old Java objects (POJO) Can be created outside the scope of the EJB container Attached/Detached Entity Manager –Object-to-relational persistence Map entity state to relational database tables and columns

Distributed Object Interoperability Location Transparency –CORBA IIOP –Support mandated in EJB 3.0 RMI/IIOP SOAP via JAX-RPC API Programming model used by Java EJB Client –Other protocols and clients can be supported by servers CORBA clients written in C++, Smalltalk, Ada using EJB-to-CORBA mapping SOAP clients written in Visual Basic.NET, C#, Perl using EJB-to-SOAP mapping

Asynchronous Enterprise Messaging Message-driven Beans (MDBs) Route messages from JMS clients to JMS-MDB Reliable delivery –Attempt redelivery on failure Persisted messages Transactional EJBs can send messages

EJB Development and Support Services Topics to be Covered: EJB Design Bean/Container Interaction Java Naming and Directory Interface (JNDI) Using Enterprise Beans Server Side Services