Presentation is loading. Please wait.

Presentation is loading. Please wait.

J2EE Course 2018/11/20.

Similar presentations


Presentation on theme: "J2EE Course 2018/11/20."— Presentation transcript:

1 J2EE Course 2018/11/20

2 参考书 Designing Enterprise Applications with the J2EE Platform, Second Edition Architecting and Designing J2EE Applications,SL-425 Core J2EE Patterns 2018/11/20

3 内容 J2EE架构 EJB基础 EJB设计模式 2018/11/20

4 J2EE架构 2018/11/20

5 J2EE Platform 分布的,多层的 Client tier提供用户界面 Middle tier为客户端提供服务,实现应用的业务逻辑
后台的EIS系统提供数据管理 典型J2EE环境中的组件和服务 2018/11/20

6 J2EE应用程序场景 Multitier Application Scenario Stand-Alone Client Scenario
Web-Centric Application Scenario Business-to-Business Scenario 2018/11/20

7 J2EE应用程序场景 Multitier Application Scenario Stand-Alone Client Scenario
Web-Centric Application Scenario Business-to-Business Scenario 2018/11/20

8 J2EE应用程序场景 Multitier Application Scenario Stand-Alone Client Scenario
Web-Centric Application Scenario Business-to-Business Scenario 2018/11/20

9 J2EE应用程序场景 Multitier Application Scenario Stand-Alone Client Scenario
Web-Centric Application Scenario Business-to-Business Scenario 2018/11/20

10 J2EE应用程序场景 Multitier Application Scenario Stand-Alone Client Scenario
Web-Centric Application Scenario Business-to-Business Scenario 2018/11/20

11 J2EE组件和容器 Client components Web components EJB components Applet
Application client Java Web Start-enabled rich client Wireless client Web components Servlet Jsp EJB components Session bean Entity bean Message-driven bean 2018/11/20

12 J2EE平台服务和服务技术 J2EE平台提供一系列服务,并允许以统一的方式访问这些服务 平台服务(Platform Service)
简化编程的工作, 允许在部署时间对组件和应用程序进行定制 应用程序或组件可以使用被部署环境中的资源 服务技术(Service Technologies) 允许应用程序以统一的方式访问各种服务 标准的API,供组件开发人员使用服务 标准的SPI,供J2EE产品提供商实现服务 2018/11/20

13 平台服务 Naming services Deployment Services Transaction Services
可以在不改变组件源码的情况下定制组件 使用一个名字访问数据库连接,其他的组件等资源 Deployment Services 在打包和部署定制应用程序/组件 部署描述符 J2EE.ear=client.jar+web.war+ejb.jar+connector.rar Transaction Services Flat:不允许嵌套事务 Distributed:支持分布式事务 Security Services 认证(Authentication) 授权(Authorization) 2018/11/20

14 服务技术 Java Naming and Directory Interface(JNDI) JDBC API
JDBC 2.0 Core API JDBC 2.0 Extension API,连接池和分布式事务支持 Java Transaction API and Service(JTA,JTS) JTA JTS Java Connector Architecture(JTA) 连接J2EE平台和EIS Java API for XML Processing Technology DOM:Document Object Model SAX:Event-based Model XSLT 2018/11/20

15 通信技术 Internet Protocols Remote Method Invocation Protocols
TCP/IP HTTP 1.0 SSL 3.0 Remote Method Invocation Protocols Object Management Group Protocols JavaIDL RMI-IIOP Message Technologies Java Message Service API JavaMail API JavaBeans Activation Framework API Data Formats HTML 3.2 Image files JAR file Class file XML 2018/11/20

16 EJB基础 2018/11/20

17 为创建 EJB 服务器端组件,Enterprise Bean 开发人员提供了两个定义 bean 商业方法的公共接口——Remote接口和Home接口(或者Local接口和LocalHome接口),以及真正的 bean 实现类——Bean Class。 客户机使用 bean 的公共接口来创建、操作 bean,以及从服务器除去 bean。 bean实现类在运行时被实例化。 EJB的构成 2018/11/20

18 EJB的构成 Bean实现类: Entity Bean的实现类实现javax.ejb.EntityB ean接口。
Session Bean的实现类实现javax.ejb.Sess ionBean接口。 Message-driven Bean的实现类实现javax.ejb. Message DrivenBean接口。 Bean实现类要实现Remote/Local接口中定义的商业方法,以及Home/LocalHome接口中定义的创建、破坏、查找方法。 EJB的构成 2018/11/20

19 EJB2.0中Session Bean和Entity Bean可以有两种客户端视图——Local Client View和Remote Client View:
Remote Client View适用于分布式环境,对Remot/Home接口方法的调用都是远程调用,因此对性能有一定的影响(特别是在细粒度的情况下)。 Local Client View避免了远程方法调用的开销,但是客户端和服务器必须存在于同一JVM中,同时失去了分布式环境带来的好处。 EJB的构成 Remote Client View Local Client View 2018/11/20

