Upload
kathlyn-spencer
View
251
Download
3
Tags:
Embed Size (px)
Citation preview
Seminar: Enterprise JavaBeans
AgendaAgenda
• Java™ 2 PlatformJava™ 2 Platform
• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)
• Enterprise JavaBeans ™ Enterprise JavaBeans ™
• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture
Java™ 2 Platform
Java HistoryJava History
1995 Sun World951995 Sun World95
1996 JDK1.0 Final Release1996 JDK1.0 Final Release
1997 JDK1.1 Final Release1997 JDK1.1 Final Release
1999 JDK1.2 Final Release1999 JDK1.2 Final Release
2000 JDK1.3 Final Release2000 JDK1.3 Final Release
Today/TomorrowWeb ContentWeb Content
E-mailE-mail
EntertainmentEntertainment
TravelTravel
Personal Personal Finance Finance
E-commerceE-commerce
Voice Over IPVoice Over IP
Long Distance Long Distance PhonePhone
Today’s Enterprise
Short History of Java Enterprise Technology
Java™ 2 Platform
Java™ 2 Platform,Standard Edition(J2SE) Java™ 2 Platform,Standard Edition(J2SE)
Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)
Java™ 2 Platform,Micro Edition(J2ME)Java™ 2 Platform,Micro Edition(J2ME)
Java™ 2 Platform
Java HistoryJava History
Java Enterprise ArchitectureJava Enterprise Architecture
PDAPDA
KioskKiosk
Java DeviceJava Device
VideoVideoServerServer
SolsticeSolsticeFirewallFirewall
WebWebServerServer
WorkstationWorkstation
ServerServer Java DesktopJava Desktop
Corporate Corporate LANLAN
PCPC
WorkgroupWorkgroupServerServer
MainframeMainframe
Public InternetPublic
InternetCorporateCorporateIntranetIntranet
CorporateCorporateIntranetIntranet
FirewallFirewall
BeeperCell PhoneATMGame
AgendaAgenda
• Java™ 2 PlatformJava™ 2 Platform
• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)
• Enterprise JavaBeans ™ Enterprise JavaBeans ™
• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture
Java™ 2 PlatformEnterprise Edition(J2EE)
Application Servers
Provides infrastructure to support Provides infrastructure to support management of business logic and access to management of business logic and access to servicesservices
Provide proprietary APIs,which leads to Provide proprietary APIs,which leads to vendor lockvendor lock
Diminishes ability to reuse business logic on Diminishes ability to reuse business logic on another vendor’s application serversanother vendor’s application servers
Enterprise Goals
ReuseReuse
InteroperabilityInteroperability
PortabilityPortability
Time-to-MarketTime-to-Market
Why another Java 2 Platform?Enterprise Services Require
AvailabilityAvailability
DistributionDistribution
ConcurrencyConcurrency
SecuritySecurity
ConsistencyConsistency
ScalabilityScalability
EIS IntegrationEIS Integration
AdministrationAdministration
What is J2EE ?
J2EEJ2EE is An Integrated Application is An Integrated Application Environment ( consist of below )Environment ( consist of below )– API specifications (EJB,JSP,JDBC etc)
Defines J2EE requirements
– Reference implementation of APIsOperational J2EE platform
– Compatibility tests with brandingValidates J2EE platform compatibility
– Application Programming ModelDescribes how to build J2EE application
What is J2EE ? The enterprise developer can concentrate on The enterprise developer can concentrate on
application components,not the underlying application components,not the underlying services services
Separation of business logic and services Separation of business logic and services provide for better reuse of business logic provide for better reuse of business logic
BusinessBusiness
logiclogicBusinessBusiness
logiclogic
ServicesServices ServicesServices
J2EE Architecture
J2EE API Summary
• J2SE 1.3
• JDBC 2.0
• RMI/IIOP 1.0
• EJB 1.1.x
• Servlet 2.2
• JSP 1.1
• J2SE 1.3
• JDBC 2.0
• RMI/IIOP 1.0
• EJB 1.1.x
• Servlet 2.2
• JSP 1.1
• JNDI 1.2
• JTA 1.0
• JMS 1.0
• JavaMail 1.1
• JAF 1.0
• JNDI 1.2
• JTA 1.0
• JMS 1.0
• JavaMail 1.1
• JAF 1.0
J2EE Standard Services
• Web• Database• Naming and
Directory• Management• Email • Protocol• Transaction
• Web• Database• Naming and
Directory• Management• Email • Protocol• Transaction
Servlet/JSP(HTML/XML)
JDBCTM
JNDI
JMX
JavaMail TM
JavaIDL/RMI
OTS/JTS/JTA
Servlet/JSP(HTML/XML)
JDBCTM
JNDI
JMX
JavaMail TM
JavaIDL/RMI
OTS/JTS/JTA
Services Java Technology
J2EE Platform
J2EE is important
Integrated Application EnvironmentIntegrated Application Environment
Open platformOpen platform
Integrates with existing environmentsIntegrates with existing environments
Provides foundation for future developmentProvides foundation for future development
AgendaAgenda
• Java™ 2 PlatformJava™ 2 Platform
• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)
• Enterprise JavaBeans ™ Enterprise JavaBeans ™
• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture
Enterprise JavaBeans ™
EJB Architecture
EJB Design Goals Simplify development/deployment of Simplify development/deployment of
distributed applicationsdistributed applications Achieve broad industry acceptanceAchieve broad industry acceptance The right expert focuses on the right jobThe right expert focuses on the right job Platform independent and protocol Platform independent and protocol
neutralneutral Enable development of portable Enable development of portable
components - Truly enable reusecomponents - Truly enable reuse
A server-side component architecture Model to enable efficient development
and deployment of Java applications :
– Transactional,Portable
– Distributed,Multi-tier
– Scalable
– Secure
Defining Enterprise JavaBeans
Defining Enterprise JavaBeans EJB is not JavaBeansEJB is not JavaBeans
a Server Component specification for Javaa Server Component specification for Java
Separates business and system programminSeparates business and system programmin
gg
Portability of business objectsPortability of business objects
Extensibility through vendor featuresExtensibility through vendor features
JavaBeans Versus Enterprise JavaBeans
Java Beans• Can be either visible or no
n-visible• Intended to be local to a si
ngle process on the client side
• Uses the BeanInfo classes, Property Editors & Customizers to describe itself
• Can also be deployed as an ActiveX control
Java Beans• Can be either visible or no
n-visible• Intended to be local to a si
ngle process on the client side
• Uses the BeanInfo classes, Property Editors & Customizers to describe itself
• Can also be deployed as an ActiveX control
Enterprise JavaBeans• Are decidedly Non-Visible,
remote objects• Remotely executable comp
onents deployed on the server
• Uses the Deployment Descriptor to describe itself
• Can not deployed as an ActiveX control since OCXs run on the desktop
Enterprise JavaBeans• Are decidedly Non-Visible,
remote objects• Remotely executable comp
onents deployed on the server
• Uses the Deployment Descriptor to describe itself
• Can not deployed as an ActiveX control since OCXs run on the desktop
JavaBeans Versus Enterprise JavaBeans
Java Beans
Server
Client
Client Enterprise information Services
Enterprise information Services
Existingapplication
Database
EJB2
EJB3
EJB1Java Beans
Java Beans
Java Beans
Java Beans
Container
Server manages resources suchas threads, connection pooling,caching, and state management
What Is Special About EJBs?
Learn onceLearn once Write Once, Run Anywhere Write Once, Run Anywhere TMTM
Portable and interoperablePortable and interoperable Flexible and extensibleFlexible and extensible ScalableScalable Easier to write distributed applicationsEasier to write distributed applications Transaction managementTransaction management CORBA compatibleCORBA compatible
AgendaAgenda
• Java™ 2 PlatformJava™ 2 Platform
• Java™ 2 Platform,Enterprise Edition(J2EE)Java™ 2 Platform,Enterprise Edition(J2EE)
• Enterprise JavaBeans ™ Enterprise JavaBeans ™
• Enterprise JavaBeans ™ ArchitectureEnterprise JavaBeans ™ Architecture
Enterprise JavaBeans ™Architecture
Key Components in EJB
EJB ServerEJB Server
EJB containerEJB container
Home ObjectHome Object
EJBObjectEJBObject
Enterprise BeanEnterprise Bean
EJB Architecture Overview
EJB HomeClass
EJB ObjectInterface
EJB HomeInterface
EJB ObjectClass
EJB ClassDeploymentDescriptor Manifest
EJB ServerEJB Server
EJB EJB ContainerContainer
EJB Architecture Overview
ClientClientClientClient
Enterprise PropertiesEnterprise Properties
HomeHome
ObjectObjectHomeHome
ObjectObject
EJBEJB
ObjectObjectEJBEJB
ObjectObject
EJBEJBEJBEJB
JNDIJNDINamingNaming TransactionTransaction PersistencePersistence SecuritySecurity
ServicesServices
66
5544
33
22
11 11111010
99
88
77
Application Life Cycle
EJB Server Provides System ServicesProvides System Services
Transaction supportTransaction support Database accessDatabase access System resourceSystem resource NamespaceNamespace
ImplementationsImplementations Middleware serversMiddleware servers Application serversApplication servers Database serversDatabase servers
EJB Server
Supplies containers for EJBsSupplies containers for EJBs
API between server and container is API between server and container is currently vendor specificcurrently vendor specific
Server could provide several container Server could provide several container types to provide various extended types to provide various extended services to different beansservices to different beans
EJB Container
Currently provided by EJB ServerCurrently provided by EJB Server
EJB access to server resource through EJB access to server resource through standard API standard API
May Contain one or multiple classesMay Contain one or multiple classes
Tools for EJB creation and deploymentTools for EJB creation and deployment
EJB Container Some standard servicesSome standard services
PersistencePersistence EJB instance creation & locationEJB instance creation & location NamespaceNamespace Transaction controlTransaction control SwappingSwapping SecuritySecurity
Custom servicesCustom services Application-specificApplication-specific Bridge to existing systems Bridge to existing systems
Home Interface
Factory interface for the bean:Factory interface for the bean: Interface provided by EJB developerInterface provided by EJB developer Class generated by vendor toolClass generated by vendor tool
One factory class per bean class One factory class per bean class
Factory instance is installed into the Factory instance is installed into the server’s naming serviceserver’s naming service
Home Interfaceimport java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface ConverterHome extends EJBHome {
Converter create() throws RemoteException,
CreateException;
}
Remote Interface
Interface is provided by bean developer Interface is provided by bean developer
Implementation is provided byImplementation is provided by container tools, which include container tools, which include
Stubs and SkeletonsStubs and Skeletons The EJB ObjectThe EJB Object
Remote Interface
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Converter extends EJBObject {
public double dollarToYen(double dollars)
throws RemoteException;
public double yenToEuro(double yen)
throws RemoteException;
}
EJB Object The EJB Object is a wrapper object thatThe EJB Object is a wrapper object that
Acts as a proxy to the EJB instanceActs as a proxy to the EJB instance
Interface provided by Bean DeveloperInterface provided by Bean Developer Implementation class generated by tool Implementation class generated by tool
Each business method has a correspondingEach business method has a corresponding method in the EJB Object method in the EJB Object Wrapper method implements container-Wrapper method implements container- provided servicesprovided services
EJB Architecture Overview
ClientClientClientClient
HomeHome
InterfaceInterfaceHomeHome
InterfaceInterface
RemoteRemote
InterfaceInterfaceRemoteRemote
InterfaceInterfaceEJBEJBEJBEJB
Home ObjectHome Object
EJB ObjectEJB Object BeanBean
RemoteRemote
InterfaceInterfaceRemoteRemote
InterfaceInterfaceEJBEJBEJBEJB
StubStubStubStub SkeletonSkeletonSkeletonSkeleton
EJB Sourceimport java.rmi.RemoteException;
import javax.ejb.*;
public class ConverterEJB implements SessionBean {
public double dollarToYen(double dollars) {
return dollars * 121.6000;
}
public double yenToEuro(double yen) {
return yen * 0.0077;
}
public ConverterEJB() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
Types of EJBs
Server
Client
ClientEnterprise information
ServicesEnterprise information
Services
Existingapplication
DatabaseEJB2
EJB3
EJB1
Container
Proxy
Proxy
Proxy
Session BeansClient state
Entity BeansState of data
Session Beans Versus Entity Beans
Session BeansPrivate client resource
Bean carries client state
Bean is not persistent
Lifetime is controlled
by client
Transactional participant
Single-threaded
Mandatory since 1.0
Session BeansPrivate client resource
Bean carries client state
Bean is not persistent
Lifetime is controlled
by client
Transactional participant
Single-threaded
Mandatory since 1.0
Entity BeansAccess by multiple clients concurrently
Bean represents state of data in data store
Bean is persistent
Lifetime corresponds to its persistent
store
Transactional by nature
Single-threaded
Mandatory since 1.1
Entity BeansAccess by multiple clients concurrently
Bean represents state of data in data store
Bean is persistent
Lifetime corresponds to its persistent
store
Transactional by nature
Single-threaded
Mandatory since 1.1
Client Sourceimport javax.naming.*;
import javax.rmi.PortableRemoteObject;
import Converter;
import ConverterHome;
public class ConverterClient {
public static void main(String[] args) {
try { Context initial = new InitialContext();
Object objref = initial.lookup("MyConverter");
ConverterHome home =
(ConverterHome)PortableRemoteObject.narrow(objref,ConverterHome.class);
Converter currencyConverter = home.create();
double amount = currencyConverter.dollarToYen(100.00);
System.out.println(String.valueOf(amount));
amount = currencyConverter.yenToEuro(100.00);
System.out.println(String.valueOf(amount));
} catch (Exception ex) { }
}
}
Enterprise EJB Scenario
HTTP response
HTTP request
DB
Enterprise Application ServerEnterprise Application Server
JSPsJSPs BackOffice
JDBC
JDBC
JMS
JMS
EJBsEJBs
JSP/ServletJSP/Servlet Java BeansJava Beans