• 211.00 KB
  • 24页

【计算机软件毕业设计】安装项目成本管理系统施工图管理子系统的设计与实现-文献翻译

  • 24页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'文献翻译Flex消息整体介绍包括1、建立BlazeDS消息2、使用Flex API消息Flex通信API,捆绑BlazeDS,提供异步消息。BlazeDS允许Flex客户端信息和服务之间进行通信,双向POJO到被集成到Flex客户端通信和JMS。在一般情况下,我们要使用通知客户的变化目的消息。这将触发一个事件更新Flexbug问题清单。图6.1显示了使用消息。图6.1简单的流程正如您可以从图中看到,当Flex客户端轮询服务器端的消息和服务器确认该请求与返回消息6.1简单的轮询发生。还有更多的比这个但这提供大画面。从本质上发生的事情是,用户将增加一个新的问题,以系统以及这样做的时候问题服务会产生客户端获得一个讯息通知。因为,客户是消费者,这个问题产生的服务的消息,因为它会得到一个确认有变化,触发一个消息处理程序事件来刷新的问题列表消息的目的地。消息处理程序是简单地连接到同一个MVP的管道模型中的与该客户机的其余部分的工作方式无干扰。本章将利用使用Flex的消息传递API和简单的轮询从模型中的变化已经发生,当服务器接收更新。变化会引起一个事件被调度,将刷新主视图和问题最终名单。 在如何传讯工作的细节取决于您的需要和选择什么风格的底层消息传递架构来实现。例如,客户端到客户端,JMS,Flex来POJO或JavaBean的消息。更重要的是它可以配置客户端进行简单的或长轮询,甚至流之上。所有这些不同用途的消息是有用的,也有益处和后果和他们一起去。它总是最好的越来越复杂之前,先从简单的方法第一。6.1设置为BlazeDS的消息有为了建立一个简单的消息传递架构,将允许Flex客户端以订阅服务器端的组件很少的配置。这也是很好的了解,消息API是不可知的底层消息传递架构。这可以很容易地从一个简单的服务器端,说使用POJO,并扩展到类似的JMS只有当必要的。6.1.1修改与services-config.xml要做的第一件事就是修改services-config.xml文件。如果在Flex-虫虫示例应用程序的工作是大火,配置模块中找到。在services-config.xml文件所在目录/flex-bugs-blaze-config/src/main/resources。我们希望与轮询,如清单6.1中看到一个新的通道定义编写服务器端。为了简便起见,我们已经排除了已经讨论过该文件的内容并不会改变。列表6.1添加了消息通道定义true4 1通道定义声明2端点URL3轮询启用4轮询间隔通道定义是很容易设置的,所有我们需要做的就是指定一个id#1,#enpoint2,并启用轮询#3。该通道定义“我的轮询-AMF”#1,随着类,将使用了Flex客户端与服务器联系。该enpoint元素#2提供了一个网址,那一定是从其他端点独特,和端点类服务器。端点是由通道服务做它的业务的问候client-side/server-side沟通。最后,嵌套在一个properties元素定义的通道属性。通道定义中包含行为,从而使其在各种不同的方式进行配置。在我们的例子中,我们有简单的轮询启用#3和轮询间隔#4组轮询在每4秒。简单的轮询一般比长轮询效率较低,因为它继续ping服务器在每个指定的时间间隔和接收确认,即使没有任何变化和确认是空的。在另一方面,长轮询允许客户端ping服务器,该服务器保存请求,并返回一个应答时,有一个消息。轮询性能当选择一个轮询机制考虑哪些解决办法是最少的开销。既简单又长轮询可以是服务器端的密集,如果有大量的消息被来回传递和大量的用户。尽管长轮询通常比简单更高效的它可能是许多用户经常改变一个应用程序可能会导致更多的客户机/服务器的摩擦和比控制轮询与简单的方法但执行。如果长轮询是一种选择,流应该是一个考虑为好。流媒体是非常相似,但保持一个连接,而不是打开和关闭各一个传输之间开放。这些变化对服务-config.xml中是必要的配置模块用于添加投票通道的唯一变化。现在,让我们继续前进的web应用模块的变化。6.1.2更新的web应用服务器端模块现在我们已经解决在services-config.xml文件中的通道定义,我们就可以继续修改web应用的服务器端。我们将开始与柔性弹簧-servlet.xml中和applicationContext.xml中配置的修改,然后移动到要改变的Java代码。 修改FLEX-SPRING-servlet.xml中首先,我们通过开放,是在/flex-bugs-web/src/main/webapp/WEB-INF目录中的flex-spring-servlet.xml中进行编辑。在这里,我们将增加一个新的Spring管理消息管理中心,消息业务,并MessageDestination为我们新的投票通道。列表6.2显示的flex-spring-servlet.xml文件所做的编辑。1添加消息服务2增加了消息的目的地在清单6.2,我们只是添加了Spring的讯息服务#1指向我们的services-config.xml中定义了我的轮询-AMF通道。由于我们使用的是Spring管理MessageBroker我们可以简单地通过添加元素,并赋予它我们要指在服务器端执行的ID指定消息目的地#2。我们将使用消息的目的地,从服务器端对象发送消息。 修改applicationContext.xml中配置细节的最后一位是在SpringapplicationContext.xml中找到。此文件也位于WEB-INF文件。列表6.3显示了更改applicationContext.xml中。为了推动信息从我们的Java对象的消息的目的地,spring给了我们MessageTemplate辅助类#1。我们只是注入MessageTemplate的一个实例到issueService#2,现在我们可以在IssueManagerImpl使用它。由于MessageTemplate被配置为一个Springbean它会自动检测消息中断。否则,就需要进行配置修改ISSUEMANAGERIMPL现在我们已经有了Spring配置平方了,我们现在可以利用注入MessageTemplate对象由如清单6.4可见其添加到IssueManagerImpl.java类。importorg.springframework.flex.messaging.MessageTemplate;@WebService(serviceName="IssueService",endpointInterface="org.foj.service.IssueManager")publicclassIssueManagerImplimplementsIssueManager{privateGenericDaoissueDao;privateCommentManagercommentManager;privateMessageTemplatemessageTemplate;publicIssueManagerImpl(GenericDaoissueDao,CommentManagercommentManager,MessageTemplatemessageTemplate){this.issueDao=issueDao;this.commentManager=commentManager;this.messageTemplate=messageTemplate;} publicIssuesave(Issueissue){StringmessageBody="Issuewassaved";messageTemplate.send("flexMessage",messageBody);#4returnissueDao.save(issue);}publicvoidremove(Longid){commentManager.deleteAllCommentsForIssueId(id);StringmessageBody="Issuewasremoved";messageTemplate.send("flexMessage",messageBody);#5issueDao.remove(id);}}1添加私有字段messageTemplate2添加注入messageTemplate给构造函数3设置messageTemplate4使用flexMessage消息目标上存5使用上删除的flexMessage消息目标为了充分使用SpringMessageTemplate首先需要创建一个私有字段来存储MessageTemplate实例#1,我们注入。由于我们是通过构造函数对象#2注入我们设置私有字段#3等于注入的实例。注射本来也可以通过提供一个setter方法,而不是构造函数的方法进行。无论哪种方法会奏效。在我们的例子中,我们将使用messageTemplate发送客户端的短信通知。可以使用该消息,也可以是一个对象,并且将让客户知道,有必要进行刷新。我们通知电汇到节省#4和#删除5方法和简单地传递到客户端,这个问题可以保存或删除。现在,所有必要的更改,让本简单的消息传递与Spring和Flex是时候继续前进,并更新Flex客户端。6.2修改客户端的消息Flex客户端的变化是非常简单的。使用了MVP设计模式的真正隔离的改变只有两个位置。我们只需添加新的投票通道到ChannelSetFactory对象,然后最后修改IssueModel对象从轮询通道接收的问题模型的更新。 packageorg.foj.model{importmx.messaging.ChannelSet;importmx.messaging.channels.AMFChannel;publicclassChannelSetFactory{privatestaticvar_defaultChannelSet:ChannelSet;privatestaticvar_messagingChannelSet:ChannelSet;publicfunctionChannelSetFactory(){}publicstaticfunctiongetDefaultChannel():ChannelSet{if(_defaultChannelSet==null){varchannel:AMFChannel=newAMFChannel("my-amf","http://localhost:8080/flexbugs/messagebroker/amf");_defaultChannelSet=newChannelSet();_defaultChannelSet.addChannel(channel);}return_defaultChannelSet;}publicstaticfunctiongetMessagingChannel():ChannelSet{if(_messagingChannelSet==null){varpollingChannel:AMFChannel=newAMFChannel("my-polling-amf","http://localhost:8080/flexbugs/messagebroker/amfpolling");_messagingChannelSet=newChannelSet();_messagingChannelSet.addChannel(pollingChannel);}return_messagingChannelSet;}}}1私有字段来保存新的轮询的ChannelSet 2静态方法返回轮询的一个实例的ChannelSet对于轮询ChannelSet的配置是相同的非轮询1以外的“我的轮询-AMF”实例化新AMFChannel时所使用的ID。我们首先添加一个私有字段称为_messagingChannelSet#1持有AMFChannel对象的实例。接着,新的静态方法#2中加入,以允许任何对象,以获取轮询的ChannelSet的一个实例。6.2.2修改IssueModel最后一个要执行的任务,在我们的样本通讯设计,是真正断火的事件当客户端收到一个推送通知信息,并应更新问题主视图的DataGrid。为此,我们通过将消息渠道的消费者。代码清单6.6显示了更新IssueModel对象。具有良好的设计短信使用MVP设计模式使得集成与服务器端通讯时的微风在Flex客户端。变化是没有必要的Flex客户端MXML文件或其他视图的特定类。良好的设计模式真正开始闪耀你得到滚动一个项目后,并开始做更改或添加这样的消息架构packageorg.foj.model{...importmx.messaging.events.MessageEvent;#1publicclassIssueModel{privatevar_issueService:RemoteObject;publicfunctionIssueModel(){vardefaultChannelSet:ChannelSet=ChannelSetFactory.getDefaultChannel();_issueService=newRemoteObject();_issueService.destination= "issueService";_issueService.channelSet=defaultChannelSet;varmessagingChannelSet:ChannelSet=ChannelSetFactory.getMessagingChannel();varconsumer:Consumer=newConsumer();consumer.destination="flexMessage";consumer.channelSet=messagingChannelSet;consumer.addEventListener(MessageEvent.MESSAGE,messageHandler);consumer.subscribe();}privatefunctionmessageHandler(event:MessageEvent):void{vareventDispatcher:EventDispatcher=EventDispatcherFactory.getEventDispatcher();varrefreshEvent:UIEvent=newUIEvent(UIEvent.REFRESH_ISSUES_BUTTON_CLICKED);eventDispatcher.dispatchEvent(refreshEvent);}...}}1导入Flex的MessageEvent的类2从工厂获取消息的ChannelSet3安装Flex消费者4MessageHandler的使用派遣一个refreshEvent在IssueModel我们能够通过内置的Flex消息API收到更改通知。导入MessageEvent的类#1后,我们需要从ChannelSetfactory#2得到消息的AMF的ChannelSet的一个实例。接下来,我们需要创建一个Flex消费者#3,建立它的属性。我们配置了消费者的目的地是“flexMessage”目的地,在柔性弹簧servlet.xml中定义的。消费者的ChannelSet的设置为我们从ChannelSetFactory拿到之一。 一个很重要的一块,这一切都是在事件侦听器。这将允许我们调用一个方法时,消费者会收到一条消息从服务器。我们不得不在这里做的唯一的事情是说,我们希望该事件成为MessageEvent消息类型“消息”,并在“MessageHandler的”#4调用该方法。最后,我们订阅服务器端的消息目标通过调用consumer.subscribe现在,我们的Flex客户端设置为订阅消息传递目的地,我们能够看到它在行动。这是可能通过打开两个不同的浏览器实例,修改于一体,同时密切关注其他类似图6.2,其中左边的浏览器代码片段显示,持续的问题,并在浏览器右边自动获取问题的形式更新。图6.2尝试了短信使用两个浏览器如发生在应用程序的问题,变化的变化应该是noticable在DataGrid中的问题。将每4秒钟内的变化,如在通道定义中指定。这是所有有设置了Flex的一个简单的消息传递解决方案!6.3小结在本章中,我们BlazeDS的配置,Spring和一个Flex客户端进行简单的消息传递架构。我们改变某些Java服务方法,使他们更改通知的客户端。并更改了Flex客户端的IssueModel听作为一个消费者。使用Flex消息传递API,我们用消费者订阅的消息通道服务,并接受动态更新的问题主视图。我们将采取短信更远了一步通过使用Grails讨论Flex会配置JMS。翻译原文 FlexMessagingThisintroductioncoversSettingupBlazeDSformessagingUsingtheFlexmessagingAPITheFlexmessagingAPI,bundledwithBlazeDS,providesasynchronousmessaging.TheBlazeDSMessageServiceallowsmessagingbetweenFlexclients,two-wayPOJOtosubcribedFlexclientcommunication,andJMSintegration.Ingeneral,wewanttousemessagingforthepurposeofnotifyingtheclientofchanges.ThiswillfireoffaneventtorefreshtheFlex-Bugsissueslist.Figure6.1demonstratesthisuseofmessaging.Figure6.1SimplePollingAsyoucanseefromfigure6.1simplepollinghappenswhentheFlexclientpollstheserver-sideforamessageandtheserveracknowledgesthatrequestwithareturnmessage.There"smoretoitthanthisbutthisprovidesthebigpicture.Essentiallywhathappensisthatauserwouldaddanewissuetothesystemandwhendoingsotheissueservicewillproduceamessagenotificationfortheclienttopickup.Since,theclientisaconsumerofamessagedestinationthattheissueserviceproducedamessageforitwillgetanacknowledgementthattherewerechangesandfireamessagehandlereventtorefreshtheissuelist.ThemessagehandlerissimplywiredtothesameMVPplumbinginthemodelwithnointerferencetothewaytherestoftheclientworks.ThischapterwillexploittheuseoftheFlexmessagingAPIandsimplepollingtoreceiveupdatesfromtheserverwhenchangesinthemodelhaveoccurred.Changeswillcauseaneventtobedispatchedthatwillrefreshthemasterviewandultimatelythelistofissues.Inthedetailsofhowmessagingworksdependsonyourneedsand whatstyleofunderlyingmessagingarchitectureischosentoimplement.Forexample,client-to-client,JMS,FlextoPOJOorJavaBeanmessaging.Ontopofthatit"spossibletoconfiguretheclienttoperformsimpleorlongpollingorevenstreaming.Allthesedifferentusagesformessagingareusefulandalsohavebenefitsandconsequencestogowiththem.It"salwaysbesttostartwiththesimpleapproachfirstbeforegettingcomplicated.6.1SettingupBlazeDSforMessagingThereisverylittleconfigurationinordertosetupasimplemessagingarchitecturethatwouldallowaFlexclienttosubscribetoaserver-sidecomponent.It"salsogoodtoknowthatthemessagingAPIisagnostictotheunderlyingmessagingarchitecture.Thismakesiteasytostartwithasimpleserver-side,saywithPOJOs,andexpandtosomethinglikeJMSonlyifnecessary.6.1.1Modifytheservices-config.xmlThefirstthingtodoistomodifytheservices-config.xmlfile.IfworkingintheFlex-Bugssampleapplicationitisfoundintheblaze-configmodule.Theservices-config.xmlfileislocateddirectory/flex-bugs-blaze-config/src/main/resources.Wewanttopreparetheserver-sidewithanewchanneldefinitionforpollingasseeninListing6.1.Forbrevitywe"veexcludedelementsofthefilethathavealreadybeendiscussedandarenotgoingtochange.Listing6.1Addingthepollingchannel-definition......#1#2true#34#4...1Channel-definitiondeclaration2Endpointurl3PollingISenabled4PollingintervalThechanneldefinitioniseasytosetupinthatallwehavetodoisspecifyanid#1,enpoint#2,andenablepolling#3.Thechanneldefinition"my-polling-amf"#1,alongwiththeclass,willbeusedbytheFlexclientforcontactingtheserver.Theenpointelement#2providesaURL,thatmustbeuniquefromotherendpoints,andtheendpointclassfortheserver.Theendpointisusedbythechannelservicetodoit"sbusinessinregardstoclient-side/server-sidecommunication.Lastly,propertiesdefiningthechannelarenestedinapropertieselement.Thechanneldefinitioncontainsbehaviorsthatallowittobeconfiguredinavarietyofways.Inourexample,wehavesimplepollingenabled#3andthepollinginterval#4settopollatevery4seconds.Simplepollingisgenerallylessefficientthanlongpollingbecauseitcontinuestopingtheserverateachspecifiedintervalandreceivesacknowledgementsevenwhentherearenochangesandtheacknowledgementsareempty.Ontheotherhand,longpollingallowstheclienttopingtheserver,theserverkeepstherequestandreturnsanacknowledgementwhenthereisamessage.PollingperformanceWhenselectingapollingmechanismconsiderwhichsolutionwouldbetheleastamountofoverhead.Bothsimpleandlongpollingcanbeserver-sideintensiveiftherearelotsofmessages beingpassedbackandforthandlotsofusers.Eventhoughlongpollingisgenerallymoreefficientthansimpleit"spossiblethatanapplicationwithmanyuserswithfrequentchangescouldcausemoreclient/serverfrictionandbelessperformantthancontrollingpollingwiththesimpleapproach.Iflongpollingisanoption,streamingshouldbeaconsiderationaswell.Streamingisverysimiliarbutkeepsaconnectionopeninsteadofopeningandclosingonebetweeneachtransmission.Thechangestotheservices-config.xmlweretheonlychangesnecessaryfortheconfigurationmoduleforaddingapollingchannel.Nowletsmoveontothewebappmodulechanges.6.1.2Updatingthewebappserver-sidemoduleNowthatwe"vetackledthechanneldefinitionintheservices-config.xmlfilewecanmoveontomodifyingthewebappserver-side.We"llstartwiththeflex-spring-servlet.xmlandapplicationContext.xmlconfigurationeditsandthenmoveontotochangesintheJavacode.MODIFYTHEFLEX-SPRING-SERVLET.XMLWestartbyopeninguptheflex-spring-servlet.xmlforeditingthatisfoundinthe/flex-bugs-web/src/main/webapp/WEB-INFdirectory.HerewewillbeaddinganewSpring-managedMessageBroker,MessageService,andMessageDestinationforournewpollingchannel.Listing6.2displaystheeditsmadetotheflex-spring-servlet.xmlfile.Listing6.2AddingtheMessageServiceandMessageBroker #1#21Addedthemessage-service2Addedthemessage-destinationInlisting6.2wesimplyaddedtheSpringmessage-service#1thatpointstothemy-polling-amfchannelwedefinedintheservices-config.xml.SinceweareusingaSpring-managedMessageBrokerwecansimplyspecifythemessagedestination#2byaddingtheelementandgivingittheidwewanttorefertointheserver-sideimplementation.Wewillusethemessagedestinationtosendmessagesfromtheserver-sideobjects.MODIFYTHEAPPLICATIONCONTEXT.XMLThelastbitofconfigurationdetailisfoundintheSpringapplicationContext.xml.ThisfileisalsolocatedintheWEB-INF.Listing6.3displaysthechangestotheapplicationContext.xml.Listing6.3AddingtheSpringMessageTemplate#21TheSpringMessageTemplatebean2InjectingtheMessagTemplateintotheissueService InordertopushmessagestothemessagedestinationfromourJavaobjects,SpringhasgivenustheMessageTemplatehelperclass#1.WesimplyinjectaninstanceoftheMessageTemplateintotheissueService#2andnowwecanuseitintheIssueManagerImpl.SincetheMessageTemplateisconfiguredasaSpringbeanitautodetectstheMessageBroker.Otherwise,itwouldneedtobeconfigured.MODIFYTHEISSUEMANAGERIMPLNowthatwehavetheSpringconfigurationsquaredawaywecannowtakeadvantageoftheinjectedMessageTemplateobjectbyaddingittotheIssueManagerImpl.javaclassasseeninlisting6.4.Listing6.4AddingtheinjectedMessageTemplate...importorg.springframework.flex.messaging.MessageTemplate;@WebService(serviceName="IssueService",endpointInterface="org.foj.service.IssueManager")publicclassIssueManagerImplimplementsIssueManager{privateGenericDaoissueDao;privateCommentManagercommentManager;#1privateMessageTemplatemessageTemplate;publicIssueManagerImpl(GenericDaoissueDao,CommentManagercommentManager,#2MessageTemplatemessageTemplate){this.issueDao=issueDao;this.commentManager=commentManager;#3this.messageTemplate=messageTemplate;}publicIssuesave(Issueissue){StringmessageBody="Issuewassaved";messageTemplate.send("flexMessage",messageBody);#4returnissueDao.save(issue);}publicvoidremove(Longid){commentManager.deleteAllCommentsForIssueId(id); StringmessageBody="Issuewasremoved";messageTemplate.send("flexMessage",messageBody);#5issueDao.remove(id);}}1AddtheprivatefieldmessageTemplate2AddtheinjectedmessageTemplatetotheconstructor3SetthemessageTemplate4UsetheflexMessagemessagedestinationonsave5UsetheflexMessagemessagedestinationonremoveInordertotakeusetheSpringMessageTemplatefirstneededtocreateaprivatefieldtostoretheMessageTemplateinstance#1thatweinject.Sinceweareinjectingthroughaconstructorobject#2wesettheprivatefield#3toequaltheinjectedinstance.Injectioncouldhavealsobeenperformedbyprovidingasettermethodinsteadoftheconstructorapproach.Eitherapproachwillwork.InourexamplewewillusethemessageTemplatetosendtheclientatextmessagenotification.Thismessagecouldbeused,couldalsobeanobject,andwilllettheclientknowthatthereisaneedtorefresh.Wewireupthenotificationtothesave#4andremove#5methodsandsimplypasstotheclientthattheissuewaseithersavedorremoved.NowthatallthenecessarychangesareinplaceforsimplemessagingwithSpringandFlexit"stimetomoveonandupdatetheFlexclient.6.2ModifyingtheclientformessagingTheFlexclientchangesareextremelysimple.TheuseoftheMVPdesignpatternreallyisolatesthechangestoonlytwolocations.WesimplyaddthenewpollingchanneltotheChannelSetFactoryobjectandthenfinallymodifytheIssueModelobjecttoreceivetheissuemodelupdatesfromthepollingchannel.6.2.1ModifytheChannelSetFactoryThefirstthingchangedrequiredfortheclientistomodifytheChannelSetFactorylocatedintheflex-bugs-libmoduleinthe/flex-bugs-lib/src/main/flex/org/foj/modeldirectory.TheadditionofaChannelSetconfigurationthatcommunicateswiththepollingchannelwecreatedisneeded.ThiswillallowtheFlexclienttothatAMFChannelandMessageBroker. Codelisting6.5displaysthechangesnecessaryforattachingtotheAMFpollingchannelfromaFlexclient.Listing6.5TheChannelSetFactorypackageorg.foj.model{importmx.messaging.ChannelSet;importmx.messaging.channels.AMFChannel;publicclassChannelSetFactory{privatestaticvar_defaultChannelSet:ChannelSet;#1privatestaticvar_messagingChannelSet:ChannelSet;publicfunctionChannelSetFactory(){}publicstaticfunctiongetDefaultChannel():ChannelSet{if(_defaultChannelSet==null){varchannel:AMFChannel=newAMFChannel("my-amf","http://localhost:8080/flexbugs/messagebroker/amf");_defaultChannelSet=newChannelSet();_defaultChannelSet.addChannel(channel);}return_defaultChannelSet;}publicstaticfunctiongetMessagingChannel():ChannelSet{#2if(_messagingChannelSet==null){varpollingChannel:AMFChannel=newAMFChannel("my-polling-amf","http://localhost:8080/flexbugs/messagebroker/amfpolling");_messagingChannelSet=newChannelSet();_messagingChannelSet.addChannel(pollingChannel);}return_messagingChannelSet;} }}1PrivatefieldtoholdthenewpollingChannelSet2StaticmethodtoreturnaninstanceofthepollingChannelSetTheconfigurationforthepollingChannelSetisidenticaltothenon-pollingoneexceptfortheIDof"my-polling-amf"usedwheninstantiatingthenewAMFChannel.Westartbyaddingaprivatefieldcalled_messagingChannelSet#1toholdtheinstanceoftheAMFChannelobject.Next,anewstaticmethod#2wasaddedinordertoallowanyobjecttogetaninstanceofthepollingChannelSet.6.2.2ModifytheIssueModelThefinaltasktoperform,inoursamplemessagingdesign,istoactuallyfireoffaneventwhentheclientreceivesapushnotificationmessageandshouldrefreshtheissuemasterviewDataGrid.WedothisbyaddingaConsumerofthemessagingchannel.Codelisting6.6displaystheupdatedIssueModelobject.MessagingwithgooddesignUsingtheMVPdesignpatternmakesintegrationwithserver-sidemessagingabreezeintheFlexclient.ChangesarenotnecessaryintheFlexclientMXMLfilesorotherviewspecificclasses.Gooddesignpatternsreallybegintoshineafteryougetrollingonaprojectandstartmakingchangesoradditionslikeamessagearchitecture.Listing6.6TheIssueModelmessageConsumerpackageorg.foj.model{...importmx.messaging.events.MessageEvent;#1publicclassIssueModel{privatevar _issueService:RemoteObject;publicfunctionIssueModel(){vardefaultChannelSet:ChannelSet=ChannelSetFactory.getDefaultChannel();_issueService=newRemoteObject();_issueService.destination="issueService";_issueService.channelSet=defaultChannelSet;varmessagingChannelSet:ChannelSet#2=ChannelSetFactory.getMessagingChannel();varconsumer:Consumer=newConsumer();#3consumer.destination="flexMessage";#3consumer.channelSet=messagingChannelSet;#3consumer.addEventListener(MessageEvent.MESSAGE,messageHandler);#3consumer.subscribe();#3}privatefunctionmessageHandler(event:MessageEvent):void{#4vareventDispatcher:EventDispatcher=EventDispatcherFactory.getEventDispatcher();varrefreshEvent:UIEvent=newUIEvent(UIEvent.REFRESH_ISSUES_BUTTON_CLICKED);eventDispatcher.dispatchEvent(refreshEvent);}... }}1ImporttheFlexMessageEventclass2GetthemessagingChannelSetfromthefactory3SettinguptheFlexConsumer4ThemessagehandlerusedtodispatcharefreshEventIntheIssueModelweareabletoreceivenotificationofchangesthroughthebuilt-inFlexMessagingAPI.AfterimportingtheMessageEventclass#1weneedtogetaninstanceofthemessagingAMFChannelSetfromtheChannelSetfactory#2.NextweneedtocreateaFlexConsumer#3andestablishit"sproperties.Weconfiguredtheconsumer"sdestinationtobethe"flexMessage"destination,definedintheflex-spring-servlet.xml.Theconsumer"sChannelSetwassettotheonewegotfromtheChannelSetFactory.Averyimportantpiecetoallthisistheeventlistener.Thiswillallowustoinvokeamethodwhenaconsumerreceivesamessagefromtheserver.TheonlythingwehadtodohereissaythatwewantedtheeventtobetheMessageEventtype"Message"andthemethodtocallis"messageHandler"#4.Finally,wesubscribetotheserver-sidemessagedestinationbycallingconsumer.subscribe().NowthatourFlexclientissetuptosubscribedtoamessagingdestinationweareabletoseeitinaction.Thisispossiblebyopeninguptwodifferentbrowserinstances,makechangesinonewhilekeepinganeyeontheotherlikeinfigure6.2wherethebrowsersnippetontheleftshowstheissueformthatpersistedtheissueandthebrowserontherightautomaticallygettingtheupdate. Figure6.2TryingoutthemessagingusingtwobrowsersChangesshouldbenoticableintheIssuesDataGridaschangesoccurintheapplicationtotheissues.Thechangeswilloccurwithinevery4seconds,asspecifiedinthechanneldefinition.That"sallthereistosettingupasimplemessagingsolutionwithFlex!6.3SummaryInthischapterweconfiguredBlazeDS,Spring,andaFlexclientforasimplemessagingarchitecture.WechangedcertainJavaservicemethodssothattheywouldnotifytheclientofchanges.andmadechangestotheFlexclient"sIssueModeltolistenasaconsumer.UsingtheFlexmessagingAPIweusedaConsumertosubscribetothemessagingchannelserviceandreceiveddynamicupdatesfortheIssuesmasterview.WewilltakemessagingastepfartherbyconfiguringJMSwhendiscussingFlexwithGrails.Inthenextchapterwewilltakeapeekatsecuringandpersonalizinganapplication.TheSpringsecurityframeworkwillbeusedalongwithitsannotationtoprovidegreatflexibilitywiththeleastamountofcomplexity. 译文要求1、译文内容必须与课题(或专业)内容相关,并需注明详细出处。2、外文翻译译文不少于2000字;外文参考资料阅读量至少3篇(相当于10万外文字符以上)。3、译文原文(或复印件)应附在译文后备查。译文评阅导师评语(应根据学校“译文要求”,对学生外文翻译的准确性、翻译数量以及译文的文字表述情况等作具体的评价)指导教师:年月日 '