本文整理汇总了Java中com.espertech.esper.client.EPStatement类的典型用法代码示例。如果您正苦于以下问题:Java EPStatement类的具体用法?Java EPStatement怎么用?Java EPStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EPStatement类属于com.espertech.esper.client包,在下文中一共展示了EPStatement类的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: main
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Configuration config = new Configuration();
//config.addEventType("BasicEvent", BasicEvent.class);
config.addEventType("PerfEvent", PerfEvent.class);
/* If we gonna use custom timestamps - use this
ConfigurationEventTypeLegacy cetl = new ConfigurationEventTypeLegacy();
cetl.setStartTimestampPropertyName("timestamp");
cetl.setEndTimestampPropertyName("timestamp");
config.addEventType("PerfEvent", PerfEvent.class.getName(), cetl);
*/
// Get engine instance
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
String stmt = "insert into OpsEvent select ciId, 'cpu' as name, 'open' as state, 'count:' || cast(count(1),string) as cnt from PerfEvent.win:time(1 min) where metrics('cpu') > 10 group by ciId having count(1) > 0 output first every 3 minutes";
EPStatement statement = epService.getEPAdministrator().createEPL(stmt, "test");
assertTrue(statement != null);
}
示例4: removeEventType
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
/**
* deletes Eventype from Esper
*
* @param eventType
* @throws Exception
*/
public void removeEventType(final EapEventType eventType) {
// System.out.println(esperConfiguration.getEventTypeNameUsedBy(eventType.getTypeName()));
final Set<String> names = new HashSet<String>(this.esperConfiguration.getEventTypeNameUsedBy(eventType.getTypeName()));
for (final String statementName : names) {
final EPStatement statement = this.getStatement(statementName);
if (statement != null) {
statement.removeAllListeners();
statement.destroy();
}
final Object ruleOrQuery = this.statementNames.get(statementName);
if (ruleOrQuery != null) {
if (ruleOrQuery instanceof QueryWrapper) {
final QueryWrapper liveQuery = (QueryWrapper) ruleOrQuery;
liveQuery.remove();
} else if (ruleOrQuery instanceof TransformationRule) {
final TransformationRule rule = (TransformationRule) ruleOrQuery;
Broker.getInstance().remove(rule);
} else {
System.err.println("WARNING - Parent of statement '" + statementName + "' is neither transformation rule nor live query.");
}
this.statementNames.remove(statementName);
}
}
this.esperConfiguration.removeEventType(eventType.getTypeName(), true);
}
示例5: initializeWithTransformationRulesFromDB
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
/**
* Registers transformation rules that are stored in the database at the
* stream processing adapter.
*/
public void initializeWithTransformationRulesFromDB() {
for (final TransformationRule transformationRule : TransformationRule.findAll()) {
/*
* NOTE: one statement for each transformation rule
*
* other option would be: if the transformation rule is equal an
* existing one, a second listener (probably transforming to another
* event type but with the same attributes) would be added to the
* existing statement
*/
/*
* MH 2014-10-21: Only add a TransformationRule from the database if
* it not already registered with Esper
*/
final EPStatement statement = StreamProcessingAdapter.getInstance().getStatement(TransformationRuleLogic.generateStatementName(transformationRule));
if (statement == null) {
Broker.getInstance().register(transformationRule);
System.out.println("Registered transformation rule '" + transformationRule.getTitle() + "' for event type '" + transformationRule.getEventType().getTypeName() + "' from database.");
} else {
System.out.println("Transformation rule " + transformationRule.getTitle() + " already registered in Esper.");
}
}
}
示例6: 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);
}
}
示例7: buildViolationStatement
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
public static EPStatement buildViolationStatement(ServiceEvaluatorLink evaluator, EventLogMixin eventLog,
LengthWindowMetricMixin lengthWindow, String slo) {
logger.info("Start building length window violation statement ...");
// create the select clause
String expression = buildSelect(evaluator, eventLog);
// set the event stream
expression = expression + buildFrom(eventLog);
// set time window
expression = expression + buildLengthWindow(lengthWindow);
// build where clause
expression = expression + buildViolationWhere(evaluator, eventLog, slo);
// create new statement
EPServiceProvider epService = ComplexEventProcessor.getInstance().getProvider();
EPStatement statement = epService.getEPAdministrator().createEPL(expression);
logger.info("Finished building length window violation statement: " + expression);
return statement;
}
示例8: runAssertionIn
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void runAssertionIn(EPServiceProvider epService) {
EPStatement stmt = epService.getEPAdministrator().createEPL("select * from SupportBeanNumeric where bigdec in (10, 20d) or bigint in (0x02, 3)");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
sendBigNumEvent(epService, 0, 9);
assertFalse(listener.getAndClearIsInvoked());
sendBigNumEvent(epService, 0, 10);
assertTrue(listener.getAndClearIsInvoked());
epService.getEPRuntime().sendEvent(new SupportBeanNumeric(null, new BigDecimal(20d)));
assertTrue(listener.getAndClearIsInvoked());
sendBigNumEvent(epService, 99, 0);
assertFalse(listener.getAndClearIsInvoked());
sendBigNumEvent(epService, 2, 0);
assertTrue(listener.getAndClearIsInvoked());
sendBigNumEvent(epService, 3, 0);
assertTrue(listener.getAndClearIsInvoked());
stmt.destroy();
}
示例9: runOnMergeAndUpdateAndSelect
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void runOnMergeAndUpdateAndSelect(EPServiceProvider epService) {
epService.getEPAdministrator().createEPL("create window MyWindowMerge#keepall as (p0 string, p1 string)");
epService.getEPRuntime().executeQuery("insert into MyWindowMerge select 'a' as p0, 'b' as p1");
epService.getEPAdministrator().createEPL("on SupportBean_S0 merge MyWindowMerge as `order` when matched then update set `order`.p1 = `order`.p0");
epService.getEPAdministrator().createEPL("on SupportBean_S1 update MyWindowMerge as `order` set p0 = 'x'");
assertFAF(epService, "MyWindowMerge", "a", "b");
epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
assertFAF(epService, "MyWindowMerge", "a", "a");
epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "x"));
assertFAF(epService, "MyWindowMerge", "x", "a");
EPStatement stmt = epService.getEPAdministrator().createEPL("on SupportBean select `order`.p0 as c0 from MyWindowMerge as `order`");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
epService.getEPRuntime().sendEvent(new SupportBean());
assertEquals("x", listener.assertOneGetNewAndReset().get("c0"));
epService.getEPAdministrator().destroyAllStatements();
}
示例10: runAssertionHavingSum
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void runAssertionHavingSum(EPServiceProvider epService) {
String epl = "select irstream sum(myEvent.intPrimitive) as mysum from pattern [every myEvent=" + SupportBean.class.getName() +
"] having sum(myEvent.intPrimitive) = 2";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
sendEvent(epService, 1);
assertFalse(listener.isInvoked());
sendEvent(epService, 1);
assertEquals(2, listener.assertOneGetNewAndReset().get("mysum"));
sendEvent(epService, 1);
assertEquals(2, listener.assertOneGetOldAndReset().get("mysum"));
}
示例11: tryPattern
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void tryPattern(EPServiceProvider epService, String text,
Integer[] intBoxedA,
Double[] doubleBoxedA,
Integer[] intBoxedB,
Double[] doubleBoxedB,
boolean[] expected) {
assertEquals(intBoxedA.length, doubleBoxedA.length);
assertEquals(intBoxedB.length, doubleBoxedB.length);
assertEquals(expected.length, doubleBoxedA.length);
assertEquals(intBoxedA.length, doubleBoxedB.length);
for (int i = 0; i < intBoxedA.length; i++) {
EPStatement stmt = epService.getEPAdministrator().createEPL(text);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
sendBeanIntDouble(epService, intBoxedA[i], doubleBoxedA[i]);
sendBeanIntDouble(epService, intBoxedB[i], doubleBoxedB[i]);
assertEquals("failed at index " + i, expected[i], listener.getAndClearIsInvoked());
stmt.stop();
}
}
示例12: runAssertionRoot_s1
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void runAssertionRoot_s1(EPServiceProvider epService) {
/**
* Query:
*
* -> s1
* s0 -> s2
* -> s3
*/
String epl = "select * from " +
EVENT_S1 + "#length(1000) as s1 " +
" right outer join " + EVENT_S0 + "#length(1000) as s0 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);
}
示例13: run
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
public void run(EPServiceProvider epService) throws Exception {
epService.getEPAdministrator().getConfiguration().addVariable("var1", long.class, "12");
epService.getEPAdministrator().getConfiguration().addVariable("var2", Long.class, "2");
epService.getEPAdministrator().getConfiguration().addVariable("var3", Long.class, null);
long startTime = System.currentTimeMillis();
String stmtTextSet = "on pattern [every timer:interval(100 milliseconds)] set var1 = current_timestamp, var2 = var1 + 1, var3 = var1 + var2";
EPStatement stmtSet = epService.getEPAdministrator().createEPL(stmtTextSet);
SupportUpdateListener listenerSet = new SupportUpdateListener();
stmtSet.addListener(listenerSet);
Thread.sleep(1000);
stmtSet.destroy();
EventBean[] received = listenerSet.getNewDataListFlattened();
assertTrue("received : " + received.length, received.length >= 5);
for (int i = 0; i < received.length; i++) {
long var1 = (Long) received[i].get("var1");
long var2 = (Long) received[i].get("var2");
long var3 = (Long) received[i].get("var3");
assertTrue(var1 >= startTime);
assertEquals(var1, var2 - 1);
assertEquals(var3, var2 + var1);
}
}
示例14: handleGetAllEventsProperty
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
protected List<Object> handleGetAllEventsProperty(String strategyName, String ruleName, String property) throws Exception {
EPStatement statement = getServiceProvider(strategyName).getEPAdministrator().getStatement(ruleName);
List<Object> list = new ArrayList<Object>();
if (statement != null && statement.isStarted()) {
SafeIterator<EventBean> it = statement.safeIterator();
try {
while (it.hasNext()) {
EventBean bean = it.next();
Object underlaying = bean.get(property);
list.add(underlaying);
}
} finally {
it.close();
}
}
return list;
}
示例15: runAssertionPreviousLengthWindowWhere
import com.espertech.esper.client.EPStatement; //导入依赖的package包/类
private void runAssertionPreviousLengthWindowWhere(EPServiceProvider epService) {
String epl = "select prev(2, symbol) as currSymbol " +
"from " + SupportMarketDataBean.class.getName() + "#length(100) " +
"where prev(2, price) > 100";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
sendMarketEvent(epService, "A", 1);
sendMarketEvent(epService, "B", 130);
sendMarketEvent(epService, "C", 10);
assertFalse(listener.isInvoked());
sendMarketEvent(epService, "D", 5);
assertEquals("B", listener.assertOneGetNewAndReset().get("currSymbol"));
stmt.destroy();
}