Skip to content

Instantly share code, notes, and snippets.

@takscape
Created October 8, 2011 14:15
Show Gist options
  • Save takscape/1272336 to your computer and use it in GitHub Desktop.
Save takscape/1272336 to your computer and use it in GitHub Desktop.
Scala: Esper
import com.espertech.esper.client.{Configuration, EventBean, UpdateListener, EPServiceProviderManager}
import java.util.HashMap
import scala.collection.JavaConversions._
object Sandbox
{
def main(args: Array[String]) {
val config = new Configuration();
val eventType = new HashMap[String, AnyRef]()
eventType.put("itemName", classOf[String])
eventType.put("price", classOf[Double])
config.addEventType("OrderEvent", eventType)
val epService = EPServiceProviderManager.getDefaultProvider(config);
val expression = "select avg(price) from OrderEvent.win:time(30 sec)";
val statement = epService.getEPAdministrator.createEPL(expression);
statement.addListener(new UpdateListener {
def update(newEvents: Array[EventBean], oldEvents: Array[EventBean]) {
val event = newEvents(0)
println("avg=" + event.get("avg(price)"))
}
})
epService.getEPRuntime.sendEvent(Map("itemName" -> "shirt", "price" -> 74.5), "OrderEvent")
epService.getEPRuntime.sendEvent(Map("itemName" -> "shirt", "price" -> 60.5), "OrderEvent")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment