Apama Documentation : Developing Apama Applications : Developing Apama Applications in EPL : Common EPL Patterns in Monitors : Contrasting using a dictionary with spawning : Translation using a dictionary
Translation using a dictionary
The events to be processed:
event Input { string value; }
event Output { string value; }
event Translation {
   string raw;
   string converted;
}
The monitor:
monitor Translator {
   dictionary < string, string > translations;
 
   action onload() {
      Translation t;
on all Translation():t addTranslation(t);
      Input i;
on all Input():i translate(i);
   }
   action addTranslation(Translation t) {
      translations[t.raw] := t.converted ;
   }
   action translate(Input i) {
      if translations.hasKey(i.value) then {
         send Output( translations[i.value] ) to "output";
      }
      else { fail(i); }
   }
   action fail(Input i ) {
      print "Cannot translate: " + i.value;
   }
}
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback