Archive for May, 2008

24
May

Data Push from Servers to Client

To push data from server to client, you use the Flex.data.DataServiceTransactions Java class. The object is used on the server-side to push changes to managed code stored on clients that have the AutoSyncEnabled property of the DataService component set to true.

The Data Management Service creates an instance of the DataServiceTransaction class when you make changes to a sync method. With the instance, you can call the getcurrentDataServiceTransaction(), deleteitem(), and createitem() methods to trigger additional changes. If the current transaction is rolled back, these changes are not pushed to clients.

Note that when you compile code that uses the FDS Java APIs, you must include the messaging JAR and flex-messaging-common.jar files in your class path.

24
May

Data Management Service Configuration

To connect to Data Management Service using the <mx:DataService> tag, you must configure a destination in your service-config.xml file. The section describes how to configure the destinations and data adapters they use, and also how to push data to clients.

Data Management Service Destination Configuration

As mentioned previously, messages are transported over message channels. You can define one or more message channels for a destination definition. If one channel cannot be reached, the next one in the list is tried.

The following example shows a destination definition with two message channels defined:

 <service id=”myDataManagementService” class=”flex.data.DataService” messageTypes=
 “flex.data.messages.DataMessage”>      <adapters>
         <adapter-definition id=”actionscript”
             class=”flex.data.adapters.ASObjectAdapter” default=”true”/>
         <adapter-definition id=”java-adapter”
             class=”flex.data.adapters.JavaAdapter”/>
     </adapters>      <default-channels>
         <channel ref=”my-rtmp”/>
     </default-channels>      <destination id=”contact”>
         <adapter ref=”java-adapter” />
             <properties>                 <source>dev.contacts.ContactAssembler</source>
                 <scope>application</scope>
                 <cache-items>true</cache-items>                 <metadata>
                     <identity property=”contactId”/>
                 </metadata>                  <network>                     <session-ti
meout>20</session-timeout>                     <paging enabled=”t
rue” pageSize=”10″ />
                     <throttle-inbound policy=”ERROR” 
max-frequency=”500″/>
                     <throttle-outbound policy=”REPLACE” max-frequency=”500″/>
 
                 </network>                  <server>
                     <fill-method>                         <name>loadContacts</name>
                     </fill-method>
                     <fill-method>                         <name>loadContacts</name>
                         <params>java.lang.String</params>
                     </fill-method>                     <sync-method>
                         <name>syncContacts</name>
                     </sync-method>                  </server>             </properties>
     </destination>
 </service>

Configure Network-Related Properties

The network-related properties are the same as configuring the Flex Message Service, except that there are two additional properties, cluster and paging, as shown in the following table.

Element

Description

Transactions

All client changes are handled as one unit and, if the value cannot be changed, all changes are rolled back. Your J2EE server must support J2EE transactions (JTA) for distributed transactions to work.

The following defines the use of transactions within a destination definition:

 <destination id=”myDestination”>     <properties>
         <metadata>
             <identity property=”name”/>
         </metadata>     </properties>
 </destination>

Item Caching

The default setting in Data Management Service is set to true for items returned from fill() and getitem() calls. This means a complete copy of the managed state of all active clients is kept in each server’s memory.

The following example turns off the cache of items in the destination definition:

 <destination id=”myDestination”>
     <properties>
             <cache-items>false</cache-items>
     </properties>
 </destination>
24
May

flex Data Synchronization Handling

When working with distribution data, there are often times that clients try to make changes already made. The following example displays an Alert box when a client conflict occurs:

 <?xml version=”1.0″ encoding=”utf-8″?>
 <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
      creationComplete=”initUI()”>       <mx:Script>           <![CDATA[
                import mx.controls.Alert;                 import mx.data.*;
                import mx.data.events.DataConflictEvent;                 public var ds:DataService;                 public function initUI():void
                {                     ds = new DataService(”myDestination”);
                     ds.addEventListener(DataConflictEvent.CONFLICT, conflictHandler);
                }                 private function conflictHandler(event:DataConflictEvent):void
                {
                     var conflicts:Conflicts = ds.conflicts;
                     var c:Conflict;                      for (var i:Number = 0; i < conflicts.length; i++)
                     {                          c = Conflict(conflicts.getItemAt(i));
                          Alert.show(”Rolling back”, “Conflict has occured”);
                          c.acceptServer();
                     }                }            ]]>
      </mx:Script>  </mx:Application>
24
May

flex Class Mappings

To map a server-side Java object to a client-side ActionScript object, you use the [RemoteClass(alias=”")] metadata tag. You must specify the package and class name of the Java object in the alias value. This is the same technique used when you map client and Java objects using RemoteObject components.

If you do not want to map the ActionScript object to the Java object, but do want it mapped from the server to client, just specify the [RemoteClass] metadata tag without the alias value.

The following example shows an ActionScript object that is mapped to a Java object called com.mycompany.vo.User:

 package com.learningpc.livecourse.vo {       [Bindable]
      [RemoteClass(alias=”com.mycompany.vo.UserVO”)]
      public class UserVO
      {
           public var id:Number;           public var sessionkey:Str
ing;           public var username:String;
           public var password:String;           public var firstname:String;
           public var middlename:String;
           public var lastname:String;
           public var photo:String;
           public var emailaddress:String;
           public var logincount:Number;
           public var lastlogindate:Date;
           public var lastlogoutdate:Date;           public var homepage:String;
           public var usertype:String;
           public var lastIp:String;
           public var active:Number;      } }

The following shows the corresponding Java object contact:

 package com.learningpc.livecourse.vo;  import java.io.Serializable;  public class User implements Serializable {      private static final long serialVersionUID = 4832904328320999999L;       private int id;
      private String usern
ame;      private String password;
      private String firstname;
      private String lastname;
      private String emailaddress;       public static long getSerialVersionUID()      {
           return serialVersionUID;      }       public String getEmailaddress()      {
           return emailaddress;      }       public void setEmailaddress(String emailaddress)      {
           this.emailaddress = emailaddress;      }       public String getFirstname()      {
           return firstname;
      }       public void setFirstname(String firstname)      {
           this.firstname = firstname;      }       public int getId()      {
           return id;      }       public void setId(int id)      {
           this.id = id;      }       public String getLastname()      {
           return lastname;      }       public void setLastname(String lastname)      {
           this.lastname = lastname;      }       public String getPassword()      {           return password;      }       public void setPassword(String password)      {
           this.password = password;      }       public String getUsername()      {
           return username;      }       public void setUsername(String username)      {
           this.username = username;      } 
      public String toString()      {
           StringBuffer sb = new StringBuffer();           sb.append(username);
           sb.append(” “);
           sb.append(password);           sb.append(” “);
           sb.append(firstname);           sb.append(” “);
           sb.append(lastname);
           return sb.toString();      } }



 

May 2008
M T W T F S S
    Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Badge Farm

  • Textmate