Download 10.4 The Java Naming and Directory Interface (JNDI)

Document related concepts
no text concepts found
Transcript
J2EE
Lecture 10: EJB 3.0 Overview
Dr. Ming Qiu
Xiamen University
Software School
[email protected]
Mastering EJB3.0, Chap 1
10.1 Overview
What plumbing do you need to build a
robust distributed object deployment?
What is EJB, and what value does it add?
Mastering EJB3.0, Chap 1
10.1 Overview
EJB is a server-side component
framework
simplifies the process of building enterpriseclass distribute component application in Java
Mastering EJB3.0, Chap 1
10.1 Overview
What is Software Component?
A piece of code written to manifest the behavior
of a corresponding abstract concept.
Sounds like Objects, but it is different
Self-contained Entity
• Be used in a similar or completely different application
• Can live an independent, reusable existence outside of
original application
• A system can be designed to consist of reusable
components
Mastering EJB3.0, Chap 1
10.1 Overview
The Need for Componentization
Lack of flexibility and interoperability
Component Framework
Common Object Request Broker Architecture
(CORBA)
ActiveX/COM
EJB
Mastering EJB3.0, Chap 1
10.1 Overview
Remote method
invocation
Loading balancing
Transparent failover
Back-end integration
Transaction
Clustering
Dynamic
redeployment
Mastering EJB3.0, Chap 1
10.1 Overview
 Clean shutdown
 Logging and Auditing
 Systems management
 Threading
 Message-oriented middleware
 Component life cycle
 Resource pooling
 Security
 Caching
 And much…
 Each of these aspects can be thought of as a service
Mastering EJB3.0, Chap 1
10.1 Overview
Application Server-Class Software
Building Middleware Services from Scratch
Buying Middleware Services via Application
Server Software
Mastering EJB3.0, Chap 1
10.1 Overview
 Standardization of Component Frameworks
More than 50 application servers on the market
Need an agreement to enable any component
to run within any application server
Mastering EJB3.0, Chap 1
10.1 Overview
Mastering EJB3.0, Chap 1
10.1 Overview
Enterprise JavaBeans Technology
A standard for developing and deploying
server-side distribute components in Java
It is a ubiquitous industry standard
Portability is possible
Rapid application development
EJB is two things in one
Specification
A set of Java Interfaces
Mastering EJB3.0, Chap 1
10.1 Overview
Why Java
Interface/implementation separation
Safe and security
If a thread dies, the application stays up
No memory pointer in java
Memory leaks occur much less often
Cross-platform
Mastering EJB3.0, Chap 1
10.1 Overview
EJB as a Business Tier Component
Presentation tier components deal directly with
end user or end application
Business tier components perform server-side
operation
Such as executing complex algorithm or performing
transactional business operation
Mastering EJB3.0, Chap 1
10.1 Overview
EJB components can perform following tasks
Performing business logic
Access a database
Integrate with other systems
Examples of EJB clients
Application clients
Dynamically generated Web pages
Web service clients
Mastering EJB3.0, Chap 1
10.1 Overview
Mastering EJB3.0, Chap 1
10.1 Overview
 Distributed Computing: The Foundation of EJB
Mastering EJB3.0, Chap 1
the Java Platform, Enterprise Edition
10.0 (Java EE)
Mastering EJB3.0, Chap 1
the Java Platform, Enterprise Edition
10.0 (Java EE)
 A uncompleted list of JavaEE Technologies














