当前位置:首页 > 开发 > Web前端 > Ext > 正文

FlexContext, FlexClient,FlexSession

发表于: 2013-01-15   作者:darrenzhu   来源:转载   浏览次数:
摘要: 使用了BlazeDS后,可以从FlexContext中获取一系列与httpRequest,httpResponse相关的对象,包括FlexClient,FlexSession. 一个FlexSession可以包含一个或多个FlexClient,这个很好理解,浏览器打开两个Tab,并且没有手动新建一个Session,那么两个Tab对应两个FlexClient,server端则只对应一个FlexSe
使用了BlazeDS后,可以从FlexContext中获取一系列与httpRequest,httpResponse相关的对象,包括FlexClient,FlexSession.
一个FlexSession可以包含一个或多个FlexClient,这个很好理解,浏览器打开两个Tab,并且没有手动新建一个Session,那么两个Tab对应两个FlexClient,server端则只对应一个FlexSession.
一个FlexClient也可以包含一个或多个FlexSession,如果Flex程序里使用了两种channel,比如RTMP-channel和HTTP-based channel那么一个FlexClient会对应两个Session

FlexClient:
用户每打开一个页面加载一次swf就会产生一个新的clientId,一份swf文件跟一个FlexClient是一一对应的。如果你的浏览器开了2个Tab,每个Tab里面访问同样的Flex应用程序,那么有两个不同的clientId,同时需要注意的是,你刷新了一个Tab,导致重新加载了一次swf文件,那么会产生一个新的clientId.另外当FlexSession过期后,如果你没有刷新页面重新加载swf,那么clientId是不变的。

FlexSession:
FlexSession是一个比HttpSession概念更宽泛的Object,FlexClient根据Channel的不同可以创建出不同的Session,基于Servlet的的HttpSession和基于NIO的RTMPSession,如果你的Flex程序使用了两种channel,那么FlexSession对应的是两个Session:HttpSession和RTMPSession,为了方便,你可以使用FlexContext.getFlexClient().getFlexSessions()来操作该FlexClient对应的Sessions.
对与只基于Servlet的HttpRequest的HttpSession来说,FlexSession和HttpSession两者的SessionId是一致的.

Are you out of luck when you use NIO-based channels/endpoints? Not really. You still have access to FlexClient object on the server, and FlexClient object has a list of sessions it is associated with. For example, if your Flex application uses a Servlet-based channel (let’s call this my-amf in short) and a NIO-based channel (my-rtmp in short), FlexClient will have 2 sessions in its list of sessions: One Servlet-based session (i.e. HttpFlexSession) for my-amf and one NIO-based session (i.e. RTMPFlexSession) for my-rtmp. Whenever you set an attribute on RTMPFlexSession, you can access the HttpFlexSession and set it there too. This way, not only all sessions associated with Flex client get the attribute, but a JSP in the same page would get the attribute in its HttpSession.

One important point. If you don’t care about sharing session data outside Flex (with a JSP for example), it’s good to know that FlexClient (the object that represents the SWF on the server) also has get/set/remove attribute methods. By setting/retrieving attributes on the FlexClient, you avoid the complexities of dealing with multiple sessions.



Reference URL:
http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/help.html?content=lcconnections_2.html
http://meteatamel.wordpress.com/2010/05/21/a-little-session-talk/

FlexClient, MessageClient, and FlexSession objects
The FlexClient object

Every Flex application, written in MXML or ActionScript, is eventually compiled into a SWF file. When the SWF file connects to the LiveCycle Data Services ES server, a flex.messaging.client.FlexClient object is created to represent that SWF file on the server. SWF files and FlexClient instances have a one-to-one mapping. In this mapping, every FlexClient instance has a unique identifier named id, which the LiveCycle Data Services ES server generates. An ActionScript singleton class, mx.messaging.FlexClient, is also created for the Flex application to access its unique FlexClient id.

The MessageClient object

If a Flex application contains a Consumer component (flex.messaging.Consumer), the server creates a corresponding flex.messaging.MessageClient instance that represents the subscription state of the Consumer component. Every MessageClient has a unique identifier named clientId. The LiveCycle Data Services ES server can automatically generate the clientId value, but the Flex application can also set the value in the Consumer.clientId property before calling the Consumer.subscribe() method.

The FlexSession object

A FlexSession object represents the connection between the Flex application and the LiveCycle Data Services ES server. Its life cycle depends on the underlying protocol, which is determined by the channels and endpoints used on the client and server, respectively.

If you use an RTMP channel in the Flex application, the FlexSession on the LiveCycle Data Services ES server is scoped to the underlying RTMP connection from the single SWF file. The server is immediately notified when the underlying SWF file is disconnected because RTMP provides a duplex socket connection between the SWF file and the LiveCycle Data Services ES server. RTMP connections are created for individual SWF files, so when the connection is closed, the associated FlexSession is invalidated.

If an HTTP-based channel, such as AMFChannel or HTTPChannel, is used in the Flex application, the FlexSession on the LiveCycle Data Services ES server is scoped to the browser and wraps an HTTP session. If the HTTP-based channel connects to a servlet-based endpoint, the underlying HTTP session is a J2EE HttpSession object. If the channel connects to an NIO-based endpoint, the underlying HTTP session supports the FlexSession API, but it is disjointed from the application server HttpSession object.

The relationship between FlexClient, MessageClient, and FlexSession classes
A FlexClient object can have one or more FlexSession instances associated with it depending on the channels that the Flex application uses. For example, if the Flex application uses one HTTPChannel, one FlexSession represents the HTTP session created for that HTTPChannel on the LiveCycle Data Services ES server. If the Flex application uses an HTTPChannel and an RTMPChannel, two FlexSessions are created; one represents the HTTP session and the other represents the RTMP session.

A FlexSession can also have one or more FlexClients associated with it. For example, when a SWF file that uses an HTTPChannel is opened in two tabs, two FlexClient instances are created in the LiveCycle Data Services ES server (one for each SWF file), but there is only one FlexSession because two tabs share the same underlying HTTP session.

In terms of hierarchy, FlexClient and FlexSession are peers whereas there is a parent-child relationship between FlexClient/FlexSession and MessageClient. A MessageClient is created for every Consumer component in the Flex application. A Consumer must be contained in a single SWF file and it must subscribe over a single channel. Therefore, each MessageClient is associated with exactly one FlexClient and one FlexSession.

If either the FlexClient or the FlexSession is invalidated on the server, it invalidates the MessageClient. This behavior matches the behavior on the client. If you close the SWF file, the client subscription state is invalidated. If you disconnect the channel or it loses connectivity, the Consumer component is unsubscribed.

Event listeners for FlexClient, MessageClient, and FlexSession
The LiveCycle Data Services ES server provides the following set of event listener interfaces that allow you to execute custom business logic as FlexClient, FlexSession, and MessageClient instances are created and destroyed and as their state changes:

Event listener
Description

FlexClientListener
FlexClientListener supports listening for life cycle events for FlexClient instances.

FlexClientAttributeListener
FlexClientAttributeListener supports notification when attributes are added, replaced, or removed from FlexClient instances.

FlexClientBindingListener
FlexClientBindingListener supports notification when the implementing class is bound or unbound as an attribute to a FlexClient instance.

FlexSessionListener
FlexSessionListener supports listening for life cycle events for FlexSession instances.

FlexSessionAttributeListener
FlexSessionAttributeListener supports notification when attributes are added, replaced, or removed from FlexSession instances.

FlexSessionBindingListener
FlexSessionBindingListener supports notification when the implementing class is bound or unbound as an attribute to a FlexSession instance.

MessageClientListener
MessageClientListener supports listening for life cycle events for MessageClient instances representing Consumer subscriptions.


For more information about these classes, see the Javadoc API documentation.

Log categories for FlexClient, MessageClient, and FlexSession classes
The following server-side log categories can be used to track creation, destruction, and other relevant information for FlexClient, MessageClient, and FlexSession:

■Client.FlexClient
■Client.MessageClient
■Endpoint.FlexSession

FlexContext, FlexClient,FlexSession

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
先说现象:当用户登录以后,如果点击浏览器的后退按钮回到登录页面,这个时候用浏览器的前进按钮是
这篇博文旨在提高编码的健壮性。良好的生命周期设计是代码健壮的前提之一,任何一个独立的类都应该
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号