Apama 10.15.0 | 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() {
on all Translation() as t addTranslation(t);
on all Input() as i translate(i);
   }
   action addTranslation(Translation t) {
      translations[t.raw] := t.converted ;
   }
   action translate(Input i) {
      if translations.hasKey(i.value) {
         send Output( translations[i.value] ) to "output";
      }
      else { fail(i); }
   }
   action fail(Input i ) {
      print "Cannot translate: " + i.value;
   }
}