Enterprise JavaBean(EJB)
Java API for Web Services(JAX-WS)
Java Remote Method Invocation (RMI) and RMI-IIOP
Java Naming and Directory Interface (JNDI)
Java Database Connectivity (JDBC)
Java Transaction API(JTA) and Java Transaction Service(JTS)
Java Message Service (JMS)
Java Servlets
Java Server Pages (JSP)
Java Server Faces (JSF)
Java EE Connector Architecture (JCA)
The Java API for XML Parsing (JAXP)
The Java Architecture for XML Binding (JAXB)
The Java Authentication and Authorization Service (JAAS)
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Briefly introduce the programming and
deployment model in EJB2.0
To realize the breadth and depth of
enhancements made in EJB3.0
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Differences between the local and the
remote interface
The local interface extends
javax.ejb.EJBLocalObject instead of
javax.ejb.EJBObject
The business method does not throw a
java.rmi.RemoteException
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Differences between the local and the
remote home interface
The local home interface extends
javax.ejb.EJBLocalHome instead of
javax.ejb.EJBHome
The local home interface methods do not throw
java.rmi.RemoteException
Mastering EJB3.0, Chap 2
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Mastering EJB3.0, Chap 2
Mastering EJB3.0, Chap 3
Mastering EJB3.0, Chap 2
10.2 Pre-EJB 3.0: The World That Was
Dissect EJB 2.x
Development Complexities
Deployment Complexities
Debugging and Testing Complexities
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
EJB Container
Responsible for managing enterprise bean
Transaction management
Security
Resource and life cycle management
Remote accessibility
Support for concurrent requests
Clustering and load-balancing
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Type of Bean
Session beans
model business processes
Stateful & Stateless session bean
Message-driven beans (MDBs)
Similar to session beans, but driven by message
Entity beans (deprecated)
Model business data
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
RMI-IIOP: The Protocol of Bean
EJB and Location Transparency
JNDI is an enabler of location transparency
Provides a standard API to access different kinds of
naming and directory services within a java program
Provides two API
• Naming API
• Directory API
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
The EJB 3.0 Simplified API
No home and object interfaces
No component interface
Use of Java metadata annotations
Simplification of APIs for accessing bean’s
environment
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Elimination of Home and Object Interface
Pre EJB 3.0
The Home interface served as a factory for creating
reference to the EJB Object.
The EJB Object Interfaces was to provide client view
for an EJB
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Elimination of Component Interface
Pre EJB 3.0
Components need to implement
javax.ejb.SessionBean or
javax.ejb.MessageDrivenBean
• Carried the various life cycle method
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Use of Annotations
Annotations are used to provide the additional
context to program.
Can be applied to various elements in Java
Methods, variables, constructors, package
declarations
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Annotations and Bean Development
EJB 3.0 is a mix of metadata tags and code structs
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Annotations and Deployment Descriptions
EJB 3.0 annotations can be used in lieu of
deployment descriptors.
Container Specific Deployment Description
Describe the value-added services of container
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
The Good, Bad and Ugly of Deployment
Annotation
Convenient
Place configuration along with the bean’s logic.
Tricky
When the bean provider and deployer is not the
same person.
Simplified Access to environment
Mastering EJB3.0, Chap 3
Package and Deployment of the “New” Bean
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
Example of EJB 3.0 Bean
The Business Interface
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
 The Bean Class
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
The Deployment Descriptor
Mastering EJB3.0, Chap 3
10.3 The New Enterprise JavaBean
 The Client
Mastering EJB3.0, Chap 3
Summary of Term
 The enterprise bean instance
 A POJO contains business method implementation of
local/remote business interface
 The business interface
 A plain old java interface that enumerates the business methods
exposed by the enterprise bean.
 The deployment descriptor
 A XML file that specifies the middleware requirements of the
bean
 The Ejb-jar file
 The package unit for enterprise bean
 The vendor-specific deployment descriptor
 Specify the bean’s need for proprietary container.
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Naming Service
Associates names with objects
Provides a facility to find an object with a name
Directory Service
A naming service that has been extended and
enhanced to provide directory object operations
to manipulating attribute
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
 Problems with Naming and Directory
Different Directory vendors offer different types of
services
 Lightweight Directory Access Protocol (LDAP)
 Network Information System (NIS)
 Network Directory System (NDS)
 What is JNDI
A System for java client to access Naming and Directory
systems
Provide one common interface to disparate directories
Mastering EJB3.0, Appendix A
Architecture
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
JNDI in JavaEE
Using JNDI to acquire a reference to the JTA
User-Transaction interface
Using JNDI to connect to resource factories,
such as JDBC drivers or JMS drivers
Using JNDI for clients and for beans to look up
other beans
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
JNDI Concepts
Atomic Name
A simple, basic, indivisible name
• In the string /etc/fstab, etc and fstab are atomic names
Compound Name
Zero or more atomic names put together using a
specific syntax
• /etc/fstab is a compound name
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Binding
An association of a name with a object
• Autoexec.bat  a file
• C:\windows  a folder
• /usr/people/ed/.cshrc  multiple bindings
Context
A set of zero or more bindings
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Naming System
A connected set of contexts that use the same name
syntax.
Namespace
The set of names contained in a naming system
javax.naming.Name
javax.naming.Context
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Composite Name
A name that spans multiple naming systems
• http://java.sun.com/product/ejb/index.html
Initial Context
The starting point of exploring a namespace
javax.naming.InitialContext
Initial Context Factory
Be implemented by JNDI drivers
churns out initial context
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
 java.naming.factory.initial
 The name of the environment property for specifying
the initial context factory to use
 java.naming.provider.url
The name of the environment property for specifying the
location of the JBoss JNDI service provider the client will
use.
 java.naming.factory.url.pkgs
The name of the environment property for specifying the
list of package prefixes to use when loading in URL
context factories.
Mastering EJB3.0, Appendix A
10.4 The Java Naming and Directory
Interface (JNDI)
 All the environment parameters can be put into
jndi.properties file, found on classpath.
Mastering EJB3.0, Appendix A