1、為什么選用amf,而不選用json
首先,amf支持?jǐn)?shù)據(jù)對象圖,比如A對象和B對象都有C對象屬性,那么amf時(shí),只有一個(gè)C對象,效率比Json高。尤其是recurive時(shí)的情景,A對象有List<D>,而D又有A a屬性,這種串行化在json里面只能修改為單向關(guān)系。
其次:amf好歹是緊促的二進(jìn)制協(xié)議。
再次:我喜歡客戶端的強(qiáng)類型模型。
2、TideResponder有什么作用?
首先,能夠傳遞一個(gè)token對象,這個(gè)對象在resultEvent和faultEvent事件中使用,當(dāng)然有些人的做法是定義一個(gè)類屬性來記載這個(gè)token對象,不太優(yōu)雅,建議用TideResponder。
例:var responder:TideResponder=new TideResponder(resultHandler,faultHander,"tokenData");
其次:可以提供一個(gè)和服務(wù)端返回結(jié)果合并的返回對象。
tideContext.productService.findAllProducts(new TideResponder(resultHandler, null, null, products));返回值和products合并,一般要求products為非空,這種合并作用于集合或者對象類型(具有uid屬性),但是對簡單類型沒有作用。
3、Service initializer
Tide remoting應(yīng)用可以不用service-config.xml配置文件,可以手工定義remoting channels,最簡單的就是使用內(nèi)置的DefaultServiceInitializer,比如在應(yīng)用創(chuàng)建完畢事件中增加:
Tide.getInstance().addComponentWithFactory("serviceInitializer", DefaultServiceInitializer,
{ contextRoot: "/context-root" }//可以提供serverName和serverPort
);
4、客戶端消息攔截器
這個(gè)相當(dāng)有用,aop,可以在所有的遠(yuǎn)程調(diào)用中增加通用行為,比如顯示和隱藏等待界面或者設(shè)置定制headers,接口見IMessageInterceptor,里面有before和after兩個(gè)方法需要實(shí)現(xiàn)。
5、全局異常處理器
這個(gè)比較重要,可以在客戶端各個(gè)異常碼定義通用的處理方法,在服務(wù)端可以定義異常轉(zhuǎn)換,將服務(wù)端異常轉(zhuǎn)換為通用的異常編碼。
需要在服務(wù)端定義ExceptionConverter類。當(dāng)graniteds配置scan=true時(shí),必須確保META-INF/granite-config.properties文件存在,盡管為空。
在flex端,需要定義異常處理類:
Tide.busy:綁定型屬性,用于判斷是否正處于遠(yuǎn)程調(diào)用,這個(gè)很有用,應(yīng)用中需要避免誤操作多次點(diǎn)擊調(diào)用。
Tide.disconnected:當(dāng)網(wǎng)絡(luò)出現(xiàn)錯(cuò)誤,將設(shè)置為true,每次成功調(diào)用,將設(shè)置為true,這個(gè)屬性一般只能做狀態(tài)顯示。
7、per-destination security:可以對每個(gè)destination進(jìn)行安全控制,編寫extends DestinationSecuirzer,并在配置文件中進(jìn)行如下配置:
{ contextRoot: "/context-root" }//可以提供serverName和serverPort
);
4、客戶端消息攔截器
這個(gè)相當(dāng)有用,aop,可以在所有的遠(yuǎn)程調(diào)用中增加通用行為,比如顯示和隱藏等待界面或者設(shè)置定制headers,接口見IMessageInterceptor,里面有before和after兩個(gè)方法需要實(shí)現(xiàn)。
5、全局異常處理器
這個(gè)比較重要,可以在客戶端各個(gè)異常碼定義通用的處理方法,在服務(wù)端可以定義異常轉(zhuǎn)換,將服務(wù)端異常轉(zhuǎn)換為通用的異常編碼。
需要在服務(wù)端定義ExceptionConverter類。當(dāng)graniteds配置scan=true時(shí),必須確保META-INF/granite-config.properties文件存在,盡管為空。
在flex端,需要定義異常處理類:
public class EntityNotFoundExceptionHandler implements IExceptionHandler {
public function accepts(emsg:ErrorMessage):Boolean {
return emsg.faultCode == "Persistence.EntityNotFound";
}
public function handle(context:BaseContext, emsg:ErrorMessage):void {
Alert.show("Entity not found: " + emsg.message);
}
}
并且在靜態(tài)初始化塊中注冊,確保在任何其他操作之前完成注冊:
6、Tide.showBusyCursor:在執(zhí)行遠(yuǎn)程調(diào)用時(shí)是否顯示busy mouse cursor。public function accepts(emsg:ErrorMessage):Boolean {
return emsg.faultCode == "Persistence.EntityNotFound";
}
public function handle(context:BaseContext, emsg:ErrorMessage):void {
Alert.show("Entity not found: " + emsg.message);
}
}
并且在靜態(tài)初始化塊中注冊,確保在任何其他操作之前完成注冊:
Tide.getInstance().addExceptionHandler(EntityNotFoundExceptionHandler);
Tide.busy:綁定型屬性,用于判斷是否正處于遠(yuǎn)程調(diào)用,這個(gè)很有用,應(yīng)用中需要避免誤操作多次點(diǎn)擊調(diào)用。
Tide.disconnected:當(dāng)網(wǎng)絡(luò)出現(xiàn)錯(cuò)誤,將設(shè)置為true,每次成功調(diào)用,將設(shè)置為true,這個(gè)屬性一般只能做狀態(tài)顯示。
7、per-destination security:可以對每個(gè)destination進(jìn)行安全控制,編寫extends DestinationSecuirzer,并在配置文件中進(jìn)行如下配置:
<destination id="restrictedDestination">
...
<properties>
<securizer>path.to.MyDestinationSecurizer</securizer>
</properties>
</destination>
...
<properties>
<securizer>path.to.MyDestinationSecurizer</securizer>
</properties>
</destination>