middlewareReview

中间件复习大纲
目录
第一章 overview of middleware
一、 了解中间件背景
二、*什么是中间件
三、IDC的中间件分类
四、中间件的特点及优势
五、 *中间件在应用软件开发中的作用。并举例说明!Software glue
第二章 AS与javaEE
一、*什么是应用服务器
二、Application Server/Web Server是中间件软件
三、多层应用体系的优势(C/S和B/S)
四、*什么是JavaEE
五、*JavaEE and N-Tiers Architecture
六、面向对象编程(Object-Oreinted Programming)
七、JavaEE开发模式(分布式与非分布式)
第三章 UDA and ORM
一、JDBC类型
二、*DAO设计模式
二、 ORM/Hibernate
第四章 MOM消息中间件
一、*什么是Message Oriented Middleware
二、 *企业什么需要MOM?
三、Queue和Topic模式
四、同步和异步通信:UDA 、RPC、ORB、TMP、MOM、RMI
五、MOM特点
第五章 JMS and ActiveMQ
一、*什么是JMS
二、JMS的消息类型
三、被管理的对象
四、JMS客户端编程
五、JMS中的Session
六、JMS与RMI
七、ActiveMQ 默认协议 Blobmessage
第六-七章 分布对象技术-CORBA
一、*什么是CORBA和ORB
二、OMA的CORBA体系结构
三、对象模型和参考模型
四、*什么是POA
五、IDL and Mapping to Java (Java IDL)
六、CORBA的命名服务CosNaming(IDL)
七、绑定对象引用和获得对象引用(Java或C++)
第八章 分布对象技术-JavaRMI
一、会定义一个远程接口
二、JavaRMI的应用
第九章 XML
一、XML 与 HTML
二、格式良好的文档
三、理解DOM 和SAX接口
四、使用Xpath读取指定的标签
第十章 EJB- SessionBean
一、*什么是EJB
二、*JNDI
三、JNDI的应用
四、如何访问EJB组件
五、有状态会话Bean和无状态会话Bean
六、会话Bean生命周期
七、定义一个SessionBean(EJB3.0)

第一章 overview of middleware
一、了解中间件背景
计算机等技术的发展,导致了开放系统概念的提出,为了使得系统开放,互操作性是关键因素之一,由此引出了中间件的概念。
The development of computer technology leads to the concept of open system. In order to make the system open, interoperability is one of the key factors, which leads to the concept of middleware.
二、*什么是中间件
中间件是一种软件,它能使处于应用层中的各应用成分之间实现跨网络的协同工作,这时允许各应用成分之下所涉及的“系统结构、操作系统、通信协议、数据库和其他应用服务”各不相同。
Middleware is a kind of software, which enables the application components in the application layer to work together across the network. At this time, it allows the “system structure, operating system, communication protocol, database and other application services” under the application components to be different.
三、IDC的中间件分类
1、事务处理中间件
2、消息中间件
3、分布式中间件

  1. Transaction processing middleware
  2. Message middleware
  3. Distributed middleware
    四、中间件的特点及优势
    1、从企业应用来说
    1.1 缩短应用开发的周期
    1/2减少项目开发风险
    1.3 应用系统质量及可维护性
    1.4 增加产品吸引力
    2、从应用程序来说
    透明的同其他应用程序交互
    与运行平台提供的网络通信服务无关
    具有良好的可靠性和可用性
    具有良好的可扩展性1. From the perspective of enterprise applications
    1.1 shorten application development cycle
    1/2 reduce project development risk
    1.3 application system quality and maintainability
    1.4 increase the attractiveness of the product
    2, from the application
    Transparent interaction with other applications
    It is independent of the network communication service provided by the running platform
    Good reliability and availability
    Good scalability
    五、*中间件在应用软件开发中的作用。并举例说明!Software glue
    中间件带给应用系统的不只是开发的简便、开发周期的缩短,还减少了系统的维护、运行和管理的工作量,同时减少了计算机总体费用的投入。Standish的调查报告显示,由于采用了中问件技术,应用系统的总建设费用可以减少50%左右。在网络经济、电子商务大发展的今天,从中间件获得利益的不只是IT厂商,IT用户同样是赢家,并且是更有把握的赢家。
    Middleware not only makes the application system easy to develop and shortens the development cycle, but also reduces the workload of system maintenance, operation and management, as well as the total cost of computer.According to Standish’s survey report, the total cost of building an application system can be reduced by about 50% due to the adoption of medium component technology.Today, with the development of network economy and e-commerce, IT is not only IT manufacturers that benefit from middleware, IT users are also winners, and even more sure winners.

