本文整理汇总了Java中com.espertech.esper.client.EPServiceProvider类的典型用法代码示例。如果您正苦于以下问题:Java EPServiceProvider类的具体用法?Java EPServiceProvider怎么用?Java EPServiceProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EPServiceProvider类属于com.espertech.esper.client包,在下文中一共展示了EPServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEsper
import com.espertech.esper.client.EPServiceProvider; //导入依赖的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: main
import com.espertech.esper.client.EPServiceProvider; //导入依赖的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);
}
示例3: testTimestamp
import com.espertech.esper.client.EPServiceProvider; //导入依赖的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: run
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
public void run(EPServiceProvider epService) throws Exception {
String stmtText = "select istream myint from " +
" sql:MyDB ['select myint from mytesttable where ${intPrimitive} = mytesttable.mybigint'] as s0," +
SupportBean.class.getName() + " as s1";
EPStatement statement = epService.getEPAdministrator().createEPL(stmtText);
String[] fields = new String[]{"myint"};
SupportUpdateListener listener = new SupportUpdateListener();
statement.addListener(listener);
sendSupportBeanEvent(epService, 10);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{100});
sendSupportBeanEvent(epService, 6);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{60});
long startTime = System.currentTimeMillis();
// Send 100 events which all fireStatementStopped a join
for (int i = 0; i < 100; i++) {
sendSupportBeanEvent(epService, 10);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{100});
}
long endTime = System.currentTimeMillis();
log.info("delta=" + (endTime - startTime));
assertTrue(endTime - startTime < 5000);
}
示例5: tryAssertionMatchUntilRangeOpWTime
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void tryAssertionMatchUntilRangeOpWTime(EPServiceProvider epService) {
String[] fields = "a1.id,aarr[0].id".split(",");
sendTime(epService, 0);
SupportUpdateListener listener = new SupportUpdateListener();
epService.getEPAdministrator().createEPL("select * from pattern " + TargetEnum.DISCARD_ONLY.getText() + "[" +
"every a1=A -> ([:100] aarr=A until (timer:interval(10 sec) and not b=B))]").addListener(listener);
sendAEvent(epService, "A1");
sendTime(epService, 1000);
sendAEvent(epService, "A2");
sendTime(epService, 10000);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"A1", "A2"});
sendTime(epService, 11000);
assertFalse(listener.isInvoked());
epService.getEPAdministrator().destroyAllStatements();
}
示例6: sendAndAwait
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void sendAndAwait(EPServiceProvider epService, KafkaConsumer<String, String> consumer, String eventId) {
// send event
String uniqueId = eventId + "___" + UUID.randomUUID().toString();
epService.getEPRuntime().sendEvent(new SupportBean(uniqueId, 10));
// await
SupportAwaitUtil.awaitOrFail(10, TimeUnit.SECONDS, "failed to receive expected event", (Supplier<Object>) () -> {
ConsumerRecords<String, String> rows = consumer.poll(1000);
Iterator<ConsumerRecord<String, String>> it = rows.iterator();
boolean found = false;
while (it.hasNext()) {
ConsumerRecord<String, String> row = it.next();
log.info("Received: {}", row.value());
if (row.value().contains(uniqueId)) {
found = true;
}
}
return found ? true : null;
});
}
示例7: runAssertionInsertTransposeNestedProperty
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionInsertTransposeNestedProperty(EPServiceProvider epService) {
String stmtOneText = "insert into StreamA select nested.* from " + SupportBeanComplexProps.class.getName() + " as s0";
SupportUpdateListener listenerOne = new SupportUpdateListener();
EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneText);
stmtOne.addListener(listenerOne);
assertEquals(SupportBeanComplexProps.SupportBeanSpecialGetterNested.class, stmtOne.getEventType().getUnderlyingType());
String stmtTwoText = "select nestedValue from StreamA";
SupportUpdateListener listenerTwo = new SupportUpdateListener();
EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoText);
stmtTwo.addListener(listenerTwo);
assertEquals(String.class, stmtTwo.getEventType().getPropertyType("nestedValue"));
epService.getEPRuntime().sendEvent(SupportBeanComplexProps.makeDefaultBean());
assertEquals("nestedValue", listenerOne.assertOneGetNewAndReset().get("nestedValue"));
assertEquals("nestedValue", listenerTwo.assertOneGetNewAndReset().get("nestedValue"));
stmtOne.destroy();
stmtTwo.destroy();
}
示例8: runAssertionRowPerEventSumHaving
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionRowPerEventSumHaving(EPServiceProvider epService) {
String statementString = "select symbol, sum(price) from " +
SupportMarketDataBean.class.getName() + "#length(10) " +
"having sum(price) > 0 " +
"output every 6 events " +
"order by symbol";
SupportUpdateListener listener = new SupportUpdateListener();
EPStatement statement = epService.getEPAdministrator().createEPL(statementString);
statement.addListener(listener);
sendEvent(epService, "IBM", 3);
sendEvent(epService, "IBM", 4);
sendEvent(epService, "CMU", 1);
sendEvent(epService, "CMU", 2);
sendEvent(epService, "CAT", 5);
sendEvent(epService, "CAT", 6);
String[] fields = "symbol,sum(price)".split(",");
EPAssertionUtil.assertPropsPerRow(listener.getLastNewData(), fields, new Object[][]{
{"CAT", 15.0}, {"CAT", 21.0}, {"CMU", 8.0}, {"CMU", 10.0}, {"IBM", 3.0}, {"IBM", 7.0}});
statement.destroy();
}
示例9: runAssertion1Stream3HistForwardSubordinate
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertion1Stream3HistForwardSubordinate(EPServiceProvider epService) {
String expression;
expression = "select s0.id as id, h0.val as valh0, h1.val as valh1, h2.val as valh2 " +
"from SupportBeanInt#keepall as s0, " +
"method:SupportJoinMethods.fetchVal('H0', p00) as h0, " +
"method:SupportJoinMethods.fetchVal('H1', p01) as h1, " +
"method:SupportJoinMethods.fetchVal(h0.val||'H2', p02) as h2 " +
" where h0.index = h1.index and h1.index = h2.index and h2.index = p03";
tryAssertionFour(epService, expression);
expression = "select s0.id as id, h0.val as valh0, h1.val as valh1, h2.val as valh2 from " +
"method:SupportJoinMethods.fetchVal(h0.val||'H2', p02) as h2, " +
"method:SupportJoinMethods.fetchVal('H0', p00) as h0, " +
"SupportBeanInt#keepall as s0, " +
"method:SupportJoinMethods.fetchVal('H1', p01) as h1 " +
" where h0.index = h1.index and h1.index = h2.index and h2.index = p03";
tryAssertionFour(epService, expression);
}
示例10: runAssertionVariables
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionVariables(EPServiceProvider epService) {
String[] fields = "myvar".split(",");
SubscriberMap subscriberCreateVariable = new SubscriberMap();
String stmtTextCreate = "create variable string myvar = 'abc'";
EPStatement stmt = epService.getEPAdministrator().createEPL(stmtTextCreate);
stmt.setSubscriber(subscriberCreateVariable);
SubscriberMap subscriberSetVariable = new SubscriberMap();
String stmtTextSet = "on SupportBean set myvar = theString";
stmt = epService.getEPAdministrator().createEPL(stmtTextSet);
stmt.setSubscriber(subscriberSetVariable);
epService.getEPRuntime().sendEvent(new SupportBean("def", 1));
EPAssertionUtil.assertPropsMap(subscriberCreateVariable.getAndResetIndicate().get(0), fields, new Object[]{"def"});
EPAssertionUtil.assertPropsMap(subscriberSetVariable.getAndResetIndicate().get(0), fields, new Object[]{"def"});
stmt.destroy();
}
示例11: runAssertionRoot_s3
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionRoot_s3(EPServiceProvider epService) {
/**
* Query:
*
* -> s1
* s0 -> s2
* -> s3
*/
String epl = "select * from " +
EVENT_S3 + "#length(1000) as s3 " +
" right outer join " + EVENT_S0 + "#length(1000) as s0 on s0.p00 = s3.p30 " +
" 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 ";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
tryAssertion(epService, listener);
}
示例12: createStmt
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
public static void createStmt(EPServiceProvider epService,
int secTimeout,
UpdateListener listener) {
String textOne = "insert into CountZone " +
"select zone, count(*) as cnt " +
"from LocationReport#unique(assetId) " +
"where assetId in ('A1', 'A2', 'A3') " +
"group by zone";
EPStatement stmtOne = epService.getEPAdministrator().createEPL(textOne);
stmtOne.addListener(new UpdateListener() {
public void update(EventBean[] newEvents, EventBean[] oldEvents) {
for (int i = 0; i < newEvents.length; i++) {
System.out.println("Summary: zone " + newEvents[i].get("zone") +
" now has count " + newEvents[i].get("cnt"));
}
}
});
String textTwo = "select Part.zone from pattern [" +
" every Part=CountZone(cnt in (1,2)) ->" +
" (timer:interval(" + secTimeout + " sec) " +
" and not CountZone(zone=Part.zone, cnt in (0,3)))]";
EPStatement stmtTwo = epService.getEPAdministrator().createEPL(textTwo);
stmtTwo.addListener(listener);
}
示例13: runAssertionAggregatedSelectUnaggregatedHaving
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionAggregatedSelectUnaggregatedHaving(EPServiceProvider epService) {
// ESPER-571
epService.getEPAdministrator().getConfiguration().addEventType("SupportBean", SupportBean.class);
String epl = "select max(intPrimitive) as val from SupportBean#time(1) having max(intPrimitive) > intBoxed";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
sendEvent(epService, "E1", 10, 1);
assertEquals(10, listener.assertOneGetNewAndReset().get("val"));
sendEvent(epService, "E2", 10, 11);
assertFalse(listener.isInvoked());
sendEvent(epService, "E3", 15, 11);
assertEquals(15, listener.assertOneGetNewAndReset().get("val"));
sendEvent(epService, "E4", 20, 11);
assertEquals(20, listener.assertOneGetNewAndReset().get("val"));
sendEvent(epService, "E5", 25, 25);
assertFalse(listener.isInvoked());
stmt.destroy();
}
示例14: runAssertionMinMax
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
private void runAssertionMinMax(EPServiceProvider epService) {
EPStatement stmt = epService.getEPAdministrator().createEPL("select " +
"min(longPrimitive).before(max(longBoxed), 1 second) as c0," +
"min(longPrimitive, longBoxed).before(20000L, 1 second) as c1" +
" from SupportBean#length(2)");
SupportUpdateListener listener = new SupportUpdateListener();
stmt.addListener(listener);
String[] fields = "c0,c1".split(",");
sendBean(epService, 20000, 20000);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {false, false});
sendBean(epService, 19000, 20000);
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {true, true});
stmt.destroy();
}
示例15: run
import com.espertech.esper.client.EPServiceProvider; //导入依赖的package包/类
public void run(EPServiceProvider epService) throws Exception {
PlugInEventRepresentationContext initContext = SupportEventRepresentation.getInitContext();
assertEquals(new URI("type://test/support"), initContext.getEventRepresentationRootURI());
assertEquals("abc", initContext.getRepresentationInitializer());
assertNotNull(initContext.getEventAdapterService());
ConfigurationOperations runtimeConfig = epService.getEPAdministrator().getConfiguration();
runtimeConfig.addPlugInEventType("TestTypeOne", new URI[]{new URI("type://test/support?a=b&c=d")}, "t1");
PlugInEventTypeHandlerContext plugincontext = SupportEventRepresentation.getAcceptTypeContext();
assertEquals(new URI("type://test/support?a=b&c=d"), plugincontext.getEventTypeResolutionURI());
assertEquals("t1", plugincontext.getTypeInitializer());
assertEquals("TestTypeOne", plugincontext.getEventTypeName());
plugincontext = SupportEventRepresentation.getEventTypeContext();
assertEquals(new URI("type://test/support?a=b&c=d"), plugincontext.getEventTypeResolutionURI());
assertEquals("t1", plugincontext.getTypeInitializer());
assertEquals("TestTypeOne", plugincontext.getEventTypeName());
epService.getEPRuntime().getEventSender(new URI[]{new URI("type://test/support?a=b")});
PlugInEventBeanReflectorContext contextBean = SupportEventRepresentation.getEventBeanContext();
assertEquals("type://test/support?a=b", contextBean.getResolutionURI().toString());
}