20 EJB的构成 Home/LocalHome接口: Factory Home接口继承javax.ejb.EJBHome接口。
LocalHome接口继承javax.ejb.EJBLocalHome接口。 Home接口中都要定义bean的创建、破坏、查找方法。 EJB的构成 2018/11/20

21 EJB的构成 Remote/Local接口: Delegate 供客户端调用商业方法的接口。
Remote接口继承javax.ejb.EJBObject接口。 Local接口继承javax.ejb.EJBLocalObject接口。 两个接口中都要定义bean的商业方法。 EJB的构成 2018/11/20

22 EJB的构成-类图 2018/11/20

23 EJB的构成-部署描述符 ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" " <ejb-jar> <enterprise-beans> <session> <ejb-name>Hello</ejb-name> <home>examples.HelloHome</home> <remote>examples.Hello</remote> <local-home>examples.HelloLocalHome</local-home> <local>examples.HelloLocal</local> <ejb-class>examples.HelloBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar> 2018/11/20

24 EJB的构成-打包 Remote/Home接口及实现类的class文件,实体Bean还包括primary key class
部署描述符(META-INF/ejb-jar.xml) 2018/11/20

25 EJB容器 2018/11/20

26 EJB容器 在部署EJB时,容器会为每个EJB: 根据Home接口和Remote接口产生Home Object和Remote Object
生成stub和skeleton 根据部署描述符设置安全环境 根据部署描述符设置事务环境 在JNDI名称空间中注册EJB——包括Home接口、资源引用等 为CMP的实体Bean创建数据库表 2018/11/20

27 EJB容器 客户端在访问EJB时: 通过JNDI查找到Home Object的引用
通过Home Interface上的create方法创建一个Remote Object Home Object会创建并返回一个Remote Object 调用Remote Interface上的商业方法 Remote Object截取调用进行处理,然后委托Bean Class完成商业方法 Remote Object截取Bean Class的返回进行处理,然后将结果返回给客户端 2018/11/20

28 EJB容器 Bean Class在执行商业方法时可以访问容器:
可以通过EJBContext对象(它是对容器的直接引用)请求关于环境的信息:如Client的身份、事务的状态以及自身的引用。 可以通过JNDI访问资源,如JDBC连接、其它的EJB等。 2018/11/20

29 EJB容器 容器在管理EJB生命周期过程中,通过回调方法通知EJB状态的变化: Bean Class实现并响应这些回调方法,进行相应的处理
不同类型的EJB回调方法各不相同,如Session Bean包括:ejbCreate;ejbRemove;ejbPassivate;ejbActivate。 2018/11/20

30 Enterpise Bean Entity Bean Session Bean Message-Driven Beans
Container-Managed Persistent Entity Bean Bean-Managed Persistent Entity Bean Session Bean Stateful Session Bean Stateless Session Bean Message-Driven Beans 2018/11/20

31 EJB设计模式 Session Facade Business Delegate Value Object Composite Entity
Value Object Assembler Value List Handler Data Access Object Service Locator 2018/11/20

32 Session Facade Context:
In a multi-tiered application, business logic is encapsulated in server–side components. Business components expose interfaces and complexity to clients. Problem: Application clients need to use business components to fulfill their responsibilities. The BusinessObjects expose their interfaces and clients access the business objects directly. This introduces a tight coupling between business components and clients. In some scenarios, several business components may be used in succession. This exposes clients to dependencies between BusinessObjects, and can introduce network chattiness. BusinessObjects are not protected from misuse or abuse by clients. Forces Clients need a simpler interface. The number of BusinessObjects exposed over the network must be reduced. The client should not have to manage interactions between business components. A unified service layer must be provided for coarsegrained access by all clients, based on use cases. BusinessObjects and clients should be decoupled. Solution A Session bean as a Façade encapsulates complex interactions between the business objects in a workflow. The Session Façade will be responsible for: locating, creating, and modifying the business objects Providing a uniform coarse-grained access layer to all clients Handling relationships between business objects 2018/11/20

33 Session Facade 2018/11/20

34 Session Facade 2018/11/20

35 Business Delegate Context:
The system exposes the entire business service API to its clients, often across a network. Problem: Presentation tier components are interacting directly with business services, exposing the underlying implementation details of the service API. Additionally, the presentation tier components that use the service API make too many calls over the network. If the implementation of the business services change, all the exposed implementation code in the presentation tier will also need to change. Forces Presentation tier clients need access to business services. Service APIs may change as business requirements evolve. There is a need to minimize coupling between presentation tier clients and the business service API, hiding underlying implementation details of the service, such as lookup and access. The system would benefit from a caching mechanism for service information. There is a need to minimize the network traffic between client and business services. Solution Use a business delegate to reduce coupling between presentation tier clients and business services. The business delegate hides the underlying implementation details of the business service, such as look–up and access details of EJBs. 2018/11/20

36 Business Delegate 2018/11/20

37 Business Delegate 2018/11/20

38 Value Object 2018/11/20

39 Value Object 2018/11/20

40 The End 2018/11/20


Download ppt "J2EE Course 2018/11/20."

Similar presentations


Ads by Google