2015年-11月-13日第一章INTRO1.概念ii.一类独立的系统软件和服务程序iii. A class of standalone system-level software and services procedures iv.在操作系统的顶部v.Working on the top of OSvi.管理计算机资源和网络vii.Managing computational resources and network communicationsviii.支持分布式通信ix.Supporting distributed appsb)功能i.在异构的网络环境中,涉及到跨连通性和可操作问题中ii.提供统一的协议和接口iii.Providing standardized interfaces and protocolsiv.隐藏实现细节v.Hiding implementation detailsvi.提高程序的可移植性vii.Increasing the portability of appsviii.放置于操作系统和数据库管理系统的顶部ix.为高级应用的开发和执行提供环境x.Providing environments for the execution and development of higher-level appsxi.协助软件工程师灵活高效地开发和集成复杂的分布式软件xii.Assisting software engineers in flexibly and efficiently developing and integrating complex distributed softwarec)中间件发展的主要因素i.隐藏异构型Hiding heterogeneity1.硬件异构hardware heterogeneity2.操作系统异构OS heterogeneity3.数据库异构database heterogeneityii.支持可操作性supporting inter-operability1.不同的平台different platforms2.不同的网络协议different network protocols3.不同的通信机制different communication mechanismsiii.提高软件的复用率improving efficiency and quality of software development d)主要类别i.远程过程调用中间件RPC remote procedure call middlewareii.对象请求代理中间件ORB object request brokers middlewareiii.面向信息中间件MOM message-oriented middlewareiv.数据库访问中间件DAM database access middlewarev.事务处理中间件TPM transaction processing middleware第二章RMIa)对象请求代理ORBi.提供一个框架,使得远程对象可以在网络中以同样的方式使用在网络中的本地对象ii.Providing a framework where remote object can use local objects in the same way over the networkiii.当对象在客户端和服务器之间传递时,提供功能的编组和解组的功能iv.Providing functionalities for marshalling and unmarshaling when objects are transmitted between clients and servers.v.客户端和服务器之间的传输隐藏实现的细节,这使得开发人员能够有效地实现分布式应用程序,而无需面对复杂的底层操作系统和网络通信vi.Hiding the implementation details,which enable developers to implement distributed apps efficiently without facing the complex underlying operatingsystems and network communicationsb)JAVA RMI 的概述i.用java编写分布式对象ii.Writing distributed objects using javaiii.直接用java对象来为分布式计算机建模iv.Simple and direct model for distributed computation with java objectsv.以java为中心,由此带来了安全性和分布式计算的可移植性vi.Centered around java, thus bringing the power of Java Safety and portability to distributed computingvii.行为可以被转移动viii.Behavior can be removedix.通过JNI可以链接到现有的遗留系统x.Connected existed legacy system by JNIxi.通过JDBC可以链接到关系数据库xii.Connected relational database by JDBCc)优点i.面向对象OO1.全部的对象可以作为参数和返回值2.All objects can be arguments and return valuesii.可移动性行为mobile behavior1.类的实现可以被移植2.The implementations of class can be movediii.设计模式design patterns1.传递性对象确保了面向对象技术的全功率2.Passing objects ensure the full power of OO techsiv.安全Secure1.基于JAVA的安全机制:安全经理2.Based on JAVA security mechanisms security managerd)次优点i.十分容易开发,使用,维护ii.Easy to write, use and maintainiii.可以与现存的遗留系统链接can connect with existed legacy system1.RMI/JNI,RMI/JDBCiv.开发一次,可以在任何地方运行write once, can be use anywhere1.100%移植到任何JVM 100%portable to any JVMv.分布式垃圾收集distributed garbage collectionvi.并行计算parallel computing1.多线程,并行处理MUTI-thread ,concurrent processinge)架构architecturei.存根stub1.编组参数,发送调用2.Marshaling arguments, sending invocationii.骨骼skeleton1.解封参数,调用服务器来实现2.Unmarshaling arguments, invoking server’s implementationf)RMI的分布式应用i.定位远程对象locate remote objectsii.与远程对象通信communicate with remote objectsiii.为被传递的对象加载类定义load definitionof classes that are passed aroundg)远程接口,对象和方法remote interface,objectsand methodsi.通过实现一个具有以下特点的远程接口来实现对象远程化An objectsbecomesremote by implementing a remote interface with followingcharacteristics1.一个远程接口扩展了接口one remote interface extends an interfacea)Java.rmi.remote2.接口的每一个方法都有事先声明every methods of the interface hasbeen declareda)Java.rmi.RemoteException in its throws clauseh)主要步骤main stepsi.定义远程接口define the remote interface1.指明可以远程调用的方法specifying the methods that can be invokedremotelyii.实施远程对象implementing the remote objects1.可能包括本地接口/方法的实现may include the implementation of localinterface/methodiii.客户实现implementing the client1.在远程接口定义后的任何时间都可以被实现can be implementedanytime when the remote interface has been defined第三章JMSa)面向消息中间件MOMi.在异构平台上发送/接收分布式应用软件/组件之间的消息ii.Sending/receiving messages between distributed apps/components over the heterogeneous platforms1.支持异步调用2.Supporting asynchronous callsiii.创建一个分布式通信层iv.Create a distribute communication layer1.避免应用开发者接触来自不同系统和网络接口的细节2.Insulating app developers from the details about different OS andnetwork interfacesv.在不同平台和网络上的API通常是MOM提供的vi.The APIS from different platforms and network are provided by MOMb)比较i.MOM1.异步通信2.Asynchronous communication3.组件松散耦合4.Loosely-coupled componentsii.RPC/ORB1.同步通信2.Synchronous communication3.组件紧密耦合4.Tightly-coupled componentsc)MOM 标准i.历史上,缺乏MOM的准确标准ii.There was a lack of standards in the history.iii.高级消息队列协议AMQPiv.Advanced Message Queuing Protocolv.数据分发服务DDSvi.Data Distribution Servicevii.可扩展消息和存在协议XXMPviii.extensible Messaging and Presence Protocolix.Java消息服务的JAVA EEx.Java Message Service by JAVAEE1.由大多数MOM供应商实施,旨在隐藏特定的MOM API实现方法2.Implemented by most MOM vendors and aims to hide the particularMOM API implementationsd)JavaMessage Servicei.一种JAVA API接口,允许应用程序创建发送接收读取消息ii. A java API that allows apps to create,send,receive and read messagesiii.定义一组通用接口和关联用语iv.Defines a set of common interface and associated semanticsv.通过JMS的提供者,力争最大力度的提高JMS应用程序的可移植性vi.Try the best to improve the portability of JMS apps across JMS providers vii.使得通信变得松散耦合的,异步的,可靠的viii.Enabling communication that is loosely coupled, asynchronous, and reliable e)当用JMS的时候i.提供者希望该组件不依赖与其他组件的接口信息,因此组件可以很容易地被替换ii.Providers hope the components don’trely on other components’message, so components can be easily replacediii.提供者希望该应用程序运行时其他组件也同时运行iv.Providers wants the apps to run whether or not all components are up and running simultaneouslyv.应用业务模式允许组件将信息发送到另一个组件,并继续操作而不用即时响应vi.Application business model allows components send message to another components and to continue to operate without receiving an immediateresponsef)信息传递方式i.点对点传送消息方式Point to point messaging style1.每个消息都是针对特定队列的2.Each message is addressed to a specific queue3.队列将保留所有发送的消息,直到他们被消耗或者过期4.The queue will retain all the messages that have been sent until theyare consumed or expire.5.每一条消息都只有一个消费者6.Every message has one consumerii.发布/订阅消息方式Publish/subscribe messaging style1.客户端可以将信息发到一个主题里2.The client can send a message to a topic3.出版社和订阅者可以动态的发布或者订阅主题4.Publisher and subscriber can dynamically publish or subscribe to thetopic.5.当且仅当消息被发送给订阅服务器后,主题才会保留信息6.Topic will retain the messages only when messages have been sent tothe subscribers7.每一条信息都可以有多个消费者8.Each message has multiple consumers9.当一个客户端创建了一个主题后,另一个订阅了相应主题的客户端才可以消费已发送的信息,并且消费者必须要保持活跃来消费信息10.After a client create a topic, another client which has subscribed thetopic can consume messages that have been sent, and the consumermust continue to be active in order for it to consume messages.g)消息消费i.同步Synchronously1.消费者通过调用消息接收方法来获取消息的目的地2.Consumer fetches the message from the destination by calling thereceive method3.如果消息没有在指定时间内到达,该接收方法会阻止消息进入4.The receive method can block until a message arrives or can time out ifa message dose not arrive within a specified time limitii.异步Asynchronously1.客户端可以注册一个消息监听器2.The client can register a message listener with a consumer3.当消息到达目的地时,JMS的提供者通过调用监听器的onMessage方法来提供信息4.When message arrives to the destination,the provider of JMS deliverthe message by calling the listener’s onMessage methodh)JMS元素i.JMS提供者:一个JMS接口的实现ii.JMS provider: an implementation of the JMS interfaceiii.JMS客户端:一个应用或者过程,可以生产/接收消息iv.JMS client:an application or process that can produce/receive messages v.JMS提供者/出版者:创建/发送消息的客户端vi.JMS provider/publisher: a client that can create/send messagesvii.JMS消费者:接收消息的客户端viii.JMS consumer : a client that can receive messagesix.JMS消息:包含数据的对象,在客户端之间转移x.JMS message : an object including data and transferred between JMS clientsxi.JMS队列:一个包含着已经被发送出去并且等待被接收的信息(只有一个消费者)中转区xii.JMS queue: a queue that include messages which have been sent andwaiting to be readxiii.JMS主题:一个发送信息给多个订阅服务器的初版发行机构xiv.JMS Topic: a distribution mechanism for publishing messages that are delivered to multiple subscribersi)JMS应用程序的基本构造块JMS application’s basic building blocksi.管理对象:连接工厂和目的地ii.Administered objects: connection factories and destinationsiii.链接iv.Connectionsv.会议vi.Sessionsvii.消息生产者viii.Message providerix.消息消费者x.Message consumerxi.消息xii.Messagej)JMS信息类型第四章JDBCa)Introi.一套为了建立JAVA编程语言和更大范围数据库之间独立性数据库连接的标准JAVA API 接口b)框架c)组件i.DriverManagerii.Driveriii.Connectioniv.Statementv.ResultSetvi.SQLexceptiond)JDBC功能i.创造一个数据库连接ii.产生SQL声明iii.在数据库中执行SQL语句iv.查看修改产生的记录e)生成一个简单的JDBC应用i.导入包1.导入数据库连接编程需要的JDBC类的包2.Importjava. Sql .*;ii.注册JDBCdriver1.初始化一个driver,来建立一个与数据库联系的通信通道2.Class.forName(“com.mysql,jdbc,driver”);iii.打开链接1.创造一个链接对象,代表着与数据库的物理连接2.Static final string user = ”username”;3.Static final string pass = ”password”;4.Conn=DriverManager.getConnection(DB_er,pass); iv.执行语句1.为了建造并提交SQL说明给数据库,使用声明或者准备声明2.Stmt=conn.createStatement();3.String sql;4.Sql = “SELECT id, name, hometown FROM t_student”;5.ResultsSetrs = stmt.executeQuery(sql);6.对更新,插入,删除进行声明7.Stmt = conn.createStatement();8.String sql;9.Sql = “DELETE FROM t_student where id=1”;10.Intnum = stmt.executeUpdate(sql);v.从结果中提取数据1.用resultSet.getXXX() 从结果中提取数据vi.清空环境f)数据类型g)执行SQL语句i.发送查询语句给数据库ii.发送更新语句给数据库第五章JTAa)数据库事务i.原子性1.每一笔交易都是全部或者无ii.一致性1.使得数据库从一个状态到另一个状态iii.隔离性iv.耐久性1.一旦交易已经被提交了,那么它将继续保持状态,即时断电,系统崩溃或者发生错误b)2PC两段提交协议i.一种分布式算法,该算法能协调所有参与分布式原子事务的过程,如是否提交/终止/滚回事务操作ii.假设1.一个节点被指定为协调器,其余节点被指定为队列2.在每个节点上有一个写前记录的稳定存储3.没有节点会永远崩溃4.在日志记录中的数据将不会在崩溃中丢失或者损坏5.任意两个节点可以通信c)2PC的基本算法i.提交申请阶段(投票阶段)1.协调器将发送一个查询来提交所有队列信息,并且等待它已收到来自所有队列的答复2.队列处理事务,直至达到它们被要求的点上,它们将各自写一个日志来罗列未完成的事务和重新再做的事务3.如果队列动作成功,那么每一个队列将回复同意信息;如果队列动作失败,将会提交终止信息(投票不,不提交)ii.允许阶段(完成阶段)1.成功:如果协调员收到了一份同意信息,来自于所有处于提交请求阶段的队列a)协调员向所有的队列发送一个提交报告b)每个队列完成他们指定的操作,解锁所有的资源c)每个队列向协调器发送一个确认d)协调器在确定到2.失败:如果在提交阶段收到任何来自于队列的否决投票或者协调器超时a)协调员向所有队列发送一个滚回信息b)每个队列使用undo日志进行交易撤销,并且释放在交易过程中所持有的资源和锁c)当所有的确认都被收到时,协调者将撤销交易d)X/Open XAi.一组为了分布式事务处理由开放组织产生的事务规范ii.指明事务管理器将如何对不同的放入一个原子交易的数据存储执行滚回操作,并执行2pc协议iii.在一种事务协作中,允许许多资源来参与到一个单一的,协调的,原子的更新操作中iv.XA规范描述了一个资源管理器应该做什么才能支持事务性访问,遵循这个规范的资源管理器叫做XA兼容e)XA事务i.一种使用全球事务的应用,设计一个或者多个资源管理者和一个交易经理ii.资源管理器提供了访问交易资源的权限iii.交易经理协调全球事务中的部分事务iv.在全球范围内的个别交易是全球交易的分支f)Java事务性APIi.在JAVA环境下,确保分布式事务可以在多重X/开放式XA资源下进行g)JTA构架i.一个事务管理器/事务处理器来协调事务,通过多重资源,比如数据库和消息队列ii.每一个资源都有他们自己的资源管理者,通常都有自己的资源管理程序来处理资源iii.资源管理器允许事务处理器去协调一个分布式事务,在他自己和其他资源管理器之间iv.应用程序通过和TP监视器来开始,提交或者滚回事务v.JTA框架要求,每一个资源管理器一定要实现javax.transaction.xa.XAResource接口以供TP监视器管理。