服务端FlexClient、MessageClient、FlexSession类的实例代表了Flex应用和服务端的连接。你可以使用这些对象管理FLEX应用程序和服务端的同步。
FlexClient, MessageClient, and FlexSession objects
FlexClient
每一个MXML或者AS的Flex应用都被编译进SWF文件。当SWF文件和Blazeds服务通信的时候,一个flex.message.client.FlexClient对象就被创建,并在服务端代表这个SWF文件。SWF文件和FlexClient实例具有一对一的映射关系。Blazeds服务端为每个FlexClient实例生成一个唯一的标识id。在客户端也有一个单例类mx.message.FlexClient,用于存储这个唯一的FlexClient Id。
MessageClient
如果某个Flex应用程序含有一个订阅组件(flex.message.Consumer),服务端就会创建一个相应的flex.messaging.MessageClient实例来代表这个订阅者的发布者。每个MessageClient都有一个唯一的clientId,可以自动由Blazeds服务端生成,也可以在调用Consumer.subscribe()方法之前指定这个Consumer.clientId属性。
FlexSession
FlexSession对象代表在Flex程序和Blazeds服务之间的连接。它的生命周期基于通道和端点使用的底层协议。如果是基于HTTP的通道,例如AMFChannel或者HTTPChannel,在Blazeds服务端就是浏览器范围。如果它连接的端点是一个基于servlet的端点,那么这个HTTP session是基于J2EE HttpSession 对象。
三者之间的关系
一个FlexObject对象可以拥有多个FlexSession实例,这取决于Flex应用使用的通道数。例如,一个程序使用了一个HTTPChannel,那么在Blazeds服务端一个FlexSession代表这个HTTP session就会被创建。
一个FlexSession也可以拥有一个或多个FlexClient和它关联。例如,a SWF file that uses an
HTTPChannel is opened in two tabs,在BlazeDS服务端2个FlexClient实例被创建(一个SWF文件一个),但是只有一个FlexSession,因为两个tab共享同一个HTTP session。
每个订阅组件都会创建MessageClient。每一个MessageClient都会和一个FlexClient以及一个FlexClient关联。
关于三者的监听器
BlazeDS服务端提供了下列监听器,来让你根据自己的逻辑来创建、销毁、以及改变三者的状态。
FlexClientListener
|
|
FlexClientAttributeListener
|
|
FlexClientBindingListener
|
|
FlexSessionListener
|
|
FlexSessionAttributeListener
|
|
FlexSessionBindingListener
|
|
MessageClientListener
|
|
数据序列化
AS对象转换为Java对象
Java对象转换为AS对象
// Product.as
package samples.externalizable {
import flash.utils.IExternalizable;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
[RemoteClass(alias="samples.externalizable.Product")]
public class Product implements IExternalizable {
public function Product(name:String=null) {
this.name = name;
}
public var id:int;
public var name:String;
public var properties:Object;
public var price:Number;
public function readExternal(input:IDataInput):void {
name = input.readObject() as String;
properties = input.readObject();
price = input.readFloat();
}
public function writeExternal(output:IDataOutput):void {
output.writeObject(name);
output.writeObject(properties);
output.writeFloat(price);
}
}
}
// Product.java
package samples.externalizable;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Map;
public class Product implements Externalizable {
private String inventoryId;
public String name;
public Map properties;
public float price;
public Product(){
}
public String getInventoryId() {
return inventoryId;
}
public void setInventoryId(String inventoryId) {
if (inventoryId != null && inventoryId.startsWith("X")){
this.inventoryId = inventoryId;
}else{
throw new IllegalArgumentException("3rd party product
inventory identities must start with 'X'");
}
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
name = (String)in.readObject();
properties = (Map)in.readObject();
price = in.readFloat();
setInventoryId(lookupInventoryId(name, price));
}
public void writeExternal(ObjectOutput out) throws IOException {
// Write out the client properties from the server representation
out.writeObject(name);
out.writeObject(properties);
out.writeFloat(price);
}
private static String lookupInventoryId(String name, float price) {
String inventoryId = "X" + name + Math.rint(price);
return inventoryId;
}
}
- 大小: 42.8 KB
- 大小: 115 KB
- 大小: 67.6 KB
- 大小: 159.8 KB
- 大小: 40.1 KB
- 大小: 42.8 KB
分享到:
相关推荐
blazeds-bin-3.3.0.22497.zip
BlazeDS是一个基于服务器的Java远程调用(remoting)和Web消息传递(messaging)技术,使得后台的Java应用程序和运行在浏览器上的Flex应用程序能够相互通信。
blazeds-turnkey-4.0.0.14931第四卷(共四卷) 含tomcat
blazeds-turnkey-4.0.0.14931 FLEX学习必备的东西。
blazeds-core-3.2.0.3978.jar blazeds-core-3.2.0.3978.jar
通过使用RemoteObject控件可以轻松实现,而不需要配置他们像SOAP-compliant网络服务。 blazeds-bin-4.0.0.15974.zip
好不容易在网上找到的 flex与java通讯 工具 希望能够帮助刚学习flex节省点时间
blazeds-turnkey-4.0.0.14931.zip Flex与JavaEE交互用的一个项目.用于Flex远程访问JavaEE服务器! 里面有实例和帮助文档,希望对您有用!
blazeds-turnkey-4.0.0.14931.zip分卷二
包含blazeds-common-4.0.0.14931.jar、blazeds-core-4.0.0.14931.jar、blazeds-proxy-4.0.0.14931.jar、blazeds-remoting-4.0.0.14931.jar
blazeds-turnkey-4.0.0.14931含tomcat 第二卷(共四卷)
blazeds, flex 于 JAVA 交互插件
blazeds-turnkey-4.0.0.14931含tomcat 第一卷(共四卷)
blazeds-turnkey-4.0.0.14931第三卷(共四卷) 含tomcat
blazeds-bin-3.3.0.20776,Flex与java通信包,只要把blazeds.war发布到Tomcat的webRoot下即可。相关例子,网上有许多,配置比较简单。
abode flex BlazeDS 源码
flex开发 blazeds-turnkey
Spring和Adobe Flex的开发技术文档。
blazeds-turnkey-4.0.0.14931.zip、 http://opensource.adobe.com/wiki/display/blazeds/Downloads FlashBuilder_4_Plugin_LS10.exe ...