throw new IllegalArgumentException("The sub sessionizer referenced by EPL " + sessionizerName + " not configured."); statement.addListener(new SubSessionizerListener(sessionizerName, context)); statement.addListener(new UpdateTTLListener(context, maxTTL)); statement.addListener(new DecorateEventListener(context)); statement.addListener(new AppendStateListener(context, (String) getAnnotationValue(part, "name", null), (String) getAnnotationValue(part, "colname", null), (Boolean) getAnnotationValue(part, "unique", true), statement.addListener(new SessionStateListener(context)); statement.addListener(new SessionMetadataListener(context)); statement.addListener(new SessionCounterListener((String) part.getAttributes().get(0).getValue(), context)); String field = (String) getAnnotationValue(part, "colname", null); Boolean auditValue = (Boolean) getAnnotationValue(part, "audit", false); statement.addListener(new SessionizerCounterListener(prefix, field, auditValue, esperCounter)); statement.addListener(ext.createUpdateListener(context, part, model));
auditValue = Boolean.FALSE; statement.addListener(new SessionizerCounterListener(prefix, field, auditValue, esperCounter)); statement.addListener(eventListener); + " not configured."); statement.addListener(new SessionizerListener(sessionizerName, sessionizationMap));
@Override protected void doStart() throws Exception { statement.addListener(this); }
/** * Adds an listener to the underlying native EPStatement. * * @param listener * the listener to add */ private void addEPStatementListener(UpdateListener listener) { if (this.subscriber == null) { if (epStatement != null) { epStatement.addListener(listener); } } }
EPStatement cepStatementRule3 = cepRule3.createEPL("every(HeartRate(heartrate>160) -> (timer:interval(5 min) and not HeartRate(heartrate<=160))"); cepStatementRule3.addListener(new rule3Listener());
/** * registers debug listeners for every statement */ @SuppressWarnings("unused") private void buildDebugListeners() { // a debug listener for every statement EPStatement statement; for (String key : this.epStatements.keySet()) { statement = this.epStatements.get(key); statement.addListener(new DebugListener()); } }
String statement = "SELECT datastream.column1, rel.column2" + "FROM Datastream.Measure AS datastream, " + "sql:database_alias ['SELECT column2 " + "FROM \"SchemaX\".\"TableY\" ] AS rel"; //Install this query in the engine EPStatement queryEngineObject = esperEngine.getEPAdministrator().createEPL(statement); //Associate a Listener to this query MyQueryListener listener = new MyQueryListener(); //that implements UpdateListener Interface queryEngineObject.addListener(listener);
/** * Sets the native Esper statement. Typically created by an Esper Template. * * @param epStatement * the underlying native Esper statement * @see org.opencredo.esper.EsperTemplate */ void setEPStatement(EPStatement epStatement) { this.epStatement = epStatement; if (this.subscriber != null) { epStatement.setSubscriber(this.subscriber); } else { for (UpdateListener listener : listeners) { epStatement.addListener(listener); } } }
/** * initializes the counting listeners */ private synchronized void initializeCountingListeners() { // for every statement in the map EPStatement epStatement; CountingListener cListener; for (String statement : this.countingListeners.keySet()) { cListener = this.countingListeners.get(statement); // register statement at engine epStatement = this.epService.getEPAdministrator().createEPL( statement); // register listener at esper statement epStatement.addListener(cListener); // store epStatements this.epStatements.put(statement, epStatement); } }
private void processAnnotations(EPStatement statement) throws Exception { Annotation[] annotations = statement.getAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Subscriber) { Subscriber subscriber = (Subscriber) annotation; Object obj = getSubscriber(subscriber.className()); statement.setSubscriber(obj); } else if (annotation instanceof Listeners) { Listeners listeners = (Listeners) annotation; for (String className : listeners.classNames()) { Class<?> cl = Class.forName(className); Object obj = cl.newInstance(); if (obj instanceof StatementAwareUpdateListener) { statement.addListener((StatementAwareUpdateListener) obj); } else { statement.addListener((UpdateListener) obj); } } } } }
public void recreateEpl(int eplId, Epl epl) { EPStatement epStatement = eplStateMap.get(eplId); if(epStatement != null && !epStatement.isDestroyed()) { epStatement.removeAllListeners(); epStatement.destroy(); } String eplSql = epl.getEplSql(); String[] eplSqls = eplSql.trim().split(";"); for(int i = 0; i < eplSqls.length; i++) { if(!StringUtils.isBlank(eplSqls[i])) { if(i == eplSqls.length - 1) { epStatement = this.admin.createEPL(eplSqls[i].trim()); LOG.info("Add statistic epl : " + eplSql); if(epStatement != null) eplStateMap.put(epl.getId(), epStatement); } else { admin.createEPL(eplSqls[i].trim()); } } } epStatement.addListener(new StatisticListener(epl, collector)); LOG.info("Recreate statistic epl : " + eplSql); }
public EPLManager addEpls() { this.allEpls = DBUtils.qetAllEpls(null); Collection<Epl> epls = allEpls.values(); EPStatement state = null; String eplSql = null; for(Epl epl : epls) { eplSql = epl.getEplSql(); String[] eplSqls = eplSql.trim().split(";"); for(int i = 0; i < eplSqls.length; i++) { if(!StringUtils.isBlank(eplSqls[i])) { if(i == eplSqls.length - 1) { LOG.info("Add statistic epl : " + eplSql + ", name: " + epl.getEplName()); state = this.admin.createEPL(eplSqls[i].trim()); state.addListener(new StatisticListener(epl, collector)); LOG.info("Add statistic epl : " + eplSql + ", name: " + epl.getEplName()); if(state != null) eplStateMap.put(epl.getId(), state); } else { admin.createEPL(eplSqls[i].trim()); } } } } return this; }
public void recreateEpl(int eplId, AlarmEpl epl) { EPStatement epStatement = eplStateMap.get(eplId); if(epStatement != null) { epStatement.removeAllListeners(); epStatement.destroy(); } String eplSql = epl.getEplSql(); epStatement = this.admin.createEPL(eplSql); epStatement.addListener(new AlertListener(epl.getAlarmEplId(), epl.getEplId(), epl.getEplName(), epl.getAlarm())); if(epStatement != null) eplStateMap.put(epl.getAlarmEplId(), epStatement); LOG.info("Recreate EPl : " + eplSql); }
private static void enableMetrics() { engineMetrics.addListener(new UpdateListener() { statementMetrics.addListener(new UpdateListener() {
@Override public void prepare(Map stormConf, TopologyContext context) { log.info("----------股票策略1(大卖盘)初始化..."); Configuration configuration = new Configuration(); configuration.addEventType("StockRealTimeEvent", StockRealTimeEvent.class.getName()); epService = EPServiceProviderManager.getProvider("strategy1",configuration); //提取出卖盘口远大于买盘口的行情数据 EPStatement stmt = epService.getEPAdministrator() .createEPL("select * from StockRealTimeEvent where " + "(buyCount5+buyCount4+buyCount3+buyCount2+buyCount1)*100" + "<=(sellCount5+sellCount4+sellCount3+sellCount2+sellCount1)"); stmt.addListener(new UpdateListener() { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents != null) { EventBean theEvent = newEvents[0]; StockRealTimeEvent stockRTEvent = (StockRealTimeEvent)theEvent.getUnderlying(); log.info("---------- 股票策略1(大卖盘)选出股票:" + stockRTEvent.getStockCode() + " 最新价:" + stockRTEvent.getNewPrice()); outputCollector.emit(new Values(new ResultStock(stockRTEvent.getStockCode(),stockRTEvent.getNewPrice(),1))); } } }); }
/** * 是当task起来后执行的初始化动作 * 这里初始化Esper * * @param stormConf * @param context */ @Override public void prepare(Map stormConf, TopologyContext context) { log.info("----------股票策略2(大买盘)初始化..."); Configuration configuration = new Configuration(); configuration.addEventType("StockRealTimeEvent", StockRealTimeEvent.class.getName()); epService = EPServiceProviderManager.getProvider("strategy2",configuration); //提取出卖盘口远大于买盘口的行情数据 EPStatement stmt = epService.getEPAdministrator() .createEPL("select * from StockRealTimeEvent where " + "(buyCount5+buyCount4+buyCount3+buyCount2+buyCount1)" + ">=(sellCount5+sellCount4+sellCount3+sellCount2+sellCount1)*100"); stmt.addListener(new UpdateListener() { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents != null) { EventBean theEvent = newEvents[0]; StockRealTimeEvent stockRTEvent = (StockRealTimeEvent) theEvent.getUnderlying(); log.info("---------- 股票策略2(大买盘)选出股票:" + stockRTEvent.getStockCode() + " 最新价:" + stockRTEvent.getNewPrice()); outputCollector.emit(new Values(new ResultStock(stockRTEvent.getStockCode(),stockRTEvent.getNewPrice(),2))); } } }); }
private void registerStatements(List<String> statements, SpOutputCollector collector, T params) { toEpStatement(statements); queue = new StatementAwareQueue(getWriter(collector, params), 500000); queue.start(); for(EPStatement epStatement : epStatements) { LOG.info("Registering statement " +epStatement.getText()); if (epStatement.getText().startsWith("select")) { epStatement.addListener(listenerSendingTo(queue)); } epStatement.start(); } }
public AlarmEPLManager addEpls() { this.allEpls = DBUtils.qetAllAlarmEpls(); Collection<AlarmEpl> epls = allEpls.values(); EPStatement state = null; String eplSql = null; for(AlarmEpl epl : epls) { eplSql = epl.getEplSql(); state = this.admin.createEPL(eplSql); state.addListener(new AlertListener(epl.getAlarmEplId(), epl.getEplId(), epl.getEplName(), epl.getAlarm())); if(state != null) eplStateMap.put(epl.getAlarmEplId(), state); } return this; }
@Override protected void doStart() throws Exception { super.doStart(); if (statement.isDestroyed()) { // statement is destroyed! re-init it! statement = endpoint.createStatement(getRoute().getId()); } if(endpoint.isListen()) { statement.addListener(this); } else { log.debug("Start esper consumer eql='"+endpoint.getEndpointConfiguration().getParameter("eql")+"' without listener!"); } }
@Override public void prepare(@SuppressWarnings("rawtypes") Map conf, TopologyContext context, OutputCollector collector) { this.collector = collector; Configuration configuration = new Configuration(); setupEventTypes(context, configuration); this.esperSink = EPServiceProviderManager.getProvider(this.toString(), configuration); this.esperSink.initialize(); this.runtime = esperSink.getEPRuntime(); this.admin = esperSink.getEPAdministrator(); for (String stmt : statements) { EPStatement statement = admin.createEPL(stmt); statement.addListener(this); } }