private static void resolveAssertionService(EPRuntime epServiceProvider) { String provider = System.getProperty(PROVIDER_PROPERTY); if (provider == null) { throw new RuntimeException("Failed to find '" + PROVIDER_PROPERTY + "' system property"); } EPRuntimeSPI spi = (EPRuntimeSPI) epServiceProvider; assertionService = (InstrumentationAssertionService) JavaClassHelper.instantiate(InstrumentationAssertionService.class, provider, spi.getServicesContext().getClassForNameProvider()); } }
private static void resolveAssertionService(EPRuntime runtime) { String provider = System.getProperty(PROVIDER_PROPERTY); if (provider == null) { throw new RuntimeException("Failed to find '" + PROVIDER_PROPERTY + "' system property"); } if (provider.toLowerCase(Locale.ENGLISH).trim().equals("default")) { assertionService = new DefaultInstrumentationAssertionService(); } else { EPRuntimeSPI spi = (EPRuntimeSPI) runtime; assertionService = (InstrumentationAssertionService) JavaClassHelper.instantiate(InstrumentationAssertionService.class, provider, spi.getServicesContext().getClasspathImportServiceRuntime().getClassForNameProvider()); } }
public void setRuntime(EPRuntime runtime) { if (runtime == null) { throw new NullPointerException("runtime cannot be null"); } if (!(runtime instanceof EPRuntimeSPI)) { throw new IllegalArgumentException("Invalid type of runtime"); } EPRuntimeSPI spi = (EPRuntimeSPI) runtime; processEvent = spi.getEventService(); schedulingService = spi.getServicesContext().getSchedulingService(); sender.setRuntime(processEvent); }
public void setRuntime(EPRuntime runtime) { if (runtime == null) { throw new NullPointerException("runtime cannot be null"); } if (!(runtime instanceof EPRuntimeSPI)) { throw new IllegalArgumentException("Invalid type of runtime"); } EPRuntimeSPI spi = (EPRuntimeSPI) runtime; processEvent = spi.getEventService(); schedulingService = spi.getServicesContext().getSchedulingService(); sender.setRuntime(processEvent); }
private static DeploymentInternal deploy(boolean recovery, String deploymentId, int statementIdFirstStatement, EPCompiled compiled, StatementNameRuntimeOption statementNameResolverRuntime, StatementUserObjectRuntimeOption userObjectResolverRuntime, StatementSubstitutionParameterOption substitutionParameterResolver, EPRuntimeSPI epRuntime) throws EPDeployException { // set variable local version epRuntime.getServicesContext().getVariableManagementService().setLocalVersion(); try { return deploySafe(recovery, deploymentId, statementIdFirstStatement, compiled, statementNameResolverRuntime, userObjectResolverRuntime, substitutionParameterResolver, epRuntime); } catch (EPDeployException ex) { throw ex; } catch (Throwable t) { throw new EPDeployException(t.getMessage(), t); } }
public static int getContextCount(RegressionEnvironment env) { EPRuntimeSPI spi = (EPRuntimeSPI) env.runtime(); return spi.getServicesContext().getContextManagementService().getContextCount(); } }
public static int getFilterCountApprox(RegressionEnvironment env) { FilterServiceSPI spi = ((EPRuntimeSPI) env.runtime()).getServicesContext().getFilterService(); return spi.getFilterCountApprox(); }
private EsperHttpRequestCacheEntry makeCacheEntry(String eventTypeName) { EventType eventType = runtime.getServicesContext().getEventTypeRepositoryBus().getNameToTypeMap().get(eventTypeName); if (eventType == null) { log.info("Event type by name '" + eventTypeName + "' not found."); eventBeanManufacturer = EventTypeUtility.getManufacturer(eventType, writableProperties, runtime.getServicesContext().getClasspathImportServiceRuntime(), false, runtime.getServicesContext().getEventTypeAvroHandler()).getManufacturer(runtime.getServicesContext().getEventBeanTypedEventFactory()); } catch (EventBeanManufactureException e) { log.info("Unable to create manufacturer for event type: " + e.getMessage(), e);
public void start() { if (log.isInfoEnabled()) { log.info("Starting EsperIO Kafka Output Adapter for runtime URI '{}'", runtimeURI); } // Obtain runtime EPRuntimeSPI runtime = (EPRuntimeSPI) EPRuntimeProvider.getRuntime(runtimeURI); // Obtain and invoke flow controlle String className = getRequiredProperty(properties, OUTPUT_FLOWCONTROLLER_CONFIG); EsperIOKafkaOutputFlowController controller; try { controller = (EsperIOKafkaOutputFlowController) JavaClassHelper.instantiate(EsperIOKafkaOutputFlowController.class, className, runtime.getServicesContext().getClasspathImportServiceRuntime().getClassForNameProvider()); EsperIOKafkaOutputFlowControllerContext context = new EsperIOKafkaOutputFlowControllerContext(runtime, properties); controller.initialize(context); } catch (Throwable t) { throw new ConfigurationException("Unexpected exception invoking flow-controller initialize method on class " + className + " for runtime URI '" + runtimeURI + "': " + t.getMessage(), t); } if (log.isInfoEnabled()) { log.info("Completed starting EsperIO Kafka Output Adapter for runtime URI '{}'", runtimeURI); } }
public void init(EsperIOKafkaInputProcessorContext context) { this.runtime = context.getRuntime(); String timestampExtractorClassName = context.getProperties().getProperty(EsperIOKafkaConfig.INPUT_TIMESTAMPEXTRACTOR_CONFIG); if (timestampExtractorClassName != null) { timestampExtractor = (EsperIOKafkaInputTimestampExtractor) JavaClassHelper.instantiate(EsperIOKafkaInputTimestampExtractor.class, timestampExtractorClassName, context.getRuntime().getServicesContext().getClasspathImportServiceRuntime().getClassForNameProvider()); } }
public static String getFilterAll(EPRuntime runtime) { String[] deployments = runtime.getDeploymentService().getDeployments(); Set<Integer> statements = new HashSet<>(); for (String deployment : deployments) { EPDeployment info = runtime.getDeploymentService().getDeployment(deployment); for (EPStatement statement : info.getStatements()) { EPStatementSPI spi = (EPStatementSPI) statement; statements.add(spi.getStatementId()); } } FilterServiceSPI filterService = ((EPRuntimeSPI) runtime).getServicesContext().getFilterService(); Map<EventTypeIdPair, Map<Integer, List<FilterItem[]>>> pairs = filterService.get(statements); return pairs.toString(); } }
/** * Ctor. * * @param runtime - the runtime for the runtimeprocessEvent and services * @param usingRuntimeThread - true if the Adapter should set time by the scheduling service in the runtime, * false if it should set time externally through the calling thread * @param usingExternalTimer - true to use esper's external timer mechanism instead of internal timing * @param usingTimeSpanEvents - true for time span events */ public AbstractCoordinatedAdapter(EPRuntime runtime, boolean usingRuntimeThread, boolean usingExternalTimer, boolean usingTimeSpanEvents) { this.usingRuntimeThread = usingRuntimeThread; this.usingExternalTimer = usingExternalTimer; this.usingTimeSpanEvents = usingTimeSpanEvents; this.setSender(new DirectSender()); if (runtime == null) { return; } if (!(runtime instanceof EPRuntimeSPI)) { throw new IllegalArgumentException("Invalid runtime provided"); } this.runtime = runtime; this.processEvent = runtime.getEventService(); this.schedulingService = ((EPRuntimeSPI) runtime).getServicesContext().getSchedulingService(); }
/** * Ctor. * * @param runtime - the runtime for the runtimeprocessEvent and services * @param usingRuntimeThread - true if the Adapter should set time by the scheduling service in the runtime, * false if it should set time externally through the calling thread * @param usingExternalTimer - true to use esper's external timer mechanism instead of internal timing * @param usingTimeSpanEvents - true for time span events */ public AbstractCoordinatedAdapter(EPRuntime runtime, boolean usingRuntimeThread, boolean usingExternalTimer, boolean usingTimeSpanEvents) { this.usingRuntimeThread = usingRuntimeThread; this.usingExternalTimer = usingExternalTimer; this.usingTimeSpanEvents = usingTimeSpanEvents; this.setSender(new DirectSender()); if (runtime == null) { return; } if (!(runtime instanceof EPRuntimeSPI)) { throw new IllegalArgumentException("Invalid runtime provided"); } this.runtime = runtime; this.processEvent = runtime.getEventService(); this.schedulingService = ((EPRuntimeSPI) runtime).getServicesContext().getSchedulingService(); }
private void scheduleNextCallback() { ScheduleHandleCallback nextScheduleCallback = new ScheduleHandleCallback() { public void scheduledTrigger() { continueSendingEvents(); } }; EPRuntimeSPI spi = (EPRuntimeSPI) runtime; String deploymentId = "CSV-adapter-" + UuidGenerator.generate(); StatementMetricHandle metricsHandle = spi.getServicesContext().getMetricReportingService().getStatementHandle(-1, deploymentId, "AbstractCoordinatedAdapter"); EPStatementHandle stmtHandle = new EPStatementHandle("AbstractCoordinatedAdapter", deploymentId, -1, null, 0, false, false, spi.getServicesContext().getMultiMatchHandlerFactory().make(false, false), false, false, metricsHandle, null, null); EPStatementAgentInstanceHandle agentInstanceHandle = new EPStatementAgentInstanceHandle(stmtHandle, -1, new StatementAgentInstanceLockRW(false)); EPStatementHandleCallbackSchedule scheduleCSVHandle = new EPStatementHandleCallbackSchedule(agentInstanceHandle, nextScheduleCallback); long nextScheduleSlot; if (eventsToSend.isEmpty()) { if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) { log.debug(".scheduleNextCallback no events to send, scheduling callback in 100 ms"); } nextScheduleSlot = 0L; schedulingService.add(100, scheduleCSVHandle, nextScheduleSlot); } else { // Offset is not a function of the currentTime alone. long baseMsec = currentTime - startTime; long afterMsec = eventsToSend.first().getSendTime() - baseMsec; nextScheduleSlot = eventsToSend.first().getScheduleSlot(); if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) { log.debug(".scheduleNextCallback schedulingCallback in " + afterMsec + " milliseconds"); } schedulingService.add(afterMsec, scheduleCSVHandle, nextScheduleSlot); } }
public static int scheduleCountOverall(RegressionEnvironment env) { EPRuntimeSPI spi = (EPRuntimeSPI) env.runtime(); ScheduleVisitorAll visitor = new ScheduleVisitorAll(); spi.getServicesContext().getSchedulingService().visitSchedules(visitor); return visitor.getCount(); }
public static NamedWindow getNamedWindow(RegressionEnvironment env, String statementNameNamedWindow, String windowName) { EPRuntimeSPI spi = (EPRuntimeSPI) env.runtime(); NamedWindowManagementService namedWindowManagementService = spi.getServicesContext().getNamedWindowManagementService(); String deploymentId = env.deploymentId(statementNameNamedWindow); NamedWindow namedWindow = namedWindowManagementService.getNamedWindow(deploymentId, windowName); if (namedWindow == null) { fail("Failed to find statement-name '" + statementNameNamedWindow + "' named window '" + windowName + "'"); } return namedWindow; }
public static Table getTable(RegressionEnvironment env, String statementNameTable, String tableName) { EPRuntimeSPI spi = (EPRuntimeSPI) env.runtime(); TableManagementService tables = spi.getServicesContext().getTableManagementService(); String deploymentId = env.deploymentId(statementNameTable); Table table = tables.getTable(deploymentId, tableName); if (table == null) { fail("Failed to find statement-name '" + statementNameTable + "' table '" + tableName + "'"); } return table; } }
private void finishInitialization(EPRuntime runtime, CSVInputAdapterSpec spec) { assertValidParameters(runtime, spec); EPRuntimeSPI spi = (EPRuntimeSPI) runtime; scheduleSlot = new ScheduleBucket(-1).allocateSlot(); reader = new CSVReader(spec.getAdapterInputSource()); reader.setLooping(spec.isLooping()); String[] firstRow = getFirstRow(); Map<String, Object> givenPropertyTypes = constructPropertyTypes(spec.getEventTypeName(), spec.getPropertyTypes(), spi.getServicesContext().getEventTypeRepositoryBus()); propertyOrder = spec.getPropertyOrder() != null ? spec.getPropertyOrder() : CSVPropertyOrderHelper.resolvePropertyOrder(firstRow, givenPropertyTypes); reader.setIsUsingTitleRow(isUsingTitleRow(firstRow, propertyOrder)); if (!isUsingTitleRow(firstRow, propertyOrder)) { this.firstRow = firstRow; } propertyTypes = resolvePropertyTypes(givenPropertyTypes, spi.getServicesContext().getClasspathImportServiceRuntime()); if (givenPropertyTypes == null) { throw new EPException("CSV adapter requires a predefined event type name, the event type named '" + spec.getEventTypeName() + "' could not be found"); } coercer.setPropertyTypes(propertyTypes); }
private void finishInitialization(EPRuntime runtime, CSVInputAdapterSpec spec) { assertValidParameters(runtime, spec); EPRuntimeSPI spi = (EPRuntimeSPI) runtime; scheduleSlot = new ScheduleBucket(-1).allocateSlot(); reader = new CSVReader(spec.getAdapterInputSource()); reader.setLooping(spec.isLooping()); String[] firstRow = getFirstRow(); Map<String, Object> givenPropertyTypes = constructPropertyTypes(spec.getEventTypeName(), spec.getPropertyTypes(), spi.getServicesContext().getEventTypeRepositoryBus()); propertyOrder = spec.getPropertyOrder() != null ? spec.getPropertyOrder() : CSVPropertyOrderHelper.resolvePropertyOrder(firstRow, givenPropertyTypes); reader.setIsUsingTitleRow(isUsingTitleRow(firstRow, propertyOrder)); if (!isUsingTitleRow(firstRow, propertyOrder)) { this.firstRow = firstRow; } propertyTypes = resolvePropertyTypes(givenPropertyTypes, spi.getServicesContext().getClasspathImportServiceRuntime()); if (givenPropertyTypes == null) { throw new EPException("CSV adapter requires a predefined event type name, the event type named '" + spec.getEventTypeName() + "' could not be found"); } coercer.setPropertyTypes(propertyTypes); }
public void setUpdateListeners(EPStatementListenerSet updateListeners, boolean isRecovery) { // indicate that listeners were updated for potential persistence of listener set, once the statement context is known if (epStatement != null) { if (!isRecovery) { StatementContext stmtCtx = epStatement.getStatementContext(); epServicesContext.getEpServicesHA().getListenerRecoveryService().put(stmtCtx.getStatementId(), stmtCtx.getStatementName(), updateListeners.getListeners()); } } this.statementListenerSet = updateListeners; isMakeNatural = statementListenerSet.getSubscriber() != null; isMakeSynthetic = !(statementListenerSet.getListeners().length == 0) || statementInformationals.isAlwaysSynthesizeOutputEvents(); if (statementListenerSet.getSubscriber() == null) { statementResultNaturalStrategy = null; isMakeNatural = false; return; } try { statementResultNaturalStrategy = ResultDeliveryStrategyFactory.create(epStatement, statementListenerSet.getSubscriber(), statementListenerSet.getSubscriberMethodName(), selectClauseTypes, selectClauseColumnNames, runtime.getURI(), runtime.getServicesContext().getClasspathImportServiceRuntime()); isMakeNatural = true; } catch (ResultDeliveryStrategyInvalidException ex) { throw new EPSubscriberException(ex.getMessage(), ex); } }