第二章 AS与javaEE
一、*什么是应用服务器
应用服务器是指通过各种协议把商业逻辑曝露给客户端的程序。它提供了访问商业逻辑的途径以供客户端应用程序使用。应用服务器使用此商业逻辑就像调用对象的一个方法一样。
Application servers are programs that expose business logic to clients through various protocols.It provides access to business logic for use by client applications.The application server USES this business logic as if it were a method calling an object.

二、Application Server/Web Server是中间件软件

三、多层应用体系的优势(C/S和B/S)
C/S优点和缺点
优点:
2.1 C/S架构的界面和操作可以很丰富。
2.2 安全性能可以很容易保证,实现多层认证也不难。
2.3 由于只有一层交互,因此响应速度较快。
缺点:
2.4 适用面窄,通常用于局域网中。
2.5 用户群固定。由于程序需要安装才可使用,因此不适合面向一些不可知的用户。
2.6 维护成本高,发生一次升级,则所有客户端的程序都需要改变。

B/S优点和缺点
优点:
1)客户端无需安装,有Web浏览器即可。
2)BS架构可以直接放在广域网上,通过一定的权限控制实现多客户访问的目的,交互性较强。
3)BS架构无需升级多个客户端,升级服务器即可。
缺点:
1)在跨浏览器上,BS架构不尽如人意。
2)表现要达到CS程序的程度需要花费不少精力。
3)在速度和安全性上需要花费巨大的设计成本,这是BS架构的最大问题。
4)客户端服务器端的交互是请求-响应模式,通常需要刷新页面,这并不是客户乐意看到的。
四、*什么是JavaEE
Java EE是具有JVM和一组特定API的编写网络应用程序的平台。
Java EE is a platform for writing web applications with a JVM and a specific set of apis.
课件 Definition of Java EE:Open and standard based platform for developing, deploying
and managing n-tier, Web-enabled, server-centric, component-based enterprise applications.

五、*JavaEE and N-Tiers Architecture
在这里插入图片描述

N-Tiers Architecture:
O-瘦客户:提供简洁的人机交互界面,完成数据的输入/输出。

业务服务(中间层):完成业务逻辑、实现与数据库通信、实现分布式管理
负载均衡、Fail/Recover、安全隔离等。

数据服务:提供数据存储。

六、面向对象编程(Object-Oreinted Programming)
基于组件开发(Component-Based Development)
面向服务架构(Service-Oreinted Architecture)

七、JavaEE开发模式(分布式与非分布式)
非分布式体系结构比较适合于Web应用,它们在一个容器里
处理所有的页面逻辑和业务逻辑,所有的应用组件都只运行
在同一个JVM里面。系统变得简单而有效。
Non-distributed architectures are better suited for Web applications that are in a containerHandle all page logic and business logic, and all application components run onlyIn the same JVM.The system becomes simple and efficient.

分布式系统经典的开发模式
通过EJB及其调用EJB的组件部署在不同JVM的方式对应用进行物理的以及逻辑的划分
A classic development model for distributed systemsApplications are physically and logically partitioned by the way ejbs and the components that invoke them are deployed in different JVMS

第三章 UDA and ORM

一、JDBC类型
Oracle OCI Driver and Oracle Thin Driver

二、*DAO设计模式
DAO = DataAccessor + Domain Object
DAO(Data Access Object,数据访问对象),主要的功能是用于进行数据操作的,在程序的标准开发框架中属于数据层的操作。

在DAO模式中,将对数据的持久化抽取到DAO层,暴露出Service层让程序员使用,这样,一方面避免了业务代码中混杂JDBC调用语句,使得业务落实实现更加清晰。
通常我们创建一个包,用于保存DAO接口,再创建一个包,用于保存DAO接口的实现类即可。
DAO (Data Access Object), the main function is used for Data operation, in the standard development framework of the program belongs to the operation of the Data layer.In the DAO pattern, the data persistence was extracted into the DAO layer, exposing the Service layer for programmers to use. In this way, on the one hand, the mixed JDBC call statements in the business code were avoided, and the business implementation was more clear. Usually we create a package to hold the DAO interface, and then create a package to hold the implementation classes of the DAO interface.

