28.01.2015 Views

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

141.4.PuttingProcessesTogether newIn; connectParms.ClientPutLinetoIn;<br />

aftertheparentinstantiatesthelter<strong>and</strong>callstheinitializationport.The returnParms;<br />

secondsectionisexecutedrepeatedlyeverytimeacallmessagearriveson --mainloop<br />

thelter'sIninputport|thiswillhappenwhentheclientmakesacallon endwhile; Thelterprocesshastwosections.Therstsectionisexecutedjustonce while('true')repeat<br />

itsPutLineoutputport. receivePutLineCMfromIn;<br />

Let'sbeginwiththeinitialization.Thelter'sinterfaceisdierentfrom returnPutLineCM; callOut(Prefix|":"|PutLineCM.Line);<br />

outputport|theconnectiontothePutLineservices|asParms.PutLine, passedthreeoutputports<strong>and</strong>astring.Thelter'sparentwillpassone theonewehaveseeninHelloWorld<strong>and</strong>Echo.Thoseprocesses'parents <strong>and</strong>aprexstringasParms.Prefix.Itexpectstoreceivebackanoutput<br />

variableParms.ClientPutLineaconnectiontotheinputportIn,using In.Thisisdonewiththenewstatement.Itthenassignstheoutputport port,Parms.ClientPutLine,connectedtothelter'sinputportIn.<br />

aconnectstatement.Theconnectstatementisthe<strong>Hermes</strong>primitivefor examples,thelterhasrealworktodoafterreturningtheinitialization nolongerbeinitializedafterthereturnstatement.Unliketheprevious call|itmustservicePutLinecallsfromitsclient. intolocalvariables.ThisisnecessarybecausethecallmessageParmswill Aftersavingthetwovariablesitneeds,ittheninitializesitsinputport TheinitializationcoderstcopiesParms.PutLine<strong>and</strong>Parms.Prefix<br />

creatingconnectionsbetweenoutputports<strong>and</strong>inputports.Itnowreturns connectedtothelter'sinputportIn. theinitializationcallmessage.Thiscallmessagewillcontainanoutputport control"asitwouldinalanguagewithoutmultipleprocesses.Thereturn thesecallswithtransformeddata.Wecodethisasaninnitewhileloop. statementmarkstheendoftheinitializationsectionofthelter,<strong>and</strong>the beginningofitsmainsection. withanargumentcomputedbyprexingtheoriginalstringwithastring Ateachiterationoftheloop,wedequeueasinglecallmessageintovariable PutLineCM.Thenweservicethecallbycallingthe`real'PutLineservice Recallthatthereturnstatementreturnsamessage;itdoesnot\transfer<br />

prex<strong>and</strong>acolon.Finally,wereturntheoriginalcallmessage.Thelterwill runindenitelyuntilitsconnectionissevered.We'llseeinalatersection howthisisdone. ThemainjobofthelteristoreceivecallsoninputportIn,<strong>and</strong>reissue Nowlet'slookatthecodeoftheparentprocess,Compound.Thisprocess

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!