public void addListener(UpdateListener listener) { statement.addListener(listener); } }
private void processStatement(EPStatement statement) { if (statement == null) { return; } Annotation annotation = AnnotationUtil.findAnnotation(statement.getAnnotations(), KafkaOutputDefault.class); if (annotation == null) { return; } KafkaOutputDefaultListener listener = new KafkaOutputDefaultListener(runtime, statement, producer, topics); statement.addListener(listener); log.info("Added Kafka-Output-Adapter listener to statement '{}' topics {}", statement.getName(), topics.toString()); }
public void run(RegressionEnvironment env) { env.compileDeploy("@name('s0') select * from SupportBean"); EPStatement statement = env.statement("s0"); env.undeployAll(); assertTrue(statement.isDestroyed()); tryInvalid(statement, stmt -> stmt.iterator()); tryInvalid(statement, stmt -> stmt.iterator(new ContextPartitionSelectorAll())); tryInvalid(statement, stmt -> stmt.safeIterator()); tryInvalid(statement, stmt -> stmt.safeIterator(new ContextPartitionSelectorAll())); tryInvalid(statement, stmt -> stmt.addListenerWithReplay(new SupportUpdateListener())); tryInvalid(statement, stmt -> stmt.addListener(new SupportUpdateListener())); tryInvalid(statement, stmt -> stmt.setSubscriber(this)); tryInvalid(statement, stmt -> stmt.setSubscriber(this, "somemethod")); } }
private void detachStatement(EPStatement statement) { Iterator<UpdateListener> listeners = statement.getUpdateListeners(); UpdateListener found = null; while (listeners.hasNext()) { UpdateListener listener = listeners.next(); if (listener instanceof KafkaOutputDefaultListener) { found = listener; break; } } if (found != null) { statement.removeListener(found); } log.info("Removed Kafka-Output-Adapter listener from statement '{}'", statement.getName()); }
private EPDataFlowEPStatementFilterContext toContext(EPStatement stmt) { return new EPDataFlowEPStatementFilterContext(stmt.getDeploymentId(), stmt.getName(), stmt); } }
public void run(RegressionEnvironment env) { String epl = "@name('s0') @IterableUnbound select * from pattern[every tag=SupportBean]"; env.compileDeploy(epl); // Pattern started when created // Add listener SupportUpdateListener listener = new SupportUpdateListener(); env.statement("s0").addListener(listener); assertNull(env.listener("s0").getLastNewData()); TestCase.assertFalse(env.iterator("s0").hasNext()); // Send event SupportBean theEvent = sendEvent(env); assertEquals(theEvent, listener.getAndResetLastNewData()[0].get("tag")); TestCase.assertSame(theEvent, env.statement("s0").iterator().next().get("tag")); // Remove listener env.statement("s0").removeListener(listener); theEvent = sendEvent(env); TestCase.assertSame(theEvent, env.iterator("s0").next().get("tag")); assertNull(listener.getLastNewData()); // Add listener back env.statement("s0").addListener(listener); theEvent = sendEvent(env); TestCase.assertSame(theEvent, env.iterator("s0").next().get("tag")); assertEquals(theEvent, listener.getAndResetLastNewData()[0].get("tag")); env.undeployAll(); } }
public Object call() throws Exception { try { for (int loop = 0; loop < numRepeats; loop++) { MyUpdateListener listener = new MyUpdateListener(env, numThread, loop); statement.addListener(listener); env.sendEventBean(new SupportBean(), "SupportBean"); statement.removeListener(listener); listener.assertCalled(); if (listener.lastException != null) { throw new RuntimeException("Listener exception: " + listener.lastException.getMessage(), listener.lastException); } } } catch (AssertionFailedError ex) { log.error("Assertion error in thread " + Thread.currentThread().getId(), ex); return false; } catch (Exception ex) { log.error("Error in thread " + Thread.currentThread().getId(), ex); return false; } return true; }
public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPRuntime runtime) { long count = (Long) countEvents.iterator().next().get("size"); log.info(".update Info, error rate in the last 10 minutes is " + count); } });
public EPStatement getStatementByName(String deploymentId, String statementName) { DeploymentInternal deployment = deploymentsByName.get(deploymentId); if (deployment == null) { return null; } for (EPStatement stmt : deployment.getStatements()) { if (stmt.getName().equals(statementName)) { return stmt; } } return null; }
private static void tryAssertion(EPStatement stmt) { Annotation[] annotations = stmt.getAnnotations(); annotations = sortAlpha(annotations); assertEquals(3, annotations.length); assertEquals(Description.class, annotations[0].annotationType()); assertEquals("MyTestStmt description", ((Description) annotations[0]).value()); assertEquals("@Description(\"MyTestStmt description\")", annotations[0].toString()); assertEquals(Name.class, annotations[1].annotationType()); assertEquals("MyTestStmt", ((Name) annotations[1]).value()); assertEquals("MyTestStmt", stmt.getName()); assertEquals("@Name(\"MyTestStmt\")", annotations[1].toString()); assertEquals(Tag.class, annotations[2].annotationType()); assertEquals("UserId", ((Tag) annotations[2]).name()); assertEquals("value", ((Tag) annotations[2]).value()); assertEquals("@Tag(name=\"UserId\", value=\"value\")", annotations[2].toString()); assertFalse(annotations[2].equals(annotations[1])); TestCase.assertTrue(annotations[1].equals(annotations[1])); TestCase.assertTrue(annotations[1].hashCode() != 0); } }
private void tryAssertionAnnotation(RegressionEnvironment env, String epl) { env.compileDeploy(epl).addListener("s0"); assertEquals(Integer.class, env.statement("s0").getEventType().getPropertyType("scalar()")); assertEquals("s0", env.statement("s0").getName()); env.sendEventBean(new SupportBean_ST0("E1", 1)); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), "scalar()".split(","), new Object[]{1}); env.undeployAll(); } }
public void traverseStatementsContains(BiConsumer<EPDeployment, EPStatement> consumer, String containsIgnoreCase) { runtimeSPI.traverseStatements((deployment, stmt) -> { boolean match = false; String searchString = containsIgnoreCase.toLowerCase(Locale.ENGLISH); if (stmt.getName().toLowerCase(Locale.ENGLISH).contains(searchString)) { match = true; } if (!match) { String epl = (String) stmt.getProperty(StatementProperty.EPL); if ((epl != null) && (epl.toLowerCase(Locale.ENGLISH).contains(searchString))) { match = true; } } if (!match) { return; } consumer.accept(deployment, stmt); }); }
private static void runAssertionIterateCreateTable(RegressionEnvironment env, Object[][] expectedType, Object[] rowValues, EPStatement stmtCreate) { assertEventTypeAndEvent(stmtCreate.getEventType(), expectedType, stmtCreate.iterator().next().getUnderlying(), rowValues); }
private void tryAssertionNoClassNameRequired(RegressionEnvironment env, SupportEnum expected, String text) { env.compileDeploy("@MyAnnotationValueEnum(supportEnum = " + text + ") @name('s0') select * from SupportBean"); MyAnnotationValueEnum anno = (MyAnnotationValueEnum) env.statement("s0").getAnnotations()[0]; assertEquals(expected, anno.supportEnum()); env.undeployAll(); } }
public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPRuntime runtime) { try { runtime.getDeploymentService().undeploy(spikeLatencyAlert.getDeploymentId()); } catch (EPUndeployException e) { log.warn("Failed to undeploy: " + e.getMessage(), e); } } });
public void close(DataFlowOpCloseContext openContext) { for (Map.Entry<EPStatement, UpdateListener> entry : listeners.entrySet()) { try { entry.getKey().removeListener(entry.getValue()); } catch (Exception ex) { log.debug("Exception encountered removing listener: " + ex.getMessage(), ex); // possible } } listeners.clear(); }
private static long getTableCount(EPStatement stmt) { return EPAssertionUtil.iteratorCount(stmt.iterator()); }
public void onUndeployment(DeploymentStateEventUndeployed event) { if (!specification.isEnableMetricsReporting()) { return; } for (EPStatement stmt : event.getStatements()) { DeploymentIdNamePair pair = new DeploymentIdNamePair(stmt.getDeploymentId(), stmt.getName()); stmtMetricRepository.removeStatement(pair); statementMetricHandles.remove(pair); } }
public void update(EventBean[] newData, EventBean[] oldData, EPStatement epStatement, EPRuntime runtime) { for (int i = 0; i < newData.length; i++) { if (log.isInfoEnabled()) { log.info("Statement " + String.format("%s", epStatement.getName()) + " produced: " + getProperties(newData[i])); } } }
public void run(RegressionEnvironment env) { MyStatementNameRuntimeResolver.getContexts().clear(); String epl = "@name('s0') select * from SupportBean"; EPCompiled compiled = env.compile(epl); DeploymentOptions options = new DeploymentOptions(); options.setStatementNameRuntime(new MyStatementNameRuntimeResolver()); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { fail(e.getMessage()); } StatementNameRuntimeContext ctx = MyStatementNameRuntimeResolver.getContexts().get(0); assertEquals("s0", ctx.getStatementName()); assertEquals(env.deploymentId("hello"), ctx.getDeploymentId()); assertSame(env.statement("hello").getAnnotations(), ctx.getAnnotations()); assertEquals(epl, ctx.getEpl()); assertEquals("hello", env.statement("hello").getName()); env.milestone(0); assertEquals("hello", env.statement("hello").getName()); env.undeployAll(); } }