Skip to content

Instantly share code, notes, and snippets.

@ghiden
Created September 7, 2010 06:26
Show Gist options
  • Save ghiden/567951 to your computer and use it in GitHub Desktop.
Save ghiden/567951 to your computer and use it in GitHub Desktop.
// based on the java source listed here http://d.hatena.ne.jp/fits/20081126/1227660571
package sample.event
class EsperEvent(val name: String, val point: Int) {
def getName:String = name
def getPoint:Int = point
}
// based on the java source listed here http://d.hatena.ne.jp/fits/20081126/1227660571
package sample
import com.espertech.esper.client.EventBean
import com.espertech.esper.client.UpdateListener
class EsperListener extends UpdateListener {
def update(newEvents: Array[EventBean], oldEvents: Array[EventBean]) = {
if (newEvents != Nil && newEvents.length > 0) {
println("event : " + newEvents(0).get("name") + ", " + newEvents(0).get("point"))
}
}
}
// based on the java source listed here http://d.hatena.ne.jp/fits/20081126/1227660571
import com.espertech.esper.client.Configuration
import com.espertech.esper.client.EPServiceProvider
import com.espertech.esper.client.EPServiceProviderManager
import com.espertech.esper.client.EPStatement
import sample.event.EsperEvent
package sample {
object EsperProcessor {
def main(args: Array[String]) {
var config = new Configuration
config.addEventType("EsperEvent", classOf[EsperEvent])
val serv:EPServiceProvider = EPServiceProviderManager.getDefaultProvider(config)
val st:EPStatement = serv.getEPAdministrator().createEPL("select * from EsperEvent(point >= 5)")
st.addListener(new EsperListener)
for (i <- 1 to 10000) {
val v = (math.random * 10).asInstanceOf[Int]
serv.getEPRuntime().sendEvent(new EsperEvent("test" + i, v));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment