本文整理汇总了Java中com.espertech.esper.client.EPStatement.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java EPStatement.addListener方法的具体用法?Java EPStatement.addListener怎么用?Java EPStatement.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.espertech.esper.client.EPStatement
的用法示例。
在下文中一共展示了EPStatement.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEsper
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
@Test
public void testEsper() {
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider();
engine.getEPAdministrator().getConfiguration().addEventType(TestEvent.class);
String query = "select name, age from TestEvent";
EPStatement statement = engine.getEPAdministrator().createEPL(query);
statement.addListener((newData, oldData) -> {
String name = (String) newData[0].get("name");
int age = (int) newData[0].get("age");
System.out.println(name + " " + age);
});
engine.getEPRuntime().sendEvent(new TestEvent("peter", 10));
}
示例2: addStatementToEngine
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
/**
* Add a EPL statement and a listener to it.
*
* @param stmtName statement name
* @param stmt statement
* @param listenerName statement listener.
*/
private void addStatementToEngine(String stmtName, String stmt, String listenerName) {
EPStatement oldStmt = epService.getEPAdministrator().getStatement(stmtName);
if (oldStmt != null) {
if (stmt.equalsIgnoreCase(oldStmt.getText())) {
return;
} else {
oldStmt.destroy();
}
}
EPStatement statement = epService.getEPAdministrator().createEPL(stmt, stmtName);
if (listenerName != null) {
statement.addListener(listeners.get(listenerName));
}
logger.debug("Loaded to Esper EPL: " + stmt);
}
示例3: testTimestamp
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
@Test
public void testTimestamp() {
final Configuration cepConfig = new Configuration();
cepConfig.addEventType("Event", EapEvent.class.getName());
final EPServiceProvider cep = EPServiceProviderManager.getProvider("myCEPEngine", cepConfig);
final EPRuntime cepRT = cep.getEPRuntime();
final EPAdministrator cepAdm = cep.getEPAdministrator();
// create statement
final EPStatement timeStatement = cepAdm.createEPL("select count(*) from Event.win:time(1 hour)");
timeStatement.addListener(new CEPListener());
// create events
final List<EapEvent> ratingEvents = this.createRatingEvents();
this.sortEventListByDate(ratingEvents);
// pass events to Esper engine
for (final EapEvent event : ratingEvents) {
cepRT.sendEvent(new TimerControlEvent(TimerControlEvent.ClockType.CLOCK_EXTERNAL));
// System.out.println(new
// CurrentTimeEvent(event.getTimestamp().getTime()).toString());
cepRT.sendEvent(new CurrentTimeEvent(event.getTimestamp().getTime()));
cepRT.sendEvent(event);
}
}
示例4: runAssertionSubqueryParam
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionSubqueryParam(EPServiceProvider epService) throws Exception {
String epl = "expression double js:myJSFunc(stringvalue) [\n" +
" calcScore(stringvalue);\n" +
" function calcScore(stringvalue) {\n" +
" return parseFloat(stringvalue);\n" +
" }\n" +
"]\n" +
"select myJSFunc((select theString from SupportBean#lastevent)) as c0 from SupportBean_S0";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new SupportBean("20", 0));
epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
assertEquals(20d, listener.assertOneGetNewAndReset().get("c0"));
epService.getEPRuntime().sendEvent(new SupportBean("30", 0));
epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
assertEquals(30d, listener.assertOneGetNewAndReset().get("c0"));
stmt.destroy();
}
示例5: runAssertionIntersectPattern
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionIntersectPattern(EPServiceProvider epService) {
String[] fields = new String[]{"theString"};
String text = "select irstream a.p00||b.p10 as theString from pattern [every a=SupportBean_S0 -> b=SupportBean_S1]#unique(a.id)#unique(b.id) retain-intersection";
EPStatement stmt = epService.getEPAdministrator().createEPL(text);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "E1"));
epService.getEPRuntime().sendEvent(new SupportBean_S1(2, "E2"));
EPAssertionUtil.assertPropsPerRowAnyOrder(stmt.iterator(), fields, toArr("E1E2"));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1E2"});
epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E3"));
epService.getEPRuntime().sendEvent(new SupportBean_S1(20, "E4"));
EPAssertionUtil.assertPropsPerRowAnyOrder(stmt.iterator(), fields, toArr("E1E2", "E3E4"));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E3E4"});
epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "E5"));
epService.getEPRuntime().sendEvent(new SupportBean_S1(2, "E6"));
EPAssertionUtil.assertPropsPerRowAnyOrder(stmt.iterator(), fields, toArr("E3E4", "E5E6"));
EPAssertionUtil.assertProps(listener.assertOneGetOld(), fields, new Object[]{"E1E2"});
EPAssertionUtil.assertProps(listener.assertOneGetNew(), fields, new Object[]{"E5E6"});
stmt.destroy();
}
示例6: tryAssertionNoTerminationConditionOverlapping
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void tryAssertionNoTerminationConditionOverlapping(EPServiceProvider epService, boolean soda) {
SupportModelHelper.createByCompileOrParse(epService, soda, "create context SupportBeanInstanceCtx as initiated by SupportBean as sb");
EPStatement stmt = SupportModelHelper.createByCompileOrParse(epService, soda, "context SupportBeanInstanceCtx " +
"select id, context.sb.intPrimitive as sbint, context.startTime as starttime, context.endTime as endtime from SupportBean_S0(p00=context.sb.theString)");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
String[] fields = "id,sbint,starttime,endtime".split(",");
epService.getEPRuntime().sendEvent(new SupportBean("P1", 100));
epService.getEPRuntime().sendEvent(new SupportBean("P2", 200));
epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "P2"));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{10, 200, 5L, null});
epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "P1"));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{20, 100, 5L, null});
epService.getEPAdministrator().destroyAllStatements();
}
示例7: validate
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void validate(EPServiceProvider epService, String select, Object expected) {
String epl = "select " + select + " as result from SupportBean";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new SupportBean("E1", 0));
Object result = listener.assertOneGetNewAndReset().get("result");
if (expected instanceof Object[]) {
Object[] returned = ((Collection) result).toArray();
EPAssertionUtil.assertEqualsExactOrder((Object[]) expected, returned);
} else {
assertEquals(expected, result);
}
stmt.destroy();
}
示例8: runAssertionRoot_s0
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionRoot_s0(EPServiceProvider epService) {
/**
* Query:
*
* -> s1
* s0 -> s2
* -> s3
*/
String epl = "select * from " +
EVENT_S0 + "#length(1000) as s0 " +
" left outer join " + EVENT_S1 + "#length(1000) as s1 on s0.p00 = s1.p10 " +
" left outer join " + EVENT_S2 + "#length(1000) as s2 on s0.p00 = s2.p20 " +
" left outer join " + EVENT_S3 + "#length(1000) as s3 on s0.p00 = s3.p30 ";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
tryAssertion(epService, listener);
}
示例9: runAssertionOA
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionOA(EPServiceProvider epService) {
epService.getEPAdministrator().createEPL("create objectarray schema OAEventInner(p0 string)");
epService.getEPAdministrator().createEPL("create objectarray schema OAEvent(intarray int[], oainner OAEventInner[])");
EPStatement stmt = epService.getEPAdministrator().createEPL("select * from OAEvent");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
Object[] oainner = new Object[] {new Object[] {"A"}, new Object[] {"B"}};
epService.getEPRuntime().sendEvent(new Object[] {new int[] {1, 2}, oainner}, "OAEvent");
EventBean event = listener.assertOneGetNewAndReset();
EventType type = event.getEventType();
assertEquals(2, type.getGetterIndexed("intarray").get(event, 1));
assertNull(type.getGetterIndexed("dummy"));
assertEquals(oainner[1], type.getGetterIndexed("oainner").get(event, 1));
stmt.destroy();
}
示例10: runAssertionTermByFilterWSubtype
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionTermByFilterWSubtype(EPServiceProvider epService) {
EPStatement ctx = epService.getEPAdministrator().createEPL("create context ByP0 partition by a from ISupportA, b from ISupportB terminated by ISupportA(a='x')");
EPStatement stmt = epService.getEPAdministrator().createEPL("context ByP0 select coalesce(a.a, b.b) as p0, count(*) as cnt from pattern[every (a=ISupportA or b=ISupportB)]");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new ISupportABCImpl("a", "a", null, null));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), "p0,cnt".split(","), new Object[] {"a", 1L});
epService.getEPRuntime().sendEvent(new ISupportAImpl("a", null));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), "p0,cnt".split(","), new Object[] {"a", 2L});
epService.getEPRuntime().sendEvent(new ISupportBImpl("a", null));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), "p0,cnt".split(","), new Object[] {"a", 3L});
ctx.destroy();
stmt.destroy();
}
示例11: runAssertionMathContextBigDecConvDivide
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private void runAssertionMathContextBigDecConvDivide(EPServiceProvider epService) {
String epl = "select " +
"10/BigDecimal.valueOf(5,0) as c0" +
" from SupportBean";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
String[] fields = "c0".split(",");
assertEquals(BigDecimal.class, stmt.getEventType().getPropertyType("c0"));
epService.getEPRuntime().sendEvent(new SupportBean());
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {BigDecimal.valueOf(2,0)});
stmt.destroy();
}
示例12: getServiceProvider
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
private EPServiceProvider getServiceProvider(String context) throws IOException {
EPServiceProvider serviceProvider = engineState.value();
if (serviceProvider != null) {
return serviceProvider;
}
synchronized (lock) {
serviceProvider = engineState.value();
if (serviceProvider == null) {
Configuration configuration = new Configuration();
configuration.getEngineDefaults().getThreading().setInternalTimerEnabled(false);
serviceProvider = EPServiceProviderManager.getProvider(context, configuration);
serviceProvider.getEPAdministrator().getConfiguration().addEventType(inputType.getTypeClass());
serviceProvider.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
EPStatement statement = query.createStatement(serviceProvider.getEPAdministrator());
statement.addListener((newData, oldData) -> {
for (EventBean event : newData) {
EsperSelectFunction<OUT> userFunction = getUserFunction();
try {
output.collect(new StreamRecord<>((userFunction.select(event))));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
this.engineState.update(serviceProvider);
return serviceProvider;
} else {
return engineState.value();
}
}
}
示例13: create
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
@RequestMapping(value = "/statements",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<StatementDTO> create(@Valid @RequestBody StatementDTO statementDTO) throws URISyntaxException {
EPStatement statement = epService.getEPAdministrator().createEPL(statementDTO.getStatement(), statementDTO.getName());
statement.addListener(statementListener);
StatementDTO dto = StatementMapper.fromStatement(statement);
return ResponseEntity.created(new URI("/api/statements/" + dto.getName()))
.body(dto);
}
示例14: EsperOperation
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
public EsperOperation() {
Configuration cepConfig = new Configuration();
cepConfig.addEventType("StockTick", Stock.class.getName());
EPServiceProvider cep = EPServiceProviderManager.getProvider(
"myCEPEngine", cepConfig);
cepRT = cep.getEPRuntime();
EPAdministrator cepAdm = cep.getEPAdministrator();
EPStatement cepStatement = cepAdm
.createEPL("select sum(price),product from "
+ "StockTick.win:time_batch(5 sec) "
+ "group by product");
cepStatement.addListener(new CEPListener());
}
示例15: addLiveQuery
import com.espertech.esper.client.EPStatement; //导入方法依赖的package包/类
/**
* registers live query to Esper and starts a listener to it
*
* @param liveQuery
* @return Listener which will get notifications if live-query gets
* triggered
*/
public LiveQueryListener addLiveQuery(final QueryWrapper liveQuery) throws EPException {
final String statementName = ++this.statementID + "_" + liveQuery.getTitle();
liveQuery.setStatementName(statementName);
final EPStatement newStatement = this.esperServiceProvider.getEPAdministrator().createEPL(liveQuery.getEsperQuery(), statementName);
final LiveQueryListener listener = new LiveQueryListener(liveQuery);
newStatement.addListener(listener);
this.statementNames.put(statementName, liveQuery);
return listener;
}