Java EE 5 tutorial Chap1 & Chap20

chap1

Java EE Application Model

The business functions to support these vatious users are conducted in the middle tier.

The JEE application model defines an architecture for implementing services as multitier applications that deliver the scalability, accessibility, and manageability needed by enterprise-level applications. This model partitions the work needed to implement a multitier service into two parts: the business and presentation logic to be implemented by the developer, and the standard system services provided by the Java EE platform.

Distributed Multitiered Applications

For enterprise applications: 分布式多层应用结构 distributed multitiered application model, application logic is divided into components according to function, 不同的application components组成了jee application, various application components are installed on different machines, 依据在分层jee中application components属于哪一层。

四个components: client-tier componentsweb-tier componentsbusiness-tier componentsenterprise information system (EIS)-tier software

分布在三个machine上: client machine/ Java EE Server machine/ Database Server

尽管有四层,但仍认为JEE multitiered applications是三层,因为分布在三个不同的地点。

Java EE Components

A Java EE component is a self-contained functional software unit, which is assembled into a JEE application with its related classes and files. They can communicate with other components.

Run on the client: Application clients and applets

Run on the server:

  1. Web components: Java Servlet, JavaServer Faces, JavaServer Pages (JSP) technology components
  2. Business components: Enterprise JavaBeans (EJB) components (enterprise beans

Java EE Clients

Java EE Client可以是一个web client或者是一个application client。

Web Clients

contains:

  1. dynamic web pages containing various types of markup language, which are generated by web components running in the web tier
  2. a web browser, which renders the pages received from the server

Is also called a thin client. Do not query databases, execute complex business rules or connect to legacy applications. 执行thin client时,重量级操作在JEE Server的enterprise beans上,使用服务器端的技术(安全、速度、服务、可靠性等

Applets

小程序。applet时很小的客户端程序,嵌入网页中,客户端需要插件。

首选API是web components因为没有插件。应用程序设计更简单(因为application programming和web page design分开了

Application CLients

Has a GUI created from Swing or the Abstract Window Toolkit (AWT) API, but a command-line interface is certainly possible.

直接access在business tier的enterprise beans,如果application需要warrant,application client可以用HTTP连接去和web tier的servlet建立联系。

可以用多种语言写,不仅仅是Java

The JavaBeans Component Architecture

client tier和serve tier应该有基于此的组件,用来管理application client/applet和JEE server上运行的组件之间的数据流,或者是在server组件和数据库之间的数据流。

该组件有properties, have get and set methods for accessing the properties.

Java EE Server Communications

客户端与Java EE Server的business tier的交流要么是通过thick application client(直接交流),要么通过thin browser-based client(间接交流,中间通过JSP Pages或者Servlets,在web tier上运行)。

Tradeoff:直接交流的用户体验好 make for a better perceived user experience,间接交流更分布式 off-load to the server: the easier it is to distribute, deploy, and manager the application.

Web Components

Business Components

对于特定的业务,解决特定的问题 handled by enterprise beans running in the business tier

Recieve data from client programs, process it (if necessary), and sends it to the enterprise information system tier for storage.

An enterprise bean also retrieves data from storage, process it (if necessary), send it back to the client program.

Enterprise Information System Tier

The enterprise information system tier handles EIS software and includes enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems.

For example, Java EE application components might need access to enterprise information systems for database connectivity.

Java EE Containers

thin client很难写,因为要处理复杂的事务、多线程、资源池等等。component-based和platform-independent Java EE结构使Java EE applications很好写。business logic已经被组织成reusable components。

Java EE server以container的形式为每一个component提供基础服务。

Container Services

container是在component和low-level平台的功能之间的interface。web、enterprise bean或者application client component被执行之前,都必须先组装到Java EE模块中并且deploy到container里。

container可以使用Jave EE提供的基础支持:

Security: 特定用户才能访问web component或是enterprise bean(实验中的ManagerSession在ejb的源包里

Transaction:确定一个transaction中的所有的方法之间的关系,一个transaction中的所有方法被认为是一个整体

JBDI Lookup: unified interface to multiple naming and directory services in the enterprise,application component可以access这些service

Java EE remote connectivity model:低层communications在clients和enterprise bean之间。在enterprise bean被创建之后,client可以像在同一个virtual machine上一样调用上面的方法。

Container Types

Web Services Support

Java EE Application Assembly and Deployment

一个Java EE application被打包成一个或多个标准unit,可以deploy到任意Java EE platform-compliant system。

每一个unit都包含:一个functional component or components (such as an enterprise bean, JSP page, servlet, or applet) / an optional deployement descriptor that describes its content

Java EE unit被产生就准备好deploy

Packaging Applications

A Java EE application is delivered in an Enterprise Archive (EAR) file, 是一个JAR文档,扩展名为.ear。

An EAR file contains Java EE modules and deployment descriptors. A deployment descriptor is an XML document with an .xml extension that describes the deployment settings of an application, a module, or a component.

There are two types of deployment descriptors: Java EE and runtime.

 A Java EE deployment descriptor is defined by a Java EE specification and can be used to configure deployment settings on any Java EE-compliant implementation.

A runtime deployment descriptor is used to configure Java EE implementation-specific parameters.

A Java EE module consists of one or more Java EE components for the same container type and one component deployment descriptor of that type.

Development Roles

component developers:

application assembler: (seperate)

application deployer and administrator:

configures the JEE application for the operational environment

Deploys (installs) the JEE application into the server

Chap20 Enterprise Beans

Enterprise beans run in the EJB container, a runtime environment within the Application Server.

What Is an Enterprise Bean?

Written in Java programming language.

A server-side component that encapsulates the business logic (the code that fulfills the purpose of the application) of an application.

Benefis of Enterprise Bean

Simplifying the development of large. distributed applications -- EJB container is responsible for system-level services such as transaction managerment and security authorization./ beans contain the application's business logic, the client developer does not have to code the routines that implement business rules or access databases./ enterprise beans are portable components, the application assembler can build new applications from existing beans

When to Use Enterprise Beans

1. Application must be scalable. You need to distribute an application's components across multiple machines.

2. Transactions must ensure data integrity

3. The application will have a variety of clients.

Types of Enterprise Beans

What Is a Session Bean

A session bean represents a single client inside the Application Server. To access an application that is deployed on the server, the client invokes the session bean’s methods. The session bean performs work for its client, shielding the client from complexity by executing business tasks inside the server.

Similiar to an interactive session.

Not persistent (the data is not saved to a database)

Example: ManagerSession and ReservationSession

State Management Modes

stateful session bean:

The client interacts with its bean, this state is often called the conversational state.

The state is retained for the duation of the client-bean session. If the client removes the bean or terminates, the session ends and the state disappears.

stateless session bean:

Does not maintain a conversational state with the client.When method is finished, the client-specific state should not be retained. The state of a stateless session bean should apply across all clients.

They can support multiple clients, can offer better scalability for applications that require large numbers of clients. An application requires fewer stateless session beans than stateful session beans to support the same number of clients.

Can implement a web service, but other types of enterprise beans cannot.

When to Use Session Beans

What Is a Message-Driven Bean

An enterprise bean which allows JEE applications to process messages asynchronously.The messages can be sent by any JEE component (an application client, another enterprise bean or a web component)

Difference Between Messages-Driven Beans and Session Beans

The most visible difference between them is that client do not access message-driven beans through interfaces. Unlike a session bean, a message-driven bean has only a bean class.

从某些方面来说,message driven bean被认为是stateless session bean,因为它的实例不为某一特定用户保存数据或对话状态,其中所有的实例都是相等的(equivalent),允许EJB container去给任何一个message driven bean实例分发消息,一个单独的message driven bean可以处理多个clients的消息

Following characteristics:

1. They execute upon receipt of a single client message.

2. They are invoked asynchronously.

3. They are relatively short-lived.

4. They do not represent directly shared data in the database, but they can access and update this data.

5. They can be transaction-aware.

6. They are stateless.

Defining Client Access with Interface

-- session beans not to message-driven beans, the later does not have interfaces that define client access.

A client can only access a session bean through the methods defined in the bean's business interface.所有的方法实现都隐藏了.

client不接触EJB tier的复杂性,EJB tier也可以随时改变函数不影响client。

Session beans can have more than one business interface. Session beans should but are not required to implement their business interface or interfaces.

When designing a JEE application, one of the first decisions you make is the type of client access allowed by the enterprise beans: remote, local, or web service.

Remote Clients:

Run on a different machine and a different JVM than the enterprise bean it access.(Not required)

Can be a web component, an application client or another enterprise bean.

Use @Remote to define the interface

Use @Remote to define the class implements interface.

remote client using remote interface to access the session bean

e.g. client用managerSessionRemote来调用managerSession中的method

Local Clients:

Must run in the same JVM as the enterprise bean it accesses. 

Can be a web component or another enterprise bean.

To the local client, the location of the enterprise bean it accesses is not transparent.

Deciding on Remote or Local Access

Tight or loose coupling of related beans

Type of client

Component distribution

Performance

Creating references to EJBs in clients: 

构件引用

@EJB

private static BeanInterface mybean;

Container will fill this in with an EJB that provides the interface.

在client中创建,创建之后mybean.getMethod(), 调用interface中的方法。

Contents of an EJB

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值