Flex与J2eeBlazeDS框架译文.doc_第1页
Flex与J2eeBlazeDS框架译文.doc_第2页
Flex与J2eeBlazeDS框架译文.doc_第3页
Flex与J2eeBlazeDS框架译文.doc_第4页
Flex与J2eeBlazeDS框架译文.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Chapter 3: BlazeDS architecture第三章 BlazeDS 结构BlazeDS客户端结构Flex组件以下是Flex组件与BlazeDS Server 交互的 RemoteObject HTTPService WebService Producer Consumer这些组件包含在Flex SDK 的 rpc.swc 库中虽然RemoteObject, Producer, and Consumer 组件包含在SDK中,但它们需要通过信息传达室送与服务器交互;BlazeDS和LiveCycle两个都是这样服务器,一个FLEX应用程序能正确向HttpService 或 WEB服务执行远程调用,BlazeDS与LiveCycle作为中间层通过BlazeDS代理服务利于解决许多问题;客户端组件集合与BlazeDS Server通过发送与接收正确类型信息进行运作;传输通道与通道集合A Flex component uses a channel to communicate with a BlazeDS server. A channel set contains channels;Flex组件使用通道与BlazeDS进行通讯,一个通道包含多个渠道集 Its primary function is to provide connectivity between the Flex client and the BlazeDS server.它是主要功能提供Flex客户端与BlazeDS进行连接的 A channel set containschannels ordered by preference. 一个通道包含多个优先选择排好序的通道集;The Flex component tries to connect to the first channel in the channel set and inthe case where a connection cannot be established falls back to the next channel in the list. Flex组件常试连接通道集的第一个通道,当一个连接不确定时,跳到通道列表的下一个通道;The Flex componentcontinues to go through the list of channels in the order in which they are specified until a connection can be establishedover one of the channels or the list of channels is exhausted.Flex组件连续通过通道集列表中下达指令,直到确定连接有用,超过一个或整个通道集耗尽Channels encapsulate the connection behavior between the Flex components and the BlazeDS server.Flex组件与BlazeDS Server通过通道集压宿后进行连接Conceptually,channels are a level below the Flex components and they handle the communication between the Flex client and theBlazeDS server. 通道是一个建立在Flex组件之上,它们负责在Flex客户端与BlazeDS Server之前通讯;They communicate with their corresponding endpoints on the BlazeDS server; 它们通讯是通过它们相应设置在BlazeDS Server 的”Endpoints(端点)“for more information about endpoints, see “Endpoints” on page 29.更多关于Endpoints信息看“Endpoints” 在29页Flex clients can use different channel types such as the AMFChannel and HTTPChannel. Channel selection depends on a number of factors, Flex客户端可以使用不同的通道类型,像“AMFChannel,HTTPChannel”通道选择取决于若干因素including the type of application you are building. If non-binary data transfer is required,you would use the HTTPChannel, which uses a non-binary format called AMFX (AMF in XML). For more information about channels, see “Channels and endpoints” on page 38.如果在应用程不包括二进制数据传达传输,你可以使用“HttpChannel”,没有二进制传达送的格式叫“AMFX (AMF IN XML)”更多信息看 “Channels and Endpoints Page 38”Message信息All communication between Flex client components and BlazeDS is performed with messages. 所有通讯通过Flex客户端组件与BlazeDS 通过信息传送执行;Flex components use several message types to communicate with their corresponding services in BlazeDS. Flex组件使用多个相应信息类型在BlazeDS中进行通讯.All messages have client-side(ActionScript) implementations and server-side (Java) implementations because the messages are serialized and deserialized on both the client and the server. 所有信息有客户端(ActionScript)执行序列化和服务器边的(JAVA)执行反序列化.You can also create messages directly in Java and have those messagesdelivered to clients using the server push API.你可以直接用JAVA创建信息并且将这些信息交负到客户端使用.Some message types, such as AcknowledgeMessage and CommandMessage, are used across different Flex components and BlazeDS services. 一些信息类型,像AcknowledgeMessage and CommandMessage,使用不同的Flex组件和BlazeDS的服务Other message types are used by specific Flex components and BlazeDSservices. 其它信息类型使用指定FLEX组件与BlazeDS服务。For example, to have a Producer component send a message to subscribed Consumer components, you create a message of type AsyncMessage and pass it to the send() method of the Producer component.例如,使用一个“Producer”组件发送一条信息认购消费者组件,你创建信息类型为“AsyncMessage”并且将它交给“Producer”组件的 “send()”方法In other situations, you do not write code for constructing and sending messages.其它情况,你不必写代码去构建与发送信息; For example, you simply use a RemoteObject component to call the remote method from the Flex application. 例如,你在应用程序中,简单使用”RemoteObject”构成调用远程方法。The RemoteObject component creates a RemotingMessage to encapsulate the RemoteObject call. “RemoteObject”组件创建一个远程信息放到压宿包中,RemoteObject进行调用。In response it receives an AcknowledgeMessage from the server. 服务器回应时,RemoteObject接收 AcknowledgeMessage 信息.The AcknowledgeMessage is encapsulated in a ResultEvent in the Flex application.AcknowledgeMessage信息压宿到ResultEvent事件中。Sometimes you must create a message to send to the server. For example, you could send a message by creating an AsyncMessage and passing it to a Producer.有时候你必需创建信息发送到服务器,例如:你可以发送“AsyncMessage”信息并且通过 “Producer”组件来传送。BlazeDS uses two patterns for sending and receiving messages: the request/reply pattern and the publish/subscribe pattern. BlazeDS 使用了两个模式进行发送与接收信息,“request/reply pattern”与 “publish/subscribe pattern”请求/应答模式例子: /guozhanxian/archive/2007/01/21/1489306.aspx发布/订阅模式RemoteObject, HTTPService, and WebService components use the request/reply message pattern, in which the Flex component makes a request and receives a reply to that request. RemoteObject, HTTPService, and WebService组件使用请求/应答模式进行信息传送,那个组件发送请求,它同时进行接收。Producer and Consumer components use the publish/subscribe message pattern. Producer and Consumer组件使用发布与订阅模式In this pattern, the Producer publishes a message to a destination defined on the BlazeDS server. All Consumers subscribed to that destination receive the message.这个模式,Producer组件向目的BlazeDS服务器发布信息,所有订阅者在目的地接收信息;BlazeDS server architectureBlazeDS服务器端结构The BlazeDS server is contained in a J2EE web application. BlazeDS服务是包含在J2EE WEB应用程序中。A Flex client makes a request over a channel and the request is routed to an endpoint on the BlazeDS server. Flex客户端发送一个请求,透过通道发送到BlazeDS Server终点.From the endpoint, the request is routed through a chain of Java objects that includes the MessageBroker object, a service object, a destination object, and finally an adapterobject.通过”Endpoint”终点,请求发送包含在MessageBroker对像中的Java对像链,一个服务对像,一个目的对像,还有一个适配器对像.The adapter fulfills the request either locally, or by contacting a backend system or a remote server such as Java Message Service (JMS) server.适配器满足本地请求,或者负责接触后端系统与远程服务,像Java Message Service(JMS)The following illustration shows the BlazeDS server architecture:以下图像显示BlazeDS服务架构:Endpoints终点BlazeDS servlet-based endpoints are inside the J2EE servlet container, which means that the servlet handles the I/O and HTTP sessions for the endpoints. BlazeDS servlet-based endpoints 是在J2EE servlet 容器里, servlet负责I/O输入输出与HTTP sessions控制。Servlet-based endpoints are bootstrapped by the MessageBrokerServlet,which is configured in the web.xml file of the web application. Servlet-based endpoints 由MessageBrokerServlet类处理,配置在应用程序的web.xml中.In addition to the MessageBrokerServlet, an HTTP session listener is registered with the J2EE server in the web applications web.xml file so that BlazeDS has HTTP session attribute and binding listener support.除了MessageBrokerServlet之外,HTTP session 监听器是登记在J2EE应用程序的web.xml文件,BlazeDS 的session属性可能通过监听器提供BlazeDS Flex client applications use channels to communicate with BlazeDS endpoints. BlazeDS Flex客户端应用程序使用通道来与BlazeDS endpoints进行通信。There is a mapping between the channels on the client and the endpoints on the server. 在客户端与服务器端之间通道是有映射的。It is important that the channel and the endpoint use the same message format. 通道与终点使用用同样的信息格式它是非常重要的。A channel that uses the AMF message format, such as the AMFChannel, must be paired withan endpoint that also uses the AMF message format, such as the AMFEndpoint.就像AMFChannel使用AMF信息格式的通道,, Endpoint与信息必需是配搭使用AMF格式,如AMFEndpoint. A channel that uses the AMFX message format such as the HTTPChannel cannot be paired with an endpoint that uses the AMF message format.就像HTTPChannel使用AMFX信息格式的通道,不能搭配使用AMF格式的endpoint与message.Also, a channel that uses streaming must be paired with an endpoint that uses streaming.同样,一个通道使用流,必需搭配使用流。You configure endpoints in the services-config.xml file in the WEB-INF/flex directory of your BlazeDS web application.你可以在WEB-INF/flex 目录下services-config.xml中配置你的endpointsFor more information about endpoints, see “Channels and endpoints” on page 38.更多信息请查阅38页。MessageBroker消息代理The MessageBroker is responsible for routing messages to services and is at the core of BlazeDS on the server.MessageBroker是为信息发送到核心的BlazeDS服务的。After an endpoint initially processes the request, it extracts the message from the request and passes it to the Message-Broker. 经过初步端点处理请求,它从请求中提取的信息并将其传递给了消息代理The MessageBroker inspects the messages destination and passes the message to its intended service. 消息代理会检查信息目的地并且把消息传递到预定的服务.If the destination is protected by a security constraint, the MessageBroker runs the authentication and authorization checks before passing the message along (see “Configuring security” on page 158). 如果目的地受安全保护约束,在信息传递前,消息代理执行授权认可验证, 配置安全设置查阅Page158You configure the MessageBroker in the services-config.xml file in he WEB-INF/flex directory of your BlazeDS web application.在WEB-INF/flex目录下services-config.xml文件配置MessageBrokerServices and destinations服务与目的地Services and destinations are the next links in the message processing chain in the BlazeDS server. 服务与目的地是BlazeDS服务中下一个连接信息过程链.The system includes four services and their corresponding destinations BlazeDS:系统包含了四个服务与他们相应的通讯目持地 RemotingService and RemotingDestination HTPProxyService and HTTPProxyDestination MessageService and MessageDestinationServices are the targets of messages from client-side Flex components. 服务目的地是从客户端的Flex组件指定。Think of destinations as instances of a service configured in a certain way. 作为一个服务配置的情况下,目的地的思考以某种方式.For example, a RemoteObject component is used on the Flex client to communicate with the RemotingService. 例如,在Flex客户端使用一个RemoteObject组件与远程服务进行通信。In the RemoteObject component, you must specify a destination id property that refers to a remoting destination with certain properties, such as the class you want to invoke methods on. 在RemoteObject组件中,你必需指定指定destination属性,确定远程目的地中某一个属性,像调用某些类的方法。The mapping between client-side Flex components and BlazeDS services is as follows:以下列表是客户端组件与BlazeDS服务相应对像。 HTTPService and WebService communicate with HTTPProxyService/HTTPProxyDestination RemoteObject communicates with RemotingService/RemotingDestination Producer and Consumer communicate with MessageService/MessageDestinationYou can configure services and their destinations in the services-config.xml file, but it is best practice to put them in separate files as follows:你可以在services-config.xml文件中配置他们的地址(目的地),但是最好办法是分别在指定文件上配置。如下: RemotingService configured in the remoting-config.xml file HTTPProxyService configured in the proxy-config.xml file MessageService configured in the messaging-config.xml fileFor more information on RPC services (HTTPProxy Service and RemotingService) and MessageService, see thefollowing topics:更多关于RPC服务使用请看以下提示: “Using HTTP and web services” on page 73 “Using the Remoting Service” on page 110 “Using the Messaging Service” on page 122Adapters and assemblers适配器和装配Adapters, and optionally assemblers, are the last link in the message processing chain. 适配器与选择装配,是最后一个环节的信息处理链When a message arrives at the correct destination, it is passed to an adapter that fulfills the request either locally or by contacting a backend system or a remote server such as a JMS server. 当信息到达正确目的地后,它会传递给适配器执行请求在本地或后台系统或远程服务,像JMS服务一样.BlazeDS uses the following mappings between destinations and adapters/assemblers:以下是BlazeDS的目的地与适配器/装配器之前对应关系. RemotingDestination uses JavaAdapter HTTPProxyDestination uses HTTPProxyAdapter or SOAPAdapter MessageDestination uses ActionScriptAdapter or JMSAdapterAdapters and assemblers are configured along with their corresponding destinations in the same configuration files.适配器与装配配置是在与之相对应的目的地配文件中。Although the BlazeDS server comes with a rich set of adapters and assemblers to communicate with differentsystems, custom adapters and assemblers can be plugged into the BlazeDS server. 虽然BlazeDS服务器伴随着一套装配的适配与不同系统之前通信,自定义的装配适配器能插入BlazeDS服务器Similarly, you do not have to create all destinations in configuration files, but instead you can create them dynamically at server startup or when the server is running; 同样,你不需要在配置文件中创建所有destinations,你可以在服务器开起来或正在运行时动态创建它们。for more information, see “Run-time configuration” on page 174.For information about the BlazeDS server-side classes, see the Javadoc API documentation.About configuration files关于配置文件You configure BlazeDS in the services-config.xml file. 你通过services-conig.xml配置BlazeDS.The default location of this file is the WEB-INF/flex directory of your BlazeDS web application. You can set this location in the configuration for the MessageBrokerServlet in the WEB-INF/web.xml file.配置文件默认在BlazeDS应用程序的WEB-INF/flex目录下,你可以设置MessageBrokerServlet,将这个路径配置在WEB-INF/web.xml文件中。You can include files that contain service definitions by reference in the services-config.xml file. 您可以引入文件,其中包含了在 service - config.xml文件中定义的参考咨询服务。Your BlazeDS installation includes the Remoting Service, Proxy Service, and Message Service by reference.你的BlazeDS安装包含远程服务,代理服务和消息服务。The following table describes the typical setup of the configuration files. 以下表格描述典型的安装配置文件.Commented versions of these files areavailable in the resources/config directory of the BlazeDS installation.services-config.xmlThe top-level BlazeDS configuration file. This file usually contains security constraint definitions,channel definitions, and logging settings that each of the services can use. It can contain servicedefinitions inline or include them by reference. Generally, the services are defined in theremoting-config.xml, proxy-config.xml, and messaging-config.xml.最顶层配置文件.这文定义安全约束,通道,日志设定,它可以包含服务定义内联或引用它们,一般,服务定义在remoting-config.xml, proxy-config.xml, and messaging-config.xmlremoting-config.xmlThe Remoting Service configuration file, which defines Remoting Service destinations forworking with remote objects.For information about configuring the Remoting Service, see “Using the Remoting Service” onpage 110.定义远程服务对像proxy-config.xmlThe Proxy Service configuration file, which defines Proxy Service destinations for working withweb services and HTTP services (REST services).For information about configuring the Proxy Service, see “Using HTTP and web services” onpage 73.代理服务配置文件,定义web services与Http Servicemessaging-config.xmlThe Messaging Service configuration file, which defines Messaging Service destinations forperforming publish subscribe messaging.For information about configuring the Messaging Service, see “Using the Messaging Service” onpage 122.消息服务配置文件,为发布与订阅服务定义消息服务When you include a file by reference, the content of the referenced file must conform to the appropriate XMLstructure for the service. 当你需要包含引用时,文件内容必需确认是XML结构。The file-path value is relative to the location of the services-config.xml file. The followingexample shows service definitions included by reference:文件路径值与services-config.xml相对的,如下:Configuration tokens配置标记The configuration files sometimes contain special and server.port tokens. 配置文件某些时候包含特殊的标记 和 server.port 标记。These tokens are replaced with server name and port values based on the URL from which the SWF file is served when it is accessed through a web browser from a web server. 这些标记可以替换为浏览器访问的URL,名称与端口值。Similarly, a special context.root token is replaced with the actual context root of a web application.相同,指定context.root标记可以替换为应用程序的目录名称。Note: If you use server tokens in a configuration file for an Adobe AIR application and you compile using that file, the application will not be able to connect to the server.如果你使用服务器的标识来给Adobe AIR应用程序配置文件,编译时使用那个文件,则应用程序将会不能连接服务器。(在AIR中,配置文件不用改,用上相对路径)You can avoid this issue by configuring channels in ActionScript rather than in a configuration file (see “Channels and endpoints” on page 38).你可以逼免在配置ActionScript通道产生这些这些问题。You can also use custom run-time tokens in service configuration files; for example, messaging-channel and my.token. 你可以同样在配置文件中使用自定义运行坏境标记;例如messaging-channel and my.token.You specify values for these tokens in Java Virtual Machine (JVM) options.你可以在Java虚拟主机中选项,给这些标记设置值。The server reads these JVM options to determine what values are defined for them, and replaces the tokens with the specified values. 服务器上JVM可以读取这些选项值。If you have a custom token for which a value cannot be found, an error is thrown. 如果你有定义自定义的标识,并且没有设置则会抛出异常.Because , server.port, and context.root are special tokens, no errors occur when these tokens are not specified in JVM options.因为, server.port, 与 context.root是特殊的标签,如果没有设置值是不会产生错误.How you define JVM options depends on the application server you use. 你如何定义JVM选项取决于您使用的应用服务器.For example, in Apache Tomcat, you can define an environment variable JAVA_OPTS that contains tokens and their values, as this code snippet shows: JAVA_OPTS=-Dmessaging.channel=my-amf -Dmy.token=myValue。例如:在Tomcat里,你能定义环境变量JAVA_OPTS选项,包含标签与它们值,像这小片代码: JAVA_OPTS=-Dmessaging.channel=my-amf -Dmy.token=myValue。Configuration elements配置无素The following table describes the XML elements of the services-config.xml file. The root element is the servicesconfigelement.XML elementDescriptionservicesContains definitions of individual data services or references to other XML filesthat contain servi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论