二、ORM/Hibernate
Hibernate是轻量级的JavaEE应用的持久层框架,Hibernate不仅管理Java类到数据表的映射,还提供数据查询和获取数据的方法,可大幅度缩短处理数据持久化的时间。
ORM的全称是:Object/Relation Mapping,即对象/关系数据库映射。ORM可理解成一种规范,它概述了这类框架的基本特征,完成面向对象的变成语言到数据库的映射。
Hibernate is a lightweight JavaEE application persistence layer framework. Hibernate not only manages the mapping of Java classes to data tables, but also provides methods for data query and data acquisition, which can significantly reduce the time of data persistence.The full name of ORM is :Object/Relation Mapping, that is, Object/ relational database Mapping.ORM can be understood as a specification that Outlines the basic characteristics of such a framework, enabling object-oriented mapping into a language into a database.

第四章 MOM消息中间件

一、*什么是Message Oriented Middleware
面向消息的中间件(MOM)是支持在分布式系统之间发送和接收消息的软件基础设施。MOM允许在异构平台上分布应用程序模块,并降低了开发跨越多个操作系统和网络协议的应用程序的复杂性。中间件创建一个分布式通信层,将应用程序开发人员与各种操作系统和网络接口的细节隔离开来。扩展到不同平台和网络的api通常由MOM提供。
Message-oriented middleware (MOM) is software infrastructure supporting sending and receiving messages between distributed systems. MOM allows application modules to be distributed over heterogeneous platforms and reduces the complexity of developing applications that span multiple operating systems and network protocols. The middleware creates a distributed communications layer that insulates the application developer from the details of the various operating systems and network interfaces. APIs that extend across diverse platforms and networks are typically provided by MOM.

二、*企业什么需要MOM?
–部署规模庞大
—网络状况复杂
—数据量大
—系统维护管理复杂
分布对象技术ORB局限性
– the deployment scale is huge-- -complex network condition-- -large amount of data-- -complex system maintenance and managementORB limitations of distributed object technology
面对规模和复杂度都越来越高的分布式系统,消息中间件技术显示出了它的
优越性:
采用异步通信模式
客户和服务对象生命周期的松耦合关系

三、Queue和Topic模式
Queue消息由发布者发送到特定的接收者。
Topic模式消息发布者可以将消息发布到主题(Topic), 用户或应用程序根据主题或
内容接收消息。
Queue messages are sent by the publisher to a specific receiver.
A message publisher in the Topic pattern can publish messages to topics, depending on the Topic or applicationContent receives messages.

四、同步和异步通信:UDA 、RPC、ORB、TMP、MOM、RMI
消息队列框架的通信模式是异步的!

同步: 应用发送请求后一直等待,直到请求被处理。如:JDBC、ORB等
客户端请求的同时,服务必须在线。Data Connectivity RPC ORB TPM
优点:
易编程
输出立即可知
更易恢复错误 (通常)
更好实时响应 (通常)
缺点:
服务必须启动、在线
请求方阻碍占用资源
通常要求面向连接的通信协议

异步: 应用发送请求,然后在将来检查请求是否被处理完成。
客户端请求时,服务无需在线。MOM
优点:
请求无需指定服务器
服务无需在线
由于没有占用, 资源可以释放
可以使用非连接协议如UDP
缺点:响应时间不可预测
错误处理通常复杂
难以设计程序

五、MOM特点
在这里插入图片描述
某高校数据集成系统如图所示,在每个数据源上都安装了TongLink/Q软件。TongLink/Q是消息中间件软件,它在该系统中的作用?

消息中间件作为一个中间层软件,它为分布式系统中创建、发送、接收消息
提供了一套可靠通用的方法,实现了分布式系统中可靠的、高效的、实时的
跨平台数据传输。
MOM指的是利用高效可靠的消息传递机制进行平台无关的数据交流,并基
于数据通信来进行分布式系统的集成。

第五章 JMS and ActiveMQ

一、*什么是JMS
JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送消息,进行异步通信。Java消息服务是一个与具体平台无关的API,绝大多数MOM提供商都对JMS提供支持。
JMS, the Java Message Service (Java) application interface, is a Java platform API for message-oriented middleware (MOM) used to send messages between two applications or in a distributed system for asynchronous communication.The Java messaging service is a platform-independent API, and JMS is supported by the vast majority of MOM providers.

