`
碧海山城
  • 浏览: 190020 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Blazeds文档(二)-------Blazeds体系结构(二)

阅读更多

服务端FlexClientMessageClientFlexSession类的实例代表了Flex应用和服务端的连接。你可以使用这些对象管理FLEX应用程序和服务端的同步。

 

FlexClient, MessageClient, and FlexSession objects

 

FlexClient

 

每一个MXML或者ASFlex应用都被编译进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服务端2FlexClient实例被创建(一个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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics