private Configuration createConfig(EsperDeclaredEvents declaredEvents) { Configuration config = new Configuration(); config.setMetricsReportingDisabled(); config.getEngineDefaults().getThreading().setThreadPoolInbound(false); config.getEngineDefaults().getThreading().setThreadPoolOutbound(false); config.getEngineDefaults().getThreading().setThreadPoolRouteExec(false); config.getEngineDefaults().getThreading().setThreadPoolTimerExec(false); config.getEngineDefaults().getThreading().setInternalTimerEnabled(false); if (declaredEvents != null) { for (AbstractEventType type : declaredEvents.getEventTypes()) { String strAlias = type.getEventAlias(); if (type instanceof MapEventType) { config.addEventType(strAlias, ((MapEventType) type).getEventFields()); this.eventTypes.add(strAlias); } } } return config; }
/** * Use the configuration specified in an application * resource named <tt>esper.cfg.xml</tt>. * @return Configuration initialized from the resource * @throws EPException thrown to indicate error reading configuration */ public Configuration configure() throws EPException { configure('/' + ESPER_DEFAULT_CONFIG); return this; }
/** * registers the namespace of the custom functions */ private void registerCustomFunctions() { // standard namespace this.config.addImport(CUSTOM_ESPER_FUNCTIONS_NAMESPACE); }
/** * Registers an event with a name at the engine. Nestable maps are allowed. * * @param eventName * Name of the event used in the patterns (mostly the inputName). * @param properties * Properties of the event. Each event is send as an HashMap. * These Properties must contain an entry for each key in the * HashMap containing the data type of the HashMap value. */ @Override public synchronized void registerEventWithProperties(String eventName, Map<String, Object> properties) { if (!this.config.getEventTypesNestableMapEvents() .containsKey(eventName)) { this.config.addEventType(eventName, properties); } }
/** * Returns the event processing service provider. If the provider is null an * instance will be created via the EPServiceProviderManager. * * @return event processing service provider */ public EPServiceProvider getEsperService(boolean configured) { if (esperService == null) { if (configured) { Configuration configuration = new Configuration(); configuration.configure(); esperService = EPServiceProviderManager.getProvider("DefaultConfiguredProvider", configuration); } else { esperService = EPServiceProviderManager.getDefaultProvider(); } } return esperService; }
@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))); } } }); }
/** * * Constructor * */ public EsperController() { this.config = new Configuration(); this.listeners = new HashMap<String, StatementListener>(); this.countingListeners = new HashMap<String, CountingListener>(); // this.timerListeners = new HashMap<String, TimerListener>(); this.epStatements = new HashMap<String, EPStatement>(); this.inputEventDataTypes = new HashMap<String, Object>(); }
epConfig.configure("cointrader-esper.cfg.xml"); epConfig.addEventType(Event.class); Set<Class<? extends Event>> eventTypes = ReflectionUtil.getSubtypesOf(Event.class); for (Class<? extends Event> eventType : eventTypes) epConfig.addEventType(eventType); epConfig.addImport(IntoMethod.class); if (timeProvider != null) { epConfig.getEngineDefaults().getThreading().setInternalTimerEnabled(false);
this.conf = conf; this.latch = latch; this.configuration = new com.espertech.esper.client.Configuration(); this.configuration.getEngineDefaults().getThreading().setInsertIntoDispatchPreserveOrder(false); this.addMethods(configuration); this.addDbs();
config.getEngineDefaults().getExceptionHandling().addClass(SessionizerEsperExceptionHandlerFactory.class); String name = EsperController.class.getName() + "-" + baseName + "-" + Thread.currentThread().getId(); esperService = EPServiceProviderManager.getProvider(name, config);
/** * Configure Esper Statement(s). */ public void initService() { LOG.debug("Initializing Servcie .."); Configuration config = new Configuration(); config.addEventTypeAutoName("com.cor.cep.event"); epService = EPServiceProviderManager.getDefaultProvider(config); createCriticalTemperatureCheckExpression(); createWarningTemperatureCheckExpression(); createTemperatureMonitorExpression(); }
public void recreateMethod(Method method) { Method md = this.allMethods.get(method.getMethodName()); if(md != null) this.configuration.removeImport(md.getMethodName()); ConfigurationMethodRef methodRef = new ConfigurationMethodRef(); ConfigurationCacheReferenceType cacheReferenceType = null; if("WEAK".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.WEAK; } else if("SOFT".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.SOFT; } else { cacheReferenceType = ConfigurationCacheReferenceType.HARD; } methodRef.setExpiryTimeCache(method.getMaxAgeSeconds(), method.getPurgeIntervalSeconds(), cacheReferenceType); Class clazz = null; try { clazz = Class.forName(method.getMethodName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } this.configuration.addMethodRef(clazz, methodRef); this.configuration.addImport(method.getMethodName()); LOG.info("Recreate Method : " + method.getMethodName()); }
public AlarmEPLManager addMethods(Configuration configuration) { this.allMethods = DBUtils.qetAllMethods(); Collection<Method> methods = this.allMethods.values(); for(Method method : methods) { ConfigurationMethodRef methodRef = new ConfigurationMethodRef(); ConfigurationCacheReferenceType cacheReferenceType = null; if("WEAK".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.WEAK; } else if("SOFT".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.SOFT; } else { cacheReferenceType = ConfigurationCacheReferenceType.HARD; } methodRef.setExpiryTimeCache(method.getMaxAgeSeconds(), method.getPurgeIntervalSeconds(), cacheReferenceType); Class clazz = null; try { clazz = Class.forName(method.getMethodName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } if(clazz == null) continue; this.configuration.addMethodRef(clazz, methodRef); this.configuration.addImport(method.getMethodName()); } return this; }
private void setupEventTypes(TopologyContext context, Configuration configuration) { Set<GlobalStreamId> sourceIds = context.getThisSources().keySet(); for (GlobalStreamId id : sourceIds) { String eventTypeName = getEventTypeName(id.get_componentId(), id.get_streamId()); Fields fields = context.getComponentOutputFields(id.get_componentId(), id.get_streamId()); TupleTypeDescriptor typeDesc = tupleTypes.get(new StreamId(id.get_componentId(), id.get_streamId())); Map<String, Object> props = setupEventTypeProperties(fields, typeDesc); configuration.addEventType(eventTypeName, props); } }
configuration.addDatabaseReference(name, configDBRef);
/** * Configure the Esper Service Provider to create the appropriate Esper * Runtime. * * @throws IOException * @throws EPException */ private void configureEPServiceProvider() throws EPException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("Configuring the Esper Service Provider with name: " + name); } if (this.configuration != null && this.configuration.exists()) { Configuration esperConfiguration = new Configuration(); esperConfiguration = esperConfiguration.configure(this.configuration.getFile()); epServiceProvider = EPServiceProviderManager.getProvider(name, esperConfiguration); LOG.info("Esper configured with a user-provided configuration", esperConfiguration); } else { epServiceProvider = EPServiceProviderManager.getProvider(name); } if (LOG.isDebugEnabled()) { LOG.debug("Completed configuring the Esper Service Provider with name: " + name); } } }
/** * 是当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))); } } }); }
/** * Returns an EPServiceProvider for a given provider URI. * @param providerURI - the provider URI * @return EPServiceProvider for the given provider URI. */ public static EPServiceProvider getProvider(String providerURI) { return getProvider(providerURI, new Configuration()); }
config.getEngineDefaults().getExceptionHandling().addClass(SessionizerEsperExceptionHandlerFactory.class); String name = EsperSessionizer.class.getName() + "-" + baseName + "-" + id; esperService = EPServiceProviderManager.getProvider(name, config);
public void recreateMethod(Method method) { Method md = this.allMethods.get(method.getMethodName()); if(md != null) this.configuration.removeImport(md.getMethodName()); ConfigurationMethodRef methodRef = new ConfigurationMethodRef(); ConfigurationCacheReferenceType cacheReferenceType = null; if("WEAK".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.WEAK; } else if("SOFT".equals(method.getCacheReferenceType())) { cacheReferenceType = ConfigurationCacheReferenceType.SOFT; } else { cacheReferenceType = ConfigurationCacheReferenceType.HARD; } methodRef.setExpiryTimeCache(method.getMaxAgeSeconds(), method.getPurgeIntervalSeconds(), cacheReferenceType); Class clazz = null; try { clazz = Class.forName(method.getMethodName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } this.configuration.addMethodRef(clazz, methodRef); this.configuration.addImport(method.getMethodName()); LOG.info("Recreate Method : " + method.getMethodName()); }