二、JMS的消息类型
TextMessage 主体包含字符串
BytesMessage 主体包含连续字节流
MapMessage 主体包含键值对
StreamMessage主体包含流
ObjectMessage 主体包含对象

三、被管理的对象
JMS管理对象
管理对象(Administered objects)是预先配置的JMS对象,由系统管理员为使用JMS的客户端创建,主要有两个被管理的对象:
• 连接工厂(ConnectionFactory)
• 目的地(Destination)
这两个管理对象由JMS系统管理员通过使用Application Server管理控制台创建,存储在应用程序服务器的JNDI名字空间或JNDI注册表。

四、JMS客户端编程

public static void main(String[] args) {
        // 连接工厂
        ConnectionFactory connectionFactory;
        Connection connection = null;
        Session session;
        Destination destination;
        MessageProducer messageProducer;
        
   
  	// 实例化连接工厂
        connectionFactory = new ActiveMQConnectionFactory(JMSProMessType.USERNAME, JMSProMessType.PASSWORD
        , JMSProMessType.BROKEURL);
 
        try {
            // 通过连接工厂获取连接
            connection = connectionFactory.createConnection();
            // 启动连接
            connection.start();
            // 创建session
            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
            // 创建一个名称为HelloWorld的消息队列
            destination = session.createQueue("HelloWorld");
            // 创建消息生产者
            messageProducer = session.createProducer(destination);
            
            // 发送消息
            sendStreamMessage(session, messageProducer);
 
            session.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(connection != null){
                try {
                    connection.close();
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        }
 
    }

五、JMS中的Session
这个是状态保持三大对象之一! 原意是会话,会议的意思! 就是你打开浏览器到关闭浏览器 这期间称为一个会话,也就是一个session, 它是保存在服务器端的. 每当客户端请求页面时,服务器就会自动分配一个ID 来唯一标识这个用户! 所以 这个ID 就是 在客户端和服务器端的连接! 但是一般不要用session来保存大量的数据,因为这样占用服务器端的资源!

六、JMS与RMI
RMI 采用stubs 和 skeletons 来进行远程对象(remote object)的通讯。stub 充当远程对象的客户端代理,有着和远程对象相同的远程接口,远程对象的调用实际是通过调用该对象的客户端代理对象stub来完成的,通过该机制RMI就好比它是本地工作,采用tcp/ip协议,客户端直接调用服务端上的一些方法。优点是强类型,编译期可检查错误,缺点是只能基于JAVA语言,客户机与服务器紧耦合。
JMS是Java的消息服务,JMS的客户端之间可以通过JMS服务进行异步的消息传输。JMS支持两种消息模型:Point-to-Point(P2P)和Publish/Subscribe(Pub/Sub),即点对点和发布订阅模型。

JMS和RMI区别:
采用JMS 服务,对象是在物理上被异步从网络的某个JVM 上直接移动到另一个JVM 上(是消息通知机制) 而RMI 对象是绑定在本地JVM 中,只有函数参数和返回值是通过网络传送的(是请求应答机制)。 RMI一般都是同步的,也就是说,当client调用Server的一个方法的时候,需要等到对方的返回,才能继续执行client端,这个过程调用本地方法感觉上是一样的,这也是RMI的一个特点。 JMS 一般只是一个点发出一个Message到Message Server,发出之后一般不会关心谁用了这个message。 所以,一般RMI的应用是紧耦合,JMS的应用相对来说是松散耦合应用。

七、ActiveMQ 默认协议 Blobmessage
ActiveMQ中默认的消息协议就是openwire:Blob(Binary Large OBjects)发送大一点的文本文件或者图片

JMS与RMI
JMS与RMI的区别:

  1. 通信方式不同
    JMS支持同步和异步消息处理模式。(事务 同步)
    RMI基于请求/应答的同步通信模式。(基于RPC)

  2. 耦合度不同
    JMS建立了一个松散耦合的通信框架。图一在这里插入图片描述
    在这里插入图片描述
    RMI是紧耦合结构。图二

  3. 需求对象获得方式
    JMS:对象从网络的某个节点移动到另一个节点。
    RMI:对象是绑定在本地JVM 中,只有参数和返回值是通过网络传送。
    第六-七章 分布对象技术-CORBA
    一、*什么是CORBA和ORB

CORBA是由OMG组织制订的一种标准的面向对象( 组件)应用程序体系结构(规范),为解决分布式处理环境(DCE)中,硬件和软件系统的互连而提出的一种解决方案。 CORBA是由OMG组织制订的一种标准的面向对象( 组件)应用程序体系结构(规范),
为解决分布式处理环境(DCE)中,硬件和软件系统的互连而提出的一种解决方案。
CORBA is the acronym for Common Object Request Broker Architecture™, OMG®’s open, vendor-independent architecture and infrastructure that computer applications use to work together over networks. Using the standard protocol IIOP, a CORBA-based program from any vendor, on almost any computer, operating system, programming language, and network, can interoperate with a CORBA-based program from the same or another vendor, on almost any other computer, operating system, programming language, and network.

ORB:联结应用程序、各种对象、CORBA服务、CORBA工具集的核心
CORBA的核心是对象请求代理ORB,它提供对象定位、对象激活和对象通讯的透明机制。客户发出要求服务的请求,而对象则提供服务,ORB把请求发送给对象、把输出值返回给客户。ORB的服务对客户而言是透明的,客户不知道对象驻留在网络中何处、对象是如何通讯、如何实现以及如何执行的,只要他持有对某对象的对象引用,就可以向该对象发出服务请求。
At the core of CORBA is the object request broker ORB, which provides a transparent mechanism for object location, object activation, and object communication.The client issues the request for the service, and the object provides the service, and the ORB sends the request to the object and returns the output value to the customer.The ORB service is transparent to the customer, who does not know where the object resides in the network, how it communicates, how it is implemented, or how it is executed, and can make service requests to an object as long as he holds an object reference to that object.

二、OMA的CORBA体系结构
OMA由对象请求代理ORB、对象服务、公共设施、域接口和应用接口这几个部分组成,其核心部分是对象请求代理ORB(Object Request Broker)。对象服务是为使用和实现对象而提供的基本服务集合;公共设施是向终端用户应用程序提供的一组共享服务接口;域接口是为应用领域服务而提供的接口;应用接口是由开发商提供的产品,用于它们的接口,不属于OMG标准的内容。ORB提供了一种机制,通过这种机制,对象可以透明的发出请求和接收响应。分布的、可以互操作的对象可以利用ORB构造可以互操作的应用。
OMA consists of the Object Request Broker ORB, Object services, common facilities, domain interfaces, and application interfaces, and at its core is the Object Request Broker.Object services are a collection of basic services provided for the use and implementation of objects.Common facilities are a set of Shared service interfaces provided to end-user applications;A domain interface is an interface provided for application domain services.Application interfaces are products provided by developers for their interfaces and are not part of OMG standards.ORB provides a mechanism through which objects can transparently issue requests and receive responses.Distributed, interoperable objects can make use of the ORB to construct interoperable applications.

三、对象模型和参考模型
OMA包括两部分:Object Model and Reference Model
对象模型:定义如何描述分布式异构环境中的对象。
网络环境中的分布对象如何以实现无关的方式进行描述。
在OMA对象模型中,对象是一个被封装的实体,它具有一个不可改变的标识,
并能给客户用户提供一个或多个服务。

interface printer
{
	attribute long model;
	void print(in string buffer);
};

参考模型:描述对象之间的交互。
分布对象间如何通过ORB进行交互。
在OMA参考模型中,OMG定义了一条为对象所公用的通信总线,即ORB。
四、*什么是POA(服务器端)
POA(Portable Object Adapter)可移植对象适配器:是BOA的替代方式,提供大量可扩展的接口。
POA是一个对象管理器,类似于EJB容器,或者Spring的IoC容器,主要用于负责创建、激活、定位以及回收对象等操作。
POA(Portable Object Adapter) : an alternative to BOA that provides a large number of extensible interfaces.A POA is an object manager, similar to an EJB container, or Spring’s IoC container, that is responsible for creating, activating, locating, and retrieving objects.

五、IDL and Mapping to Java (Java IDL)
OMG IDL接口定义语言用来描述产生对象调用请求的客户对象和服务对象之间的接口的语言。
OMG IDL文件描述了服务器提供的服务功能,客户机可以根据该接口文件
描述的方法向服务器提出业务请求。
OMG IDL interface definition language (IDL) is a language used to describe the interface between the customer object and the service object that generates the object invocation request.
The OMG IDL file describes the service capabilities provided by the server, and the client can refer to this interface file
The described method makes a business request to the server.

六、CORBA的命名服务CosNaming(IDL)
七、绑定对象引用和获得对象引用(Java或C++)

第八章 分布对象技术-JavaRMI
一、会定义一个远程接口

import java.rmi.Remote;
import java.rmi.RemoteException;
public interface InterfaceService extends Remote {
/**远程服务对象所必须实现的方法
* 所有的远程调用的方法,必须声明throws RemoteException
* */
Object service(Object obj) throws RemoteException;
}

二、JavaRMI的应用

第九章 XML
一、XML 与 HTML

  1. html是用来显示数据的;xml是用来描述数据、存放数据的,所以可以作为持久化的介质!Html将数据和显示结合在一起,在页面中把这数据显示出来;xml
    则将数据和显示分开。 XML被设计用来描述数据,其焦点是数据的内容。HTML被设计用来显示数据,其焦点是数据的外观。
    二、格式良好的文档
    在这里插入图片描述
    三、理解DOM 和SAX接口
    DOM(Document Object Model 文档对象模型),在应用程序中,基于DOM的
    XML解析器将XML文档转换成对象模型的集合(DOM树),通过对这个对象
    模型的操作,来实现对XML文档数据的操作。
    DOM的基本对象类型:Document(I)、Node(I)、NodeList(I)、Element(I)和Attr(I)
    DOM(Document Object Model), in the application, based on the DOMThe XML parser converts the XML document into a collection of object models (DOM trees) by manipulating the objectModel operation, to achieve the operation of XML document data.DOM’s basic object types: Document(I), Node(I), NodeList(I), Element(I)And Attr (I)
public static void main(String[] args){
  try{
       //得到DOM解析器的工厂实例 
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       //从DOM工厂获得DOM解析器  
      DocumentBuilder builder = factory.newDocumentBuilder();
      //DOM解析器解析XML文档得到Document对象,Document对象代表整个XML文档
      Document document = builder.parse(new File("publication.xml"));
      //得到Dom树的根节点
      Element element = document.getDocumentElement();
      NodeList nodelist = element.getChildNodes(); //得到子节点列表
      getElement(nodelist); //用递归实现DOM树的遍历
   } catch(Exception e){
      e.printStackTrace();}
   }
public static void main(String[] args){
  try{
       //得到DOM解析器的工厂实例 
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       //从DOM工厂获得DOM解析器  
      DocumentBuilder builder = factory.newDocumentBuilder();
      //DOM解析器解析XML文档得到Document对象,Document对象代表整个XML文档
      Document document = builder.parse(new File("publication.xml"));
      //得到Dom树的根节点
      Element element = document.getDocumentElement();
      NodeList nodelist = element.getChildNodes(); //得到子节点列表
      getElement(nodelist); //用递归实现DOM树的遍历
   } catch(Exception e){
      e.printStackTrace();}
   }

Simple API for XML(简称SAX)是个循序存取XML的解析器API。
SAX以一个串流解析器的型式作用,拥有事件驱动 API。
优点:不用实现调入整个文档,占用资源少。尤其在嵌入式环境中。
Simple API for XML (SAX for short) is a parser API for sequential access to XML.SAX ACTS as a streaming parser with an event-driven API. Advantages: no need to implement the whole document, occupying less resources.Especially in embedded environments.

public static void main(String[] args){
  String fileName = "publication.xml";
try{
   ConfigParser handler = new ConfigParser();//将我们的解析器对象化
   SAXParserFactory factory = SAXParserFactory.newInstance();//获得SAX工厂对象
   factory.setNamespaceAware(false);//对 XML 名称空间的不支持 
   factory.setValidating(false);//解析文档时不验证文档 
   SAXParser parser = factory.newSAXParser();//获得SAX解析
   parser.parse(fileName, handler);//将解析器和解析对象联系起来并开始解析
       }
   catch(Exception e){
     e.printStackTrace();}  
 }
}
class ConfigParser extends DefaultHandler{
   private String temp;
   private Stack element =new Stack();
   private StringBuffer currentValue = new StringBuffer();
   public void startElement(String uri, String localName, String qName, Attributes attributes)    
              throws SAXException{  //接收元素开始的通知
          currentValue.delete(0, currentValue.length());              
          element.push(qName);
         } //读到结束标签会触发该方法
   public void endElement(String uri, String localName, String qName )throws SAXException{
          temp=(String)element.pop();
          if(temp.equals("Title"))
             System.out.println("Title:"+currentValue);
          if(temp.equals("Writer"))
             System.out.println("Writer:"+currentValue);
          if(temp.equals("PublishDate"))
             System.out.println("PublishDate:"+currentValue);
          }
   //此方法用来处理XML文件中字符串
   public void characters(char[] ch, int start, int length)throws SAXException{
          currentValue.append(ch, start, length);
}
}

四、使用Xpath读取指定的标签
http://www.w3school.com.cn/xpath/index.asp

第十章 EJB- SessionBean
一、*什么是EJB
企业级JavaBean(Enterprise JavaBean EJB)是一个用来构筑企业级应用的服务器端可被管理组件。EJB以一个标准方式自动处理了诸如数据持久化,事务集成,安全对策等不同应用的共有问题,使得软件开发人员可以专注于程序的特定需求而不再饱受那些非业务元素的困扰。
Enterprise javabeans EJB (Enterprise javabeans EJB) is a server-side managed component for building Enterprise applications.Ejbs automatically handle common problems in different applications such as data persistence, transaction integration, and security countermeasures in a standard way, allowing software developers to focus on the specific needs of the application without having to worry about non-business elements.
二、*JNDI
JNDI是 Java 命名与目录接口(Java Naming and Directory Interface)
JNDI指通过提供统一的Java API 访问不同的命名和目录服务。(Service Provider Interface)
JNDI is a Java Naming and Directory Interface.JNDI refers to access to different naming and directory services by providing a unified Java API.(the Service Provider Interface)
三、JNDI的应用
JNDI作用:
? 把名字和对象联系起来;
?提供一个工具,根据名字寻找资源;
?类似于文件系统。
使用JNDI:在程序中通过数据源名称引用数据源从而访问数据库!
Example1:通过JNDI访问MySQL数据库

Connection conn=null;  
try {  
Context ctx=new InitialContext();  
Object datasourceRef=ctx.lookup("MySqlDS"); //引用数据源  
DataSource ds=(Datasource)datasourceRef;  
conn=ds.getConnection();  
……
Example2: 通过JNDI获得JMS的连接工厂ConnectionFactory
Try{
    Properties  env = Properties();
     Context inictxt = new InitialContext(env);
     TopicConnectionFactory connFactory = (TopicConnectionFactory)
          inictxt.lookup("TTopicConnectionFactory");
     ……
 }

四、如何访问EJB组件
通过使用JNDI让客户使用对象的名称或属性来查找对象:

DirContext ctx = new InitialDirContext(hs);
//利用lookup查找返回指定DN的条目对象, LDAP目录记录的标识名(Distinguished Name,简称DN)
Persons pers =(Persons)ctx.lookup("uid=Jordan,ou=Bull,o=NBA");

要通过JNDI进行资源访问,我们必须设置初始化上下文的参数,主要是
设置JNDI驱动的类名(java.naming.factory.initial)和提供命名服务的URL(java.naming.provider.url)。
在这里插入图片描述

五、有状态会话Bean和无状态会话Bean
有状态会话 Bean :如:购物小车
有状态会话 Bean 是向业务进程提供服务的 Bean,它广泛分布于多个方法请求。
在方法调用期间,如果有状态会话 Bean 的状态改变,那么在接着的方法调用中,客户端会出现同样的状态。
有状态会话Bean的成员变量描述一个唯一的客户端-会话Bean的关联状态 。
有状态会话Bean使用激活(Activation)
在有状态会话 Bean 中,每个会话对象将委托 Bean 类的相同实例

无状态会话 Bean :如:发送邮件的EJB
对于无状态会话 Bean,它们不用保存客户端的状态,所以称为无状态。
在无状态会话 Bean 中,方法调用之间没有存储信息,因此在方法之间没有保留任何会话状态。
除了在方法调用期间,所有同一个无状态会话Bean实例是等价的,可以被容器分配给任一客户端。
无状态会话Bean使用对象池管理
在无状态会话 Bean 中,对象将委托任何未用的可用实例

六、会话Bean生命周期

在这里插入图片描述
在这里插入图片描述
七、定义一个SessionBean(EJB3.0)
stateless or stateful在这里插入图片描述

一、判断题

  1. Oracle Thin Driver 属于JDBC的本地API驱动类型。×
  2. ORM框架软件如Hibernate、MyBatis也是中间件软件。×
  3. CORBA是支持分布式的计算机编程语言。×
  4. IDL的模块定义module xxx相当于Java的包package xxx。√
  5. JavaRMI可以访问非Java的组件如COM组件。×
  6. BlobMessage和TextMessage都是JMS规范的消息类型。×
  7. CORBA服务是指那些有可能被应用程序使用的、与领域无关的公共服务对象。例如:CORBA目录服务中的名字服务。√
  8. This is correct在XML中是合法的。×
  9. 通过Http协议能够访问Java的 Web组件和EJB组件。×
  10. 消息中间件的Queue模式是指消息生产者把消息直接发送给消费者。×
    二、问答题
    bank.idl定义如下:
interface BANKAccount{
          enum account_kind{cheking, saving};
          readonly attribute float balance;
          attribute account_kind kind_of_account;
          void access(in string account, in string pin); };
module MeineBank {
	exception BankFehler { //异常定义
 		string info;
	};
                //基本账户
 	interface BasisKonto {
		readonly attribute long nummer; 
		double einzahlen ( in double betrag ) raises ( BankFehler )//存钱
	};
	
	//接口继承---支票账号
	interface GiroKonto : BasisKonto {
		double attribute dispoKredit;//信贷额度
	};
                //储蓄账号
             	interface SparKonto : BasisKonto {
		 double attribute zinssatz;//存款利率
	};

                //接口多重继承
	interface GiroSparKonto : SparKonto, GiroKonto {......};
}; 
  1. in的含义

<1>in,in属性说明了参数是从客户端传递给服务器程序。
<2>out,out属性表明参数京被返回给客户端程序。但是没有任何信息将从客户端程序传递给服务器程序,因此。服务器程序不能期望标有这种属性的参数包含任何有效的信息,相反,应该把它看成是未初始化的变量。注意:in和out可以同时使用。

写出Xpath表达式
1、channel的子元素/rss/channel/*
2、 sex= "female"的元素//@sex=”female”
3、所有价格>35的书名/rss/bookstore/book[price>35]/title
4、所有英文版的书名/rss/bookstore/book[@lang=’eng’]/title

消息中间件

定义

Message-oriented middleware (MOM) is software infrastructure supporting sending and receiving messages between distributed systems. MOM allows application modules to be distributed over heterogeneous platforms and reduces the complexity of developing applications that span multiple operating systems and network protocols. The middleware creates a distributed communications layer that insulates the application developer from the details of the various operating systems and network interfaces. APIs that extend across diverse platforms and networks are typically provided by MOM.

面向消息的中间件(MOM)是支持在分布式系统之间发送和接收消息的软件基础结构。 MOM允许应用程序模块分布在异构平台上,并降低开发跨多个操作系统和网络协议的应用程序的复杂性。 中间件创建分布式通信层,使应用程序开发人员与各种操作系统和网络接口的详细信息隔离开来。 跨越不同平台和网络的API通常由MOM提供。

为什么要使用消息中间件(消息中间件可以解决的问题)
  1. 系统解耦
  2. 异步调用
  3. 流量削峰(过载保护)
  4. 扩展性
  5. 消息的可靠性
    有些情况下,处理数据的过程会失败。除非数据被持久化,否则将造成丢失。消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险。许多消息队列所采用的”插入-获取-删除”范式中,在把一个消息从队列中删除之前,需要你的处理系统明确的指出该消息已经被处理完毕,从而确保你的数据被安全的保存直到你使用完毕。
    详细解释见下连接
    https://www.cnblogs.com/east7/p/10323391.html
    https://blog.csdn.net/wqc19920906/article/details/82193316
Topic 和 Queue 模式

消息生产者生产消息发送到queue中,然后消息消费者从queue中取出并且消费消息。
消息被消费以后,queue中不再存储,所以消息消费者不可能消费到已经被消费的消息。 Queue支持存在多个消费者,但是对一个消息而言,只会有一个消费者可以消费。

消息生产者(发布)将消息发布到topic中,同时有多个消息消费者(订阅)消费该消息。和点对点方式不同,发布到topic的消息会被所有订阅者消费。
queue实现了负载均衡,将producer生产的消息发送到消息队列中,由多个消费者消费。但一个消息只能被一个消费者接受,当没有消费者可用时,这个消息会被保存直到有一个可用的消费者。
topic实现了发布和订阅,当你发布一个消息,所有订阅这个topic的服务都能得到这个消息,所以从1到N个订阅者都能得到一个消息的拷